MCPcopy Create free account
hub / github.com/effector/effector / createDomain

Function createDomain

src/effector/createDomain.ts:21–117  ·  view source on GitHub ↗
(nameOrConfig: any, maybeConfig?: any)

Source from the content-addressed store, hash-verified

19import {flattenConfig} from './config'
20
21export function createDomain(nameOrConfig: any, maybeConfig?: any): Domain {
22 const config = flattenConfig({
23 or: maybeConfig,
24 and: typeof nameOrConfig === 'string' ? {name: nameOrConfig} : nameOrConfig,
25 }) as any
26
27 const node = createNode({
28 family: {type: DOMAIN},
29 regional: true,
30 parent: config?.domain || config?.parent,
31 })
32
33 const domain = {
34 history: {},
35 graphite: node,
36 hooks: {},
37 } as Domain
38
39 node.meta = initUnit(
40 DOMAIN,
41 domain,
42 {
43 parent: config?.domain || config?.parent,
44 or: {...config, derived: true},
45 },
46 getUnitTrace(createDomain),
47 )
48
49 forIn(
50 {
51 Event: createEvent,
52 Effect: createEffect,
53 Store: createStore,
54 Domain: createDomain,
55 },
56 (factory, tag) => {
57 const lowerCaseTag = tag.toLowerCase() as
58 | 'event'
59 | 'effect'
60 | 'store'
61 | 'domain'
62
63 const onCreateUnit = createNamedEvent(`on${tag}`)
64 domain.hooks[lowerCaseTag] = onCreateUnit
65
66 const history = new Set<any>()
67 domain.history[`${lowerCaseTag}s`] = history
68
69 onCreateUnit.create = unit => {
70 launch(onCreateUnit, unit)
71 return unit
72 }
73 add(
74 getGraph(onCreateUnit).seq,
75 calc((upd, _, stack) => {
76 stack.scope = null
77 return upd
78 }),

Callers 15

useStore.test.tsxFile · 0.90
scopes.test.tsxFile · 0.90
clearNode.test.tsFile · 0.90
domain.test.tsFile · 0.90
fork.test.tsFile · 0.90
useUnit.test.tsxFile · 0.90
scopes.test.tsxFile · 0.90
index.test.tsFile · 0.90
observable.test.tsFile · 0.90
effector.test.tsFile · 0.90
region.test.tsFile · 0.90
applyFunction · 0.90

Calls 15

flattenConfigFunction · 0.90
createNodeFunction · 0.90
initUnitFunction · 0.90
getUnitTraceFunction · 0.90
forInFunction · 0.90
createNamedEventFunction · 0.90
launchFunction · 0.90
addFunction · 0.90
getGraphFunction · 0.90
calcFunction · 0.90
ownFunction · 0.90
getParentFunction · 0.90

Tested by 2

applyFunction · 0.72
nameClashCheckFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…