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

Function initUnit

src/effector/createUnit.ts:64–109  ·  view source on GitHub ↗
(
  kind: Kind,
  unit: any,
  rawConfig: any,
  unitTrace: string,
)

Source from the content-addressed store, hash-verified

62}
63
64export const initUnit = (
65 kind: Kind,
66 unit: any,
67 rawConfig: any,
68 unitTrace: string,
69) => {
70 const config = flattenConfig(rawConfig)
71 const isDomain = kind === DOMAIN
72 const id = nextUnitID()
73 const {sid = null, named = null, domain = null, parent = domain} = config
74 const name = named ? named : config.name || (isDomain ? '' : id)
75 const compositeName = createName(name, parent)
76 const meta: Record<string, any> = {
77 op: (unit.kind = kind),
78 name: (unit.shortName = name),
79 sid: (unit.sid = readSidRoot(sid)),
80 named,
81 unitId: (unit.id = id),
82 serialize: config.serialize,
83 derived: config.derived,
84 config,
85 unitTrace,
86 }
87 unit.targetable = !config.derived
88 unit.parent = parent
89 unit.compositeName = compositeName
90 unit.defaultConfig = config
91 unit.getType = () => {
92 deprecate(false, 'getType', 'compositeName.fullName')
93 return compositeName.fullName
94 }
95 if (!isDomain) {
96 unit.subscribe = (observer: Subscriber<any>) => {
97 assertObject(observer)
98 return unit.watch(
99 isFunction(observer)
100 ? observer
101 : (upd: any) => observer.next && observer.next(upd),
102 )
103 }
104 unit[observableSymbol] = () => unit
105 const template = readTemplate()
106 if (template) meta.nativeTemplate = template
107 }
108 return meta
109}
110export const createNamedEvent = (named: string) => createEvent({named})
111
112const deriveEvent = (

Callers 3

createDomainFunction · 0.90
createEventFunction · 0.85
createStoreFunction · 0.85

Calls 8

flattenConfigFunction · 0.90
createNameFunction · 0.90
readSidRootFunction · 0.90
deprecateFunction · 0.90
assertObjectFunction · 0.90
isFunctionFunction · 0.90
readTemplateFunction · 0.90
watchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…