(nameOrConfig: any, maybeConfig?: any)
| 19 | import {flattenConfig} from './config' |
| 20 | |
| 21 | export 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 | }), |
searching dependent graphs…