( kind: Kind, unit: any, rawConfig: any, unitTrace: string, )
| 62 | } |
| 63 | |
| 64 | export 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 | } |
| 110 | export const createNamedEvent = (named: string) => createEvent({named}) |
| 111 | |
| 112 | const deriveEvent = ( |
no test coverage detected
searching dependent graphs…