lanka 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +242 -0
- package/dist/ALankaGateway-ExlRGT3D.d.ts +122 -0
- package/dist/ALankaSharedStore-B7uepuuk.d.ts +29 -0
- package/dist/ILankaApiError-zI_2bNs0.d.ts +16 -0
- package/dist/ILankaRuntimeConfig-Vl436GWK.d.ts +62 -0
- package/dist/ILankaScenarioMetadata-Bu-yggTZ.d.ts +14 -0
- package/dist/ILankaScenarioVM-DuCyPoyT.d.ts +260 -0
- package/dist/LankaError-B1HtuIkw.d.ts +86 -0
- package/dist/LankaScenarioLocator-BGQHwf3n.d.ts +144 -0
- package/dist/LankaSharedStoreLocator-MvCpav5F.d.ts +126 -0
- package/dist/TLankaErrorHandler-Yfqtdh1M.d.ts +3 -0
- package/dist/_extend/index.d.ts +34 -0
- package/dist/_extend/index.js +36 -0
- package/dist/_extend/index.js.map +1 -0
- package/dist/_internal/index.d.ts +43 -0
- package/dist/_internal/index.js +34 -0
- package/dist/_internal/index.js.map +1 -0
- package/dist/activeRuntime-FcsSJvUg.d.ts +84 -0
- package/dist/bootstrap/index.d.ts +242 -0
- package/dist/bootstrap/index.js +22 -0
- package/dist/bootstrap/index.js.map +1 -0
- package/dist/chunk-73IVH3C6.js +52 -0
- package/dist/chunk-73IVH3C6.js.map +1 -0
- package/dist/chunk-BGVDPDX4.js +29 -0
- package/dist/chunk-BGVDPDX4.js.map +1 -0
- package/dist/chunk-C2HP7CRD.js +224 -0
- package/dist/chunk-C2HP7CRD.js.map +1 -0
- package/dist/chunk-D27MREPB.js +13 -0
- package/dist/chunk-D27MREPB.js.map +1 -0
- package/dist/chunk-DTO27QFR.js +59 -0
- package/dist/chunk-DTO27QFR.js.map +1 -0
- package/dist/chunk-EWVDJYCC.js +296 -0
- package/dist/chunk-EWVDJYCC.js.map +1 -0
- package/dist/chunk-FIR4XTBL.js +136 -0
- package/dist/chunk-FIR4XTBL.js.map +1 -0
- package/dist/chunk-ILQNYQY5.js +200 -0
- package/dist/chunk-ILQNYQY5.js.map +1 -0
- package/dist/chunk-J5LA3Q6D.js +14 -0
- package/dist/chunk-J5LA3Q6D.js.map +1 -0
- package/dist/chunk-MDZ42XRH.js +10 -0
- package/dist/chunk-MDZ42XRH.js.map +1 -0
- package/dist/chunk-Q3SOVBIJ.js +176 -0
- package/dist/chunk-Q3SOVBIJ.js.map +1 -0
- package/dist/chunk-Q7QESSYF.js +49 -0
- package/dist/chunk-Q7QESSYF.js.map +1 -0
- package/dist/chunk-RKYKK6MN.js +19 -0
- package/dist/chunk-RKYKK6MN.js.map +1 -0
- package/dist/chunk-RYFZCAQ3.js +637 -0
- package/dist/chunk-RYFZCAQ3.js.map +1 -0
- package/dist/chunk-UJEC7H6K.js +39 -0
- package/dist/chunk-UJEC7H6K.js.map +1 -0
- package/dist/chunk-XESL274R.js +23 -0
- package/dist/chunk-XESL274R.js.map +1 -0
- package/dist/chunk-YR4MZXMU.js +13 -0
- package/dist/chunk-YR4MZXMU.js.map +1 -0
- package/dist/config/index.d.ts +63 -0
- package/dist/config/index.js +16 -0
- package/dist/config/index.js.map +1 -0
- package/dist/createLankaScope-Bc_vChRs.d.ts +30 -0
- package/dist/errors/index.d.ts +37 -0
- package/dist/errors/index.js +16 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/gateway/index.d.ts +258 -0
- package/dist/gateway/index.js +438 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/lankaHttpInFlight-Bk1eIuSx.d.ts +43 -0
- package/dist/lankaRequestMiddleware-DAC5kCb7.d.ts +62 -0
- package/dist/lankaStandardValidator-CL-r-zEV.d.ts +34 -0
- package/dist/locator/index.d.ts +282 -0
- package/dist/locator/index.js +67 -0
- package/dist/locator/index.js.map +1 -0
- package/dist/logger/index.d.ts +146 -0
- package/dist/logger/index.js +11 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/mock/index.d.ts +16 -0
- package/dist/mock/index.js +58 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/role/index.d.ts +48 -0
- package/dist/role/index.js +7 -0
- package/dist/role/index.js.map +1 -0
- package/dist/scenario/index.d.ts +204 -0
- package/dist/scenario/index.js +28 -0
- package/dist/scenario/index.js.map +1 -0
- package/dist/validation/index.d.ts +18 -0
- package/dist/validation/index.js +53 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/viewmodel/index.d.ts +478 -0
- package/dist/viewmodel/index.js +701 -0
- package/dist/viewmodel/index.js.map +1 -0
- package/package.json +99 -0
- package/skills/lanka-core/SKILL.md +241 -0
- package/skills/lanka-core/reference.md +1090 -0
- package/skills/lanka-packages/SKILL.md +70 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/viewmodel/_abstractions/lanka-vm-environment/ALankaVMEnvironment.ts","../../src/viewmodel/_abstractions/lanka-vm/ALankaVM.ts","../../src/viewmodel/_internal/create-lanka-blind-spot-trap/createLankaBlindSpotTrap.ts","../../src/viewmodel/_internal/create-lanka-scenario-binder/createLankaScenarioBinder.ts","../../src/viewmodel/_internal/create-lanka-tracked-hook/createLankaTrackedHook.ts","../../src/viewmodel/_utils/resolve-lanka-dependency/resolveLankaDependency.ts","../../src/viewmodel/_factories/create-lanka-vm/createLankaVM.ts","../../src/viewmodel/_internal/create-lazy-lanka-hook/createLazyLankaHook.ts","../../src/viewmodel/_factories/create-lazy-lanka-vm/createLazyLankaVM.ts","../../src/viewmodel/_abstractions/lanka-stateless-vm/ALankaStatelessVM.ts","../../src/viewmodel/_factories/create-stateless-lanka-vm/createStatelessLankaVM.ts","../../src/viewmodel/_factories/create-lazy-stateless-lanka-vm/createLazyStatelessLankaVM.ts","../../src/viewmodel/_factories/create-shared-store-lanka-vm/createSharedStoreLankaVM.ts","../../src/viewmodel/_factories/create-lazy-shared-store-lanka-vm/createLazySharedStoreLankaVM.ts","../../src/viewmodel/_abstractions/lanka-shared-store-vm/ALankaSharedStoreVM.ts","../../src/viewmodel/_abstractions/lanka-shared-store/ALankaSharedStore.ts","../../src/viewmodel/_factories/create-lanka-shared-store/createLankaSharedStore.ts"],"sourcesContent":["/**\n * What every ViewModel is given, and the two moments it is told about.\n *\n * The three ViewModel shapes — stateful, stateless, over a shared store — differ\n * in where their state lives and in nothing else about this: each is handed a\n * data layer and a set of collaborators, and each is told when its scenarios are\n * bound and when they are about to be unbound.\n *\n * Stated once because a fifth hook added to two of the three is exactly the\n * divergence `skills/parity/SKILL.md` is written against, and three copies of a\n * default is how that starts.\n *\n * It is not a role and nothing extends it directly: the three bases do, and a\n * consumer extends one of them.\n */\nexport abstract class ALankaVMEnvironment<\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n> {\n\t/** What `createGateways` answered: the data layer, kept apart from services. */\n\tprotected gateways!: TGateways;\n\n\t/** What `createServices` answered: everything that is not a gateway. */\n\tprotected services!: Services;\n\n\t/** The data layer, built once per ViewModel. */\n\tprotected createGateways(): TGateways {\n\t\treturn {} as TGateways;\n\t}\n\n\t/** Non-gateway collaborators, built once per ViewModel. */\n\tprotected createServices(): Services {\n\t\treturn {} as Services;\n\t}\n\n\t/** Runs after the scenarios are bound. */\n\tprotected onInit(): void {}\n\n\t/** Runs when the screen goes away, before the scenarios are unbound. */\n\tprotected onReset(): void {}\n}\n","import { ALankaVMEnvironment } from \"../lanka-vm-environment/ALankaVMEnvironment\";\nimport { create, StoreApi, UseBoundStore } from \"zustand\";\nimport { getLankaFlags } from \"../../../config/get-lanka-flags/getLankaFlags\";\nimport { createLankaBlindSpotTrap } from \"../../_internal/create-lanka-blind-spot-trap/createLankaBlindSpotTrap\";\nimport { createLankaScenarioBinder } from \"../../_internal/create-lanka-scenario-binder/createLankaScenarioBinder\";\nimport { createLankaTrackedHook } from \"../../_internal/create-lanka-tracked-hook/createLankaTrackedHook\";\nimport { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\nimport { lankaScenarioBootstrap } from \"../../../scenario/lanka-scenario-bootstrap/LankaScenarioBootstrap\";\nimport { lankaLogger } from \"../../../logger/lanka-logger/LankaLogger\";\nimport type { ILankaScenario } from \"../../../scenario/_interfaces/ILankaScenario\";\nimport type { ILankaVMContext } from \"../../_interfaces/ILankaVMContext\";\nimport type { TLankaVMEnhancer } from \"../../_types/TLankaVMEnhancer\";\nimport type { TLankaVMStateCreator } from \"../../_types/TLankaVMStateCreator\";\nimport type { TUnknownLankaScenarioBinding } from \"../../_types/TUnknownLankaScenarioBinding\";\n\n/**\n * A ViewModel written as a class: the state a screen reads, and the only place a\n * gateway is called from.\n *\n * This is the implementation of the role, and `createLankaVM` is the same thing\n * reached the other way — a subclass built from an options object. Neither style\n * can do what the other cannot, because there is nothing here to diverge from.\n *\n * The protected surface IS the functional context, member for member:\n * `set`, `get`, `gateways`, `services`, `trigger`. What the config supplies as a\n * value or a thunk, the class supplies by overriding a method of the same name —\n * `states`, `scenarioHandlers`, `enhancers`, `onInit`, `onReset` — with the two\n * dependency suppliers named `createGateways` and `createServices`, because\n * `gateways` and `services` already name what they answer.\n *\n * ```ts\n * class TodoVM extends ALankaVM<ITodoState, ITodoActions, ITodoGateways> {\n * \tprotected readonly name = \"TodoVM\";\n *\n * \tprotected states(): ITodoState {\n * \t\treturn { todos: [], isLoading: false };\n * \t}\n *\n * \tprotected createGateways(): ITodoGateways {\n * \t\treturn { todo: new TodoGateway() };\n * \t}\n *\n * \tprotected createActions(): ITodoActions {\n * \t\treturn {\n * \t\t\tload: async () => {\n * \t\t\t\tthis.set({ isLoading: true });\n * \t\t\t\tthis.set({ todos: await this.gateways.todo.list(), isLoading: false });\n * \t\t\t},\n * \t\t};\n * \t}\n * }\n *\n * export const useTodoVM = new TodoVM().build();\n * ```\n *\n * The access-tracking blind spot the functional style documents is the same one\n * here, and `enableAccessTrackingOptimization` is the same switch. A consumer\n * re-renders only for state keys it READ off the returned proxy; an action that\n * DERIVES a value reads the store through `get`, which the proxy never sees, so a\n * component whose only link to a key is such a getter never re-renders for it. In\n * development the mismatch announces itself by name rather than by a frozen\n * screen. Canon: `skills/parity/SKILL.md`.\n */\nexport abstract class ALankaVM<\n\tState extends object,\n\tActions extends object,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n> extends ALankaVMEnvironment<TGateways, Services> {\n\t/** Names the ViewModel in the logs, the scenario registry and the blind-spot warning. */\n\tprotected abstract readonly name: string;\n\n\t/**\n\t * Turn off when one broad consumer reads most fields, or when an action derives\n\t * what the screen shows — proxy tracking then costs more than it saves, and in\n\t * the second case it cannot see the read at all.\n\t */\n\tprotected readonly enableAccessTrackingOptimization: boolean = true;\n\n\t/** Writes state. Available from `createActions` onwards, never before. */\n\tprotected set!: StoreApi<State & Actions & ILankaScenarioVM>[\"setState\"];\n\n\t/** Reads state. The read a tracked hook cannot see — hence the switch above. */\n\tprotected get!: () => State & Actions & ILankaScenarioVM;\n\n\t/** Fires a scenario, which every ViewModel bound to it then hears. */\n\tprotected trigger = <TData>(scenario: ILankaScenario<TData>, data?: TData): void => {\n\t\tscenario.trigger(data);\n\t};\n\n\t/** The reactive fields the screen reads. */\n\tprotected states(): State {\n\t\treturn {} as State;\n\t}\n\n\t/** The scenarios this ViewModel listens to, unsubscribed for it on reset. */\n\tprotected scenarioHandlers(): TUnknownLankaScenarioBinding<\n\t\tState & Actions,\n\t\tTGateways,\n\t\tServices\n\t>[] {\n\t\treturn [];\n\t}\n\n\t/** Store middleware — `persist`, `lankaDevtools` — the last one applied outermost. */\n\tprotected enhancers(): TLankaVMEnhancer<State & Actions & ILankaScenarioVM>[] {\n\t\treturn [];\n\t}\n\n\t/** The actions the screen calls. Written against `this.set` and `this.get`. */\n\tprotected abstract createActions(): Actions;\n\n\t/**\n\t * The protected surface as an object, for the functional style.\n\t *\n\t * Assembled INSIDE the class because that is the only place `protected` can be\n\t * read — a context built from outside could carry only the public half, which is\n\t * the wrong half. Canon: `skills/parity/SKILL.md` section 3a.\n\t */\n\tprotected toStyleContext(): ILankaVMContext<\n\t\tState & Actions & ILankaScenarioVM,\n\t\tTGateways,\n\t\tServices\n\t> {\n\t\treturn {\n\t\t\tset: this.set,\n\t\t\tget: this.get,\n\t\t\tgateways: this.gateways,\n\t\t\tservices: this.services,\n\t\t\ttrigger: this.trigger,\n\t\t};\n\t}\n\n\t/** Builds the hook a screen calls. One store per call. */\n\tpublic build(): UseBoundStore<StoreApi<State & Actions & ILankaScenarioVM>> {\n\t\ttype TFullState = State & Actions & ILankaScenarioVM;\n\n\t\tlankaLogger.printViewModelLog(\"START Create VM\", this.name);\n\n\t\tconst blindSpot = createLankaBlindSpotTrap(\n\t\t\tthis.name,\n\t\t\tgetLankaFlags().isDevelopment === true,\n\t\t);\n\n\t\t// Asked once. Every call builds a fresh array, and this one used to be made\n\t\t// twice per ViewModel: once to bind the scenarios, once to decide whether to\n\t\t// register the ViewModel at all.\n\t\tconst bindings = this.scenarioHandlers();\n\n\t\tconst stateCreator: TLankaVMStateCreator<TFullState> = (set, get) => {\n\t\t\tthis.set = set;\n\t\t\tthis.get = blindSpot.observeGet(get);\n\t\t\tthis.gateways = this.createGateways();\n\t\t\tthis.services = this.createServices();\n\n\t\t\tconst actions = blindSpot.observeActions(this.createActions());\n\n\t\t\tconst { initializeScenario, resetScenario } = createLankaScenarioBinder({\n\t\t\t\tname: this.name,\n\t\t\t\tbindings,\n\t\t\t\tcontext: () => this.toStyleContext(),\n\t\t\t\tonInit: () => {\n\t\t\t\t\tthis.onInit();\n\t\t\t\t},\n\t\t\t\tonReset: () => {\n\t\t\t\t\tthis.onReset();\n\t\t\t\t},\n\t\t\t});\n\n\t\t\treturn {\n\t\t\t\t...this.states(),\n\t\t\t\t...actions,\n\t\t\t\tinitializeScenario,\n\t\t\t\tresetScenario,\n\t\t\t};\n\t\t};\n\n\t\tconst enhancedCreator = this.enhancers().reduce<TLankaVMStateCreator<TFullState>>(\n\t\t\t(creator, enhance) => enhance(creator),\n\t\t\tstateCreator,\n\t\t);\n\n\t\tconst store = create<TFullState>()(enhancedCreator);\n\n\t\tconst registerScenarioViewModel = (viewModel: ILankaScenarioVM): void => {\n\t\t\tif (bindings.length > 0) {\n\t\t\t\tlankaScenarioBootstrap.registerViewModel(viewModel, this.name);\n\t\t\t}\n\t\t};\n\n\t\tif (!this.enableAccessTrackingOptimization) {\n\t\t\tregisterScenarioViewModel(store.getState());\n\t\t\tlankaLogger.printViewModelLog(\"FINISH Create VM\", this.name);\n\n\t\t\treturn store;\n\t\t}\n\n\t\tconst useOptimizedViewModel = createLankaTrackedHook<TFullState>({\n\t\t\tsubscribe: (onChange) => store.subscribe(onChange),\n\t\t\treadState: () => store.getState(),\n\t\t\tonUntrackedChange: blindSpot.isArmed ? blindSpot.report : undefined,\n\t\t}) as UseBoundStore<StoreApi<TFullState>>;\n\n\t\tuseOptimizedViewModel.setState = store.setState;\n\t\tuseOptimizedViewModel.getState = store.getState;\n\t\tuseOptimizedViewModel.getInitialState = store.getInitialState;\n\t\tuseOptimizedViewModel.subscribe = store.subscribe;\n\n\t\tregisterScenarioViewModel(useOptimizedViewModel.getState());\n\n\t\tlankaLogger.printViewModelLog(\"FINISH Create VM\", this.name);\n\n\t\treturn useOptimizedViewModel;\n\t}\n}\n","export interface ILankaBlindSpotTrap {\n\t/** Whether the trap is armed. Everything below is inert when it is not. */\n\treadonly isArmed: boolean;\n\t/** Wraps `get` so reads made inside an action are attributed to it. */\n\tobserveGet: <TState>(get: () => TState) => () => TState;\n\t/** Wraps the actions so the trap knows which one is running. */\n\tobserveActions: <TActions extends object>(declared: TActions) => TActions;\n\t/** Reports a change that will not re-render, when the component reads the key. */\n\treport: (\n\t\ttrackedKeys: Set<string>,\n\t\tnext: Record<string, unknown>,\n\t\tprev: Record<string, unknown>,\n\t) => void;\n}\n\n/**\n * The blind spot: a key the component reads through a GETTER.\n *\n * Access tracking sees direct reads off the proxy. A key reached only inside a\n * derived getter is invisible to it, so a change to that key re-renders nothing\n * and the screen freezes with no error anywhere.\n *\n * The trap watches which keys each action reads through `get()`, and warns when\n * one of those changes without a tracked key changing with it.\n *\n * Development only: in production this is work on a hot path plus console noise\n * for somebody who does not write the code. Disarmed, every method is identity.\n */\nexport const createLankaBlindSpotTrap = (\n\tviewModelName: string,\n\tisArmed: boolean,\n): ILankaBlindSpotTrap => {\n\tif (!isArmed) {\n\t\treturn {\n\t\t\tisArmed: false,\n\t\t\tobserveGet: (get) => get,\n\t\t\tobserveActions: (declared) => declared,\n\t\t\treport: () => undefined,\n\t\t};\n\t}\n\n\t/** Action name → state keys it read through `get()`, past the proxy. */\n\tconst indirectReads = new Map<string, Set<string>>();\n\t/** Keys already warned about: a second warning adds nothing. */\n\tconst warnedKeys = new Set<string>();\n\tlet activeActionName: string | null = null;\n\n\treturn {\n\t\tisArmed: true,\n\n\t\tobserveGet<TState>(get: () => TState): () => TState {\n\t\t\treturn () => {\n\t\t\t\tconst state = get();\n\t\t\t\tconst actionName = activeActionName;\n\t\t\t\tif (actionName === null) return state;\n\n\t\t\t\treturn new Proxy(state as object, {\n\t\t\t\t\tget(target, prop, receiver) {\n\t\t\t\t\t\tif (typeof prop === \"string\") {\n\t\t\t\t\t\t\tlet keys = indirectReads.get(actionName);\n\t\t\t\t\t\t\tif (!keys) {\n\t\t\t\t\t\t\t\tkeys = new Set<string>();\n\t\t\t\t\t\t\t\tindirectReads.set(actionName, keys);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tkeys.add(prop);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn Reflect.get(target, prop, receiver) as unknown;\n\t\t\t\t\t},\n\t\t\t\t}) as TState;\n\t\t\t};\n\t\t},\n\n\t\tobserveActions<TActions extends object>(declared: TActions): TActions {\n\t\t\tconst observed = { ...declared } as Record<string, unknown>;\n\n\t\t\tfor (const [name, value] of Object.entries(declared)) {\n\t\t\t\tif (typeof value !== \"function\") continue;\n\n\t\t\t\tobserved[name] = (...args: unknown[]) => {\n\t\t\t\t\t// Restored rather than cleared: actions call each other, and clearing\n\t\t\t\t\t// would attribute the caller's later reads to nobody.\n\t\t\t\t\tconst previous = activeActionName;\n\t\t\t\t\tactiveActionName = name;\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn (value as (...a: unknown[]) => unknown)(...args);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tactiveActionName = previous;\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn observed as TActions;\n\t\t},\n\n\t\treport(trackedKeys, next, prev): void {\n\t\t\tfor (const [changedKey, value] of Object.entries(next)) {\n\t\t\t\tif (Object.is(value, prev[changedKey])) continue;\n\t\t\t\tif (trackedKeys.has(changedKey) || warnedKeys.has(changedKey)) continue;\n\n\t\t\t\t// Not every untracked key is a fault: not reading what you do not need\n\t\t\t\t// is exactly what tracking exists for. The fault is a key the component\n\t\t\t\t// DOES read — through a getter taken off the proxy.\n\t\t\t\tconst viaGetter = [...trackedKeys].some((key) =>\n\t\t\t\t\tindirectReads.get(key)?.has(changedKey),\n\t\t\t\t);\n\t\t\t\tif (!viaGetter) continue;\n\n\t\t\t\twarnedKeys.add(changedKey);\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[lanka] ${viewModelName}: key \"${changedKey}\" changed but no re-render will follow. ` +\n\t\t\t\t\t\t`The component reads it only through a getter, and tracking sees direct proxy reads only. ` +\n\t\t\t\t\t\t`Set enableAccessTrackingOptimization: false on this ViewModel — ` +\n\t\t\t\t\t\t`destructuring the key in the view \"for the side effect\" reads as dead code and will not survive a refactor.`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t};\n};\n","/**\n * A subscription option bag, as wide as the bus accepts.\n *\n * The binder passes it through and reads only `usedBy`; naming the rest here\n * would make this file a second declaration of the bus's options.\n */\nexport type TLankaScenarioBindingOptions = Record<string, unknown> & { usedBy?: string };\n\n/**\n * What the binder needs of a binding, and nothing more.\n *\n * Structural rather than the concrete `ILankaScenarioBinding`: three ViewModel\n * families declare their own binding type over their own context, and the binder\n * only ever calls `subscribe` and `handler`.\n */\nexport interface ILankaScenarioBindingLike<TContext, TData = unknown> {\n\tscenario: {\n\t\teventType: string;\n\t\tsubscribe: (\n\t\t\tcallback: (data?: TData) => void,\n\t\t\toptions?: TLankaScenarioBindingOptions,\n\t\t) => () => void;\n\t};\n\thandler: (context: TContext) => (data?: TData) => void;\n\toptions?: TLankaScenarioBindingOptions;\n}\n\nexport interface ILankaScenarioBinderConfig<TContext> {\n\t/** The ViewModel's name, reported to the bus as the subscriber. */\n\tname: string;\n\t/** What to bind. A ViewModel with none still gets a working binder. */\n\tbindings?: readonly ILankaScenarioBindingLike<TContext>[];\n\t/** The context handlers are built with, read at bind time. */\n\tcontext: () => TContext;\n\tonInit?: (context: TContext) => void;\n\tonReset?: (context: TContext) => void;\n}\n\nexport interface ILankaScenarioBinder {\n\t/** Whether the bindings are live. */\n\treadonly isInitialized: boolean;\n\t/** Subscribes every binding once. A second call does nothing. */\n\tinitializeScenario: () => void;\n\t/** Releases every subscription and allows a later re-initialisation. */\n\tresetScenario: () => void;\n}\n\n/**\n * The scenario lifetime of a ViewModel: bind once, release on reset.\n *\n * All three ViewModel families need exactly this, and all three had written it\n * out — two with an array plus a Set of seen event types, one with a Map. The\n * Map is the shape kept, because it does both jobs with one structure: the key\n * prevents a second subscription to the same event, and the value is the\n * function that releases THIS subscription.\n *\n * Releasing by callback identity, which an array invites, removes the first\n * entry carrying that callback rather than the caller's own — two handlers whose\n * closures compare equal cancel each other.\n */\nexport const createLankaScenarioBinder = <TContext>(\n\tconfig: ILankaScenarioBinderConfig<TContext>,\n): ILankaScenarioBinder => {\n\tconst subscriptions = new Map<string, () => void>();\n\tlet isInitialized = false;\n\n\treturn {\n\t\tget isInitialized(): boolean {\n\t\t\treturn isInitialized;\n\t\t},\n\n\t\tinitializeScenario(): void {\n\t\t\tif (isInitialized) return;\n\n\t\t\tconst context = config.context();\n\n\t\t\tfor (const binding of config.bindings ?? []) {\n\t\t\t\tconst key = binding.scenario.eventType;\n\t\t\t\tif (subscriptions.has(key)) continue;\n\n\t\t\t\tsubscriptions.set(\n\t\t\t\t\tkey,\n\t\t\t\t\tbinding.scenario.subscribe(binding.handler(context), {\n\t\t\t\t\t\tusedBy: config.name,\n\t\t\t\t\t\t...binding.options,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconfig.onInit?.(context);\n\t\t\tisInitialized = true;\n\t\t},\n\n\t\tresetScenario(): void {\n\t\t\tfor (const release of subscriptions.values()) release();\n\t\t\tsubscriptions.clear();\n\t\t\tisInitialized = false;\n\n\t\t\tconfig.onReset?.(config.context());\n\t\t},\n\t};\n};\n","import { useCallback, useRef, useSyncExternalStore } from \"react\";\n\nexport interface ILankaTrackedHookConfig<TState extends object> {\n\t/**\n\t * Subscribes to the source, reporting both states already in FULL shape.\n\t *\n\t * A shared-store ViewModel composes its full state from a store slice, so the\n\t * shaping happens here rather than inside the hook: the hook compares states,\n\t * it does not know how one is assembled.\n\t */\n\tsubscribe: (onChange: (next: TState, prev: TState) => void) => () => void;\n\t/** The current full state. */\n\treadState: () => TState;\n\t/**\n\t * Called when a change touched no tracked key, so no re-render will follow.\n\t *\n\t * The one seam the two ViewModel families differ on: only the plain factory\n\t * reports the blind spot, and only in development.\n\t */\n\tonUntrackedChange?: (\n\t\ttrackedKeys: Set<string>,\n\t\tnext: Record<string, unknown>,\n\t\tprev: Record<string, unknown>,\n\t) => void;\n}\n\nconst asRecord = (state: object): Record<string, unknown> => state as Record<string, unknown>;\n\n/**\n * The access-tracking hook every ViewModel factory renders through.\n *\n * Without a selector the component receives a Proxy that records which keys it\n * read; the next change re-renders only if one of THOSE keys moved. With a\n * selector the selector decides and tracking is bypassed.\n *\n * Both ViewModel families needed exactly this, and differed only in where the\n * state comes from — a store of their own, or a slice of a shared one. Those are\n * the two parameters above; the eighty lines below were copied.\n */\nexport const createLankaTrackedHook = <TState extends object>(\n\tconfig: ILankaTrackedHookConfig<TState>,\n) => {\n\treturn (selector?: (state: TState) => unknown): unknown => {\n\t\tconst selectorRef = useRef(selector);\n\t\tselectorRef.current = selector;\n\n\t\tconst trackedKeysRef = useRef<Set<string>>(new Set());\n\t\tconst trackedStateRef = useRef<TState | null>(null);\n\t\tconst trackedProxyRef = useRef<TState | null>(null);\n\n\t\t/**\n\t\t * Stable identity; the empty dependency list is deliberate.\n\t\t *\n\t\t * `useSyncExternalStore` keeps `subscribe` in an effect keyed on its\n\t\t * identity, so an inline arrow makes React tear the subscription down and\n\t\t * rebuild it on EVERY render of EVERY connected component — measured at 201\n\t\t * subscriptions for 200 renders. The body reads only refs and the\n\t\t * factory-scope config, never a prop or a render-scoped value, so there is\n\t\t * nothing for `[]` to capture stale.\n\t\t */\n\t\tconst subscribe = useCallback(\n\t\t\t(onStoreChange: () => void) =>\n\t\t\t\tconfig.subscribe((nextState, prevState) => {\n\t\t\t\t\tif (selectorRef.current) {\n\t\t\t\t\t\tonStoreChange();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst trackedKeys = trackedKeysRef.current;\n\t\t\t\t\tif (trackedKeys.size === 0) {\n\t\t\t\t\t\tonStoreChange();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst next = asRecord(nextState);\n\t\t\t\t\tconst prev = asRecord(prevState);\n\n\t\t\t\t\tfor (const key of trackedKeys) {\n\t\t\t\t\t\tif (!Object.is(next[key], prev[key])) {\n\t\t\t\t\t\t\tonStoreChange();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Reaching here means NO re-render will follow. If the changed key is\n\t\t\t\t\t// linked to the component through a getter it read, the screen froze.\n\t\t\t\t\tconfig.onUntrackedChange?.(trackedKeys, next, prev);\n\t\t\t\t}),\n\t\t\t[],\n\t\t);\n\n\t\treturn useSyncExternalStore(subscribe, readTracked, readUntracked);\n\n\t\tfunction readTracked(): unknown {\n\t\t\tconst state = config.readState();\n\t\t\tconst activeSelector = selectorRef.current;\n\n\t\t\tif (activeSelector) return activeSelector(state);\n\n\t\t\tif (trackedStateRef.current === state && trackedProxyRef.current) {\n\t\t\t\treturn trackedProxyRef.current;\n\t\t\t}\n\n\t\t\tconst trackedKeys = new Set<string>();\n\t\t\tconst proxyState = new Proxy(state, {\n\t\t\t\tget(target, prop, receiver) {\n\t\t\t\t\tif (typeof prop === \"string\") {\n\t\t\t\t\t\ttrackedKeys.add(prop);\n\t\t\t\t\t}\n\t\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttrackedKeysRef.current = trackedKeys;\n\t\t\ttrackedStateRef.current = state;\n\t\t\ttrackedProxyRef.current = proxyState;\n\n\t\t\treturn proxyState;\n\t\t}\n\n\t\t/**\n\t\t * The server snapshot: the state itself, never the Proxy.\n\t\t *\n\t\t * Tracking exists to skip renders a client would otherwise do; a server\n\t\t * renders once, and handing it a recording Proxy would only add work whose\n\t\t * result nothing reads.\n\t\t */\n\t\tfunction readUntracked(): unknown {\n\t\t\tconst state = config.readState();\n\t\t\tconst activeSelector = selectorRef.current;\n\n\t\t\treturn activeSelector ? activeSelector(state) : state;\n\t\t}\n\t};\n};\n","/**\n * A dependency bag given either directly or as a factory.\n *\n * The factory form exists so a ViewModel declared at module level does not\n * resolve its gateways at import time: the locator needs an active framework\n * instance, and a module body runs before one exists.\n */\nexport type TLankaDependencyBag<TBag extends object> = TBag | (() => TBag) | undefined;\n\n/**\n * Reads a dependency bag, whichever form it was declared in.\n *\n * All three ViewModel factories wrote this out twice each — once for gateways,\n * once for services — which is six copies of one three-line decision.\n */\nexport const resolveLankaDependency = <TBag extends object>(\n\tdeclared: TLankaDependencyBag<TBag>,\n): TBag => {\n\tif (typeof declared === \"function\") return declared();\n\treturn declared ?? ({} as TBag);\n};\n","import { StoreApi, UseBoundStore } from \"zustand\";\nimport { ALankaVM } from \"../../_abstractions/lanka-vm/ALankaVM\";\nimport { resolveLankaDependency } from \"../../_utils/resolve-lanka-dependency/resolveLankaDependency\";\nimport { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\nimport type { ILankaVMConfig } from \"../../_interfaces/ILankaVMConfig\";\n\n/**\n * The functional style of `ALankaVM`: a ViewModel declared as an options object.\n *\n * Everything it can do, the class can do, because this IS the class — the hooks a\n * subclass overrides arrive here as config fields of the same names, and the\n * protected surface arrives as the `ctx` every hook is handed. What a ViewModel is\n * and how it binds scenarios is documented once, on `ALankaVM`.\n *\n * ⚠️ ACCESS-TRACKING BLIND SPOT. A consumer re-renders only for state keys it READ\n * off the returned proxy. An action that DERIVES a value (`getSomeView()`) reads the\n * store through `get()`, which the proxy never sees — so a component whose only link\n * to a state key is such a getter will never re-render when that key changes.\n *\n * Set `enableAccessTrackingOptimization: false` on such a ViewModel. Do NOT patch it\n * in the view by destructuring the underlying keys for their side effect only: that\n * reads as dead code, so a refactor, an unused-variable cleanup or a lint autofix\n * removes it and the screen silently freezes again. `MeetingReportViewModel` carries\n * the worked example (its report toggles froze exactly that way, twice).\n *\n * In development the mismatch ANNOUNCES ITSELF: the framework sees that a key\n * changed, that no re-render will follow, and that the component reads that key\n * through a getter — and warns with the ViewModel and key names. \"Remember to\n * set the flag\" is not a mechanism.\n */\nexport function createLankaVM<State extends object, Actions extends object>(\n\tconfig: ILankaVMConfig<State, Actions, Record<string, never>, Record<string, never>>,\n): UseBoundStore<StoreApi<State & Actions & ILankaScenarioVM>>;\n\nexport function createLankaVM<\n\tState extends object,\n\tActions extends object,\n\tServices extends object,\n>(\n\tconfig: ILankaVMConfig<State, Actions, Record<string, never>, Services>,\n): UseBoundStore<StoreApi<State & Actions & ILankaScenarioVM>>;\n\nexport function createLankaVM<\n\tState extends object,\n\tActions extends object,\n\tTGateways extends object,\n>(\n\tconfig: ILankaVMConfig<State, Actions, TGateways, Record<string, never>>,\n): UseBoundStore<StoreApi<State & Actions & ILankaScenarioVM>>;\n\nexport function createLankaVM<\n\tState extends object,\n\tActions extends object,\n\tTGateways extends object,\n\tServices extends object,\n>(\n\tconfig: ILankaVMConfig<State, Actions, TGateways, Services>,\n): UseBoundStore<StoreApi<State & Actions & ILankaScenarioVM>>;\n\nexport function createLankaVM<\n\tState extends object,\n\tActions extends object,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n>(\n\tconfig: ILankaVMConfig<State, Actions, TGateways, Services>,\n): UseBoundStore<StoreApi<State & Actions & ILankaScenarioVM>> {\n\t/**\n\t * The bridge subclass lives here rather than in a shared helper because\n\t * `toStyleContext` is `protected`: only a class body deriving from `ALankaVM`\n\t * may read it. Canon: `skills/parity/SKILL.md` section 3a.\n\t */\n\tclass FunctionalVM extends ALankaVM<State, Actions, TGateways, Services> {\n\t\tprotected readonly name = config.name;\n\n\t\tprotected override readonly enableAccessTrackingOptimization =\n\t\t\tconfig.enableAccessTrackingOptimization ?? true;\n\n\t\tprotected override states(): State {\n\t\t\treturn config.states ?? ({} as State);\n\t\t}\n\n\t\tprotected override scenarioHandlers(): NonNullable<typeof config.scenarioHandlers> {\n\t\t\treturn config.scenarioHandlers ?? [];\n\t\t}\n\n\t\tprotected override enhancers(): NonNullable<typeof config.enhancers> {\n\t\t\treturn config.enhancers ?? [];\n\t\t}\n\n\t\tprotected override createGateways(): TGateways {\n\t\t\treturn resolveLankaDependency(config.gateways);\n\t\t}\n\n\t\tprotected override createServices(): Services {\n\t\t\treturn resolveLankaDependency(config.services);\n\t\t}\n\n\t\tprotected createActions(): Actions {\n\t\t\treturn config.createActions(this.toStyleContext());\n\t\t}\n\n\t\tprotected override onInit(): void {\n\t\t\tconfig.onInit?.(this.toStyleContext());\n\t\t}\n\n\t\tprotected override onReset(): void {\n\t\t\tconfig.onReset?.(this.toStyleContext());\n\t\t}\n\t}\n\n\treturn new FunctionalVM().build();\n}\n","import { lankaLogger } from \"../../../logger/lanka-logger/LankaLogger\";\n\n/**\n * What a lazy hook needs of the store behind it.\n *\n * Stated rather than cast: releasing a ViewModel means unsubscribing its\n * scenarios, so the mechanism does require this much — and every store it is\n * given has it, because `ILankaScenarioVM` is part of all three VM states.\n */\nexport interface ILankaReleasableStore {\n\tgetState: () => { resetScenario: () => void };\n}\n\n/** What every lazy factory is handed: a name for the log, and how to build. */\nexport interface ILankaLazyHookConfig<TStore> {\n\t/** The ViewModel's name, as the log line says it. */\n\tname: string;\n\t/** What the log calls this kind of ViewModel — `VM`, `slVM`, `ssVM`. */\n\tkind: string;\n\t/** Builds the real store. Called at most once until `release`. */\n\tcreate: () => TStore;\n}\n\n/** A lazily built store: everything the store is, plus `dispose`. */\nexport type TLazyLankaHook<TStore> = TStore & { dispose: () => void };\n\n/** The one store a lazy hook stands in front of, built at most once. */\ninterface ILankaLazySlot<TStore> {\n\tget: () => TStore;\n\trelease: () => void;\n}\n\n/**\n * Build once, release on demand: the state a lazy hook is made of.\n *\n * Separate from the forwarding below because they answer different questions —\n * WHEN the store exists, and WHERE a call goes. Read together they were one\n * function of fifty lines, which the composition canon calls what it is.\n */\nconst lazySlot = <TStore extends ILankaReleasableStore>(\n\tconfig: ILankaLazyHookConfig<TStore>,\n): ILankaLazySlot<TStore> => {\n\tlet store: TStore | null = null;\n\n\treturn {\n\t\tget: () => {\n\t\t\tif (!store) {\n\t\t\t\tlankaLogger.printViewModelLog(\n\t\t\t\t\t`LAZY: Creating ${config.kind} on first access`,\n\t\t\t\t\tconfig.name,\n\t\t\t\t);\n\t\t\t\tstore = config.create();\n\t\t\t}\n\t\t\treturn store;\n\t\t},\n\n\t\t/**\n\t\t * Releases the store. The next access builds a new one.\n\t\t *\n\t\t * Scenario subscriptions go first, through `resetScenario` — the same path\n\t\t * the between-tests reset uses. Dropping the reference without\n\t\t * unsubscribing would leave the bus holding handlers that write into a\n\t\t * discarded store.\n\t\t *\n\t\t * On a slot that never built, this does NOTHING: building a store in order\n\t\t * to destroy it is work with no result, and it would resurrect a ViewModel\n\t\t * a closed screen had just released.\n\t\t */\n\t\trelease: () => {\n\t\t\tif (!store) return;\n\t\t\tstore.getState().resetScenario();\n\t\t\tstore = null;\n\t\t},\n\t};\n};\n\n/**\n * How a member reaches the store: through a wrapper, always.\n *\n * The trap returns a FUNCTION for every member rather than the member itself, so\n * reading `useVM.setState` builds nothing and calling it builds the store. A trap\n * that resolved eagerly would end laziness the moment a devtool, a spread or a\n * debugger looked at the object — which is most of the ways an object is looked\n * at.\n *\n * `dispose` is the exception in both directions: it is not the store's, and it\n * must not build one.\n */\nconst forwardEveryMember =\n\t<TStore>(slot: ILankaLazySlot<TStore>) =>\n\t(_target: object, property: string | symbol): unknown => {\n\t\tif (property === \"dispose\") return slot.release;\n\n\t\treturn (...args: unknown[]) => {\n\t\t\tconst built = slot.get();\n\t\t\tconst member = (built as Record<string | symbol, unknown>)[property];\n\n\t\t\t// Every member of a zustand store is a method, and so is every one a\n\t\t\t// ViewModel adds — `getStoreState` included. A value member cannot be\n\t\t\t// classified without building the store first, which is the one thing a\n\t\t\t// property READ may not do, so it is handed back from the call instead:\n\t\t\t// `useVM.whatever()` gives the value.\n\t\t\treturn typeof member === \"function\"\n\t\t\t\t? (member as (...rest: unknown[]) => unknown).apply(built, args)\n\t\t\t\t: member;\n\t\t};\n\t};\n\n/**\n * The lazy half of every ViewModel factory, written once.\n *\n * Three factories used to carry this mechanism: build on first access, keep the\n * store, hand every member through, release on `dispose`. They differed in the\n * one line that builds — and, as it turned out, in which members they had\n * remembered to hand through.\n *\n * ## Why a Proxy rather than a list of members\n *\n * The three copies attached members BY HAND, and the three lists differed:\n * `getState` + `getInitialState` + `setState` + `subscribe` for the plain one,\n * `getState` alone for the stateless, `getState` + `getStoreState` for the\n * shared-store. Each list matched its own type, so nothing was broken — but the\n * plain one MIRRORS a zustand store, and a mirror is a promise to keep in step\n * with something somebody else releases. The day zustand adds a member, three\n * files have to hear about it.\n *\n * A Proxy cannot be incomplete. What the built store has, the lazy hook has, and\n * the type each factory declares is what narrows it back down to that variant's\n * contract — a lazy variant promises exactly what its eager twin promises, plus\n * `dispose`.\n */\nexport const createLazyLankaHook = <TStore extends ILankaReleasableStore>(\n\tconfig: ILankaLazyHookConfig<TStore>,\n): TLazyLankaHook<TStore> => {\n\tconst slot = lazySlot(config);\n\n\t// The hook itself: a function, so `useVM()` and `useVM(selector)` work before\n\t// anything is built.\n\tconst hook = (selector?: (state: unknown) => unknown): unknown => {\n\t\tconst built = slot.get() as unknown as (chosen?: unknown) => unknown;\n\t\treturn selector ? built(selector) : built();\n\t};\n\n\treturn new Proxy(hook, { get: forwardEveryMember(slot) }) as unknown as TLazyLankaHook<TStore>;\n};\n","import { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\nimport { createLazyLankaHook } from \"../../_internal/create-lazy-lanka-hook/createLazyLankaHook\";\nimport { createLankaVM } from \"../create-lanka-vm/createLankaVM\";\nimport type { ILankaVMConfig } from \"../../_interfaces/ILankaVMConfig\";\n\nexport function createLazyLankaVM<State extends object, Actions extends object>(\n\tconfig: ILankaVMConfig<State, Actions, Record<string, never>, Record<string, never>>,\n): TLazyLankaVM<\n\tReturnType<typeof createLankaVM<State, Actions, Record<string, never>, Record<string, never>>>,\n\tState & Actions & ILankaScenarioVM\n>;\n\nexport function createLazyLankaVM<\n\tState extends object,\n\tActions extends object,\n\tServices extends object,\n>(\n\tconfig: ILankaVMConfig<State, Actions, Record<string, never>, Services>,\n): TLazyLankaVM<\n\tReturnType<typeof createLankaVM<State, Actions, Record<string, never>, Services>>,\n\tState & Actions & ILankaScenarioVM\n>;\n\nexport function createLazyLankaVM<\n\tState extends object,\n\tActions extends object,\n\tTGateways extends object,\n>(\n\tconfig: ILankaVMConfig<State, Actions, TGateways, Record<string, never>>,\n): TLazyLankaVM<\n\tReturnType<typeof createLankaVM<State, Actions, TGateways, Record<string, never>>>,\n\tState & Actions & ILankaScenarioVM\n>;\n\nexport function createLazyLankaVM<\n\tState extends object,\n\tActions extends object,\n\tTGateways extends object,\n\tServices extends object,\n>(\n\tconfig: ILankaVMConfig<State, Actions, TGateways, Services>,\n): TLazyLankaVM<\n\tReturnType<typeof createLankaVM<State, Actions, TGateways, Services>>,\n\tState & Actions & ILankaScenarioVM\n>;\n\n/**\n * The lazy `createLankaVM`: nothing is built until a screen asks.\n *\n * For a ViewModel a session may never open — a settings screen, an admin panel,\n * a route behind a flag. The eager factory builds its store at module load, and\n * this one waits, which is the difference between paying for every screen the\n * application has and paying for the screens it shows.\n *\n * The mechanism is `createLazyLankaHook`, shared with the stateless and\n * shared-store variants, so all three hand through every member the store has\n * and release the same way. This file is the one line that says what gets built.\n */\nexport function createLazyLankaVM<\n\tState extends object,\n\tActions extends object,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n>(config: ILankaVMConfig<State, Actions, TGateways, Services>) {\n\treturn createLazyLankaHook({\n\t\tname: config.name,\n\t\tkind: \"VM\",\n\t\tcreate: () => createLankaVM(config),\n\t});\n}\n\n/**\n * A lazy ViewModel hook: everything an ordinary store does, plus `dispose`.\n */\nexport type TLazyLankaVM<TStore, TFullState> = TStore & {\n\tgetState: () => TFullState;\n\tdispose: () => void;\n};\n","import { ALankaVMEnvironment } from \"../lanka-vm-environment/ALankaVMEnvironment\";\nimport { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\nimport { lankaScenarioBootstrap } from \"../../../scenario/lanka-scenario-bootstrap/LankaScenarioBootstrap\";\nimport { lankaLogger } from \"../../../logger/lanka-logger/LankaLogger\";\nimport { createLankaScenarioBinder } from \"../../_internal/create-lanka-scenario-binder/createLankaScenarioBinder\";\nimport type { ILankaScenario } from \"../../../scenario/_interfaces/ILankaScenario\";\nimport type {\n\tILankaStatelessScenarioBinding,\n\tILankaStatelessVMContext,\n\tTLankaSetState,\n\tTLankaStatelessVMHook,\n} from \"../../_factories/create-stateless-lanka-vm/createStatelessLankaVM\";\n\n/**\n * A ViewModel that holds no reactive state: actions, and what they orchestrate.\n *\n * The second rung of the ladder in `core/README.md` written as a class. A screen\n * that reads nothing and only DOES things — a sign-out, a share sheet, a form\n * whose fields live in the form library — pays for a zustand store it never\n * reads; this is the same role without one.\n *\n * The protected surface IS the functional context, member for member: `set`,\n * `get`, `gateways`, `services`, `trigger`. What the config supplies as a value\n * or a thunk, the class supplies by overriding a method of the same name, with\n * the two dependency suppliers named `createGateways` and `createServices`\n * because `gateways` and `services` already name what they answer.\n *\n * ```ts\n * class SessionVM extends ALankaStatelessVM<ISessionActions, ISessionGateways> {\n * \tprotected readonly name = \"SessionVM\";\n *\n * \tprotected createGateways(): ISessionGateways {\n * \t\treturn { session: new SessionGateway() };\n * \t}\n *\n * \tprotected createActions(): ISessionActions {\n * \t\treturn {\n * \t\t\tsignOut: async () => {\n * \t\t\t\tawait this.gateways.session.signOut();\n * \t\t\t\tthis.trigger(sessionEnded);\n * \t\t\t},\n * \t\t};\n * \t}\n * }\n *\n * export const useSessionVM = new SessionVM().build();\n * ```\n *\n * Canon: `skills/parity/SKILL.md`.\n */\nexport abstract class ALankaStatelessVM<\n\tActions extends object,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n> extends ALankaVMEnvironment<TGateways, Services> {\n\t/** Names the ViewModel in the logs, the scenario registry and any warning. */\n\tprotected abstract readonly name: string;\n\n\t/** Writes state. Available from `createActions` onwards, never before. */\n\tprotected set!: TLankaSetState<Actions & ILankaScenarioVM>;\n\n\t/** Reads what the actions have written, including the actions themselves. */\n\tprotected get!: () => Actions & ILankaScenarioVM;\n\n\t/** Fires a scenario, which every ViewModel bound to it then hears. */\n\tprotected trigger = <TData>(scenario: ILankaScenario<TData>, data?: TData): void => {\n\t\tscenario.trigger(data);\n\t};\n\n\t/** The scenarios this ViewModel listens to, unsubscribed for it on reset. */\n\tprotected scenarioHandlers(): ILankaStatelessScenarioBinding<\n\t\tunknown,\n\t\tActions & ILankaScenarioVM,\n\t\tTGateways,\n\t\tServices\n\t>[] {\n\t\treturn [];\n\t}\n\n\t/** The actions the screen calls. Written against `this.set` and `this.get`. */\n\tprotected abstract createActions(): Actions;\n\n\t/**\n\t * The protected surface as an object, for the functional style.\n\t *\n\t * Assembled INSIDE the class because that is the only place `protected` can be\n\t * read. Canon: `skills/parity/SKILL.md` section 3a.\n\t */\n\tprotected toStyleContext(): ILankaStatelessVMContext<\n\t\tActions & ILankaScenarioVM,\n\t\tTGateways,\n\t\tServices\n\t> {\n\t\treturn {\n\t\t\tset: this.set,\n\t\t\tget: this.get,\n\t\t\tgateways: this.gateways,\n\t\t\tservices: this.services,\n\t\t\ttrigger: this.trigger,\n\t\t};\n\t}\n\n\t/** Builds the hook a screen calls. One ViewModel per call. */\n\tpublic build(): TLankaStatelessVMHook<Actions> {\n\t\ttype TFullState = Actions & ILankaScenarioVM;\n\n\t\tlankaLogger.printViewModelLog(\"START Create slVM\", this.name);\n\n\t\tlet state = {} as TFullState;\n\n\t\tthis.get = () => state;\n\t\tthis.set = (partial, replace) => {\n\t\t\tconst next =\n\t\t\t\ttypeof partial === \"function\"\n\t\t\t\t\t? (partial as (current: TFullState) => TFullState)(state)\n\t\t\t\t\t: partial;\n\n\t\t\tstate = replace ? (next as TFullState) : { ...state, ...next };\n\t\t};\n\n\t\tthis.gateways = this.createGateways();\n\t\tthis.services = this.createServices();\n\n\t\tconst actions = this.createActions();\n\t\tconst bindings = this.scenarioHandlers();\n\n\t\tconst { initializeScenario, resetScenario } = createLankaScenarioBinder({\n\t\t\tname: this.name,\n\t\t\tbindings,\n\t\t\tcontext: () => this.toStyleContext(),\n\t\t\tonInit: () => {\n\t\t\t\tthis.onInit();\n\t\t\t},\n\t\t\tonReset: () => {\n\t\t\t\tthis.onReset();\n\t\t\t},\n\t\t});\n\n\t\tstate = { ...state, ...actions, initializeScenario, resetScenario };\n\n\t\tif (bindings.length > 0) {\n\t\t\tlankaScenarioBootstrap.registerViewModel(state, this.name);\n\t\t}\n\n\t\tconst useStatelessViewModel = ((selector?: (full: TFullState) => unknown) =>\n\t\t\tselector ? selector(state) : state) as TLankaStatelessVMHook<Actions>;\n\n\t\tuseStatelessViewModel.getState = () => state;\n\n\t\tlankaLogger.printViewModelLog(\"FINISH Create slVM\", this.name);\n\n\t\treturn useStatelessViewModel;\n\t}\n}\n","import type { TLankaReplayRequest } from \"../../../scenario/event-bus/lanka-event-bus-instance/LankaEventBusInstance\";\nimport type { TLankaScenarioHandler } from \"../../_types/TLankaScenarioHandler\";\nimport { resolveLankaDependency } from \"../../_utils/resolve-lanka-dependency/resolveLankaDependency\";\nimport { ALankaStatelessVM } from \"../../_abstractions/lanka-stateless-vm/ALankaStatelessVM\";\nimport { ILankaScenario } from \"../../../scenario/_interfaces/ILankaScenario\";\nimport { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\n\nexport type TLankaSetState<TState> = (\n\tpartial: TState | Partial<TState> | ((state: TState) => TState | Partial<TState>),\n\treplace?: boolean,\n) => void;\n\nexport interface ILankaStatelessVMContext<\n\tTState,\n\tTGateways extends object,\n\tTServices extends object,\n> {\n\tset: TLankaSetState<TState>;\n\tget: () => TState;\n\tgateways: TGateways;\n\tservices: TServices;\n\ttrigger: <T>(scenario: ILankaScenario<T>, data?: T) => void;\n}\n\nexport interface ILankaStatelessScenarioBinding<\n\tTData,\n\tTState extends object,\n\tTGateways extends object,\n\tTServices extends object,\n> {\n\tscenario: ILankaScenario<TData>;\n\thandler: (\n\t\tctx: ILankaStatelessVMContext<TState, TGateways, TServices>,\n\t) => TLankaScenarioHandler<TData>;\n\toptions?: {\n\t\tpriority?: number;\n\t\treplay?: TLankaReplayRequest;\n\t\tusedBy?: string;\n\t};\n}\n\nexport type TLankaStatelessVMConfig<\n\tActions extends object,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n> = {\n\tname: string;\n\tcreateActions: (\n\t\tctx: ILankaStatelessVMContext<Actions & ILankaScenarioVM, TGateways, Services>,\n\t) => Actions;\n\tscenarioHandlers?: ILankaStatelessScenarioBinding<\n\t\tunknown,\n\t\tActions & ILankaScenarioVM,\n\t\tTGateways,\n\t\tServices\n\t>[];\n\tservices?: Services | (() => Services);\n\tgateways?: TGateways | (() => TGateways);\n\tonInit?: (\n\t\tctx: ILankaStatelessVMContext<Actions & ILankaScenarioVM, TGateways, Services>,\n\t) => void;\n\tonReset?: (\n\t\tctx: ILankaStatelessVMContext<Actions & ILankaScenarioVM, TGateways, Services>,\n\t) => void;\n};\n\nexport type TLankaStatelessVMHook<Actions extends object> = {\n\t<TSelected = Actions & ILankaScenarioVM>(\n\t\tselector?: (full: Actions & ILankaScenarioVM) => TSelected,\n\t): TSelected;\n\tgetState: () => Actions & ILankaScenarioVM;\n};\n\nexport function createStatelessLankaVM<Actions extends object>(\n\tconfig: TLankaStatelessVMConfig<Actions, Record<string, never>, Record<string, never>>,\n): TLankaStatelessVMHook<Actions>;\n\nexport function createStatelessLankaVM<Actions extends object, Services extends object>(\n\tconfig: TLankaStatelessVMConfig<Actions, Record<string, never>, Services>,\n): TLankaStatelessVMHook<Actions>;\n\nexport function createStatelessLankaVM<Actions extends object, TGateways extends object>(\n\tconfig: TLankaStatelessVMConfig<Actions, TGateways, Record<string, never>>,\n): TLankaStatelessVMHook<Actions>;\n\nexport function createStatelessLankaVM<\n\tActions extends object,\n\tTGateways extends object,\n\tServices extends object,\n>(config: TLankaStatelessVMConfig<Actions, TGateways, Services>): TLankaStatelessVMHook<Actions>;\n\n/**\n * The functional style of `ALankaStatelessVM`: actions declared as an options object.\n *\n * Same outward shape as the stateful factory — a hook-like function with\n * `getState` — and no zustand store under it, because a ViewModel that holds\n * nothing has nothing to subscribe to. What it is and how it binds scenarios is\n * documented once, on the class.\n */\nexport function createStatelessLankaVM<\n\tActions extends object,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n>(config: TLankaStatelessVMConfig<Actions, TGateways, Services>): TLankaStatelessVMHook<Actions> {\n\t/**\n\t * The bridge subclass lives here rather than in a shared helper because\n\t * `toStyleContext` is `protected`: only a class body deriving from\n\t * `ALankaStatelessVM` may read it. Canon: `skills/parity/SKILL.md` section 3a.\n\t */\n\tclass FunctionalStatelessVM extends ALankaStatelessVM<Actions, TGateways, Services> {\n\t\tprotected readonly name = config.name;\n\n\t\tprotected override scenarioHandlers(): NonNullable<typeof config.scenarioHandlers> {\n\t\t\treturn config.scenarioHandlers ?? [];\n\t\t}\n\n\t\tprotected override createGateways(): TGateways {\n\t\t\treturn resolveLankaDependency(config.gateways);\n\t\t}\n\n\t\tprotected override createServices(): Services {\n\t\t\treturn resolveLankaDependency(config.services);\n\t\t}\n\n\t\tprotected createActions(): Actions {\n\t\t\treturn config.createActions(this.toStyleContext());\n\t\t}\n\n\t\tprotected override onInit(): void {\n\t\t\tconfig.onInit?.(this.toStyleContext());\n\t\t}\n\n\t\tprotected override onReset(): void {\n\t\t\tconfig.onReset?.(this.toStyleContext());\n\t\t}\n\t}\n\n\treturn new FunctionalStatelessVM().build();\n}\n","import { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\nimport { createStatelessLankaVM } from \"../create-stateless-lanka-vm/createStatelessLankaVM\";\nimport type { ILankaVMConfig } from \"../../_interfaces/ILankaVMConfig\";\nimport { createLazyLankaHook } from \"../../_internal/create-lazy-lanka-hook/createLazyLankaHook\";\n\nexport type TLankaStatelessVMConfig<\n\tActions extends object,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n> = Omit<ILankaVMConfig<object, Actions, TGateways, Services>, \"states\"> & {\n\tstates?: never;\n};\n\ntype TLazyStatelessReturn<\n\tActions extends object,\n\tTGateways extends object,\n\tServices extends object,\n> = ReturnType<typeof createStatelessLankaVM<Actions, TGateways, Services>> & {\n\tgetState: () => Actions & ILankaScenarioVM;\n\tdispose: () => void;\n};\n\nexport function createLazyStatelessLankaVM<Actions extends object>(\n\tconfig: TLankaStatelessVMConfig<Actions, Record<string, never>, Record<string, never>>,\n): TLazyStatelessReturn<Actions, Record<string, never>, Record<string, never>>;\n\nexport function createLazyStatelessLankaVM<Actions extends object, Services extends object>(\n\tconfig: TLankaStatelessVMConfig<Actions, Record<string, never>, Services>,\n): TLazyStatelessReturn<Actions, Record<string, never>, Services>;\n\nexport function createLazyStatelessLankaVM<Actions extends object, TGateways extends object>(\n\tconfig: TLankaStatelessVMConfig<Actions, TGateways, Record<string, never>>,\n): TLazyStatelessReturn<Actions, TGateways, Record<string, never>>;\n\nexport function createLazyStatelessLankaVM<\n\tActions extends object,\n\tTGateways extends object,\n\tServices extends object,\n>(\n\tconfig: TLankaStatelessVMConfig<Actions, TGateways, Services>,\n): TLazyStatelessReturn<Actions, TGateways, Services>;\n\n/**\n * The lazy `createStatelessLankaVM`: nothing is built until a screen asks.\n *\n * The mechanism is `createLazyLankaHook` — build on first access, hand every\n * member through, release on `dispose` — and this file is the one line that says\n * WHICH ViewModel is built. It used to be a copy of that mechanism, and the copy\n * had forgotten `setState`, `subscribe` and `getInitialState`: typed as the whole\n * store, absent at runtime.\n */\nexport function createLazyStatelessLankaVM<\n\tActions extends object,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n>(config: TLankaStatelessVMConfig<Actions, TGateways, Services>) {\n\treturn createLazyLankaHook({\n\t\tname: config.name,\n\t\tkind: \"slVM\",\n\t\tcreate: () => createStatelessLankaVM(config),\n\t});\n}\n","import { useStore } from \"zustand\";\nimport { resolveLankaDependency } from \"../../_utils/resolve-lanka-dependency/resolveLankaDependency\";\nimport { createLankaScenarioBinder } from \"../../_internal/create-lanka-scenario-binder/createLankaScenarioBinder\";\nimport { createLankaTrackedHook } from \"../../_internal/create-lanka-tracked-hook/createLankaTrackedHook\";\nimport { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\nimport { lankaScenarioBootstrap } from \"../../../scenario/lanka-scenario-bootstrap/LankaScenarioBootstrap\";\nimport { lankaLogger } from \"../../../logger/lanka-logger/LankaLogger\";\nimport type {\n\tILankaSharedStoreVMConfig,\n\tTLankaSharedStoreVMHook,\n} from \"../../_interfaces/ILankaSharedStoreVMConfig\";\nimport type { ILankaSharedStoreVMContext } from \"../../_interfaces/ILankaSharedStoreVMContext\";\nimport { ALankaSharedStore } from \"../../_abstractions/lanka-shared-store/ALankaSharedStore\";\n\n/**\n * Factory for ViewModels backed by an external shared store instance.\n * Multiple ViewModels can be created on top of the same store instance.\n */\nexport function createSharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n>(\n\tconfig: ILankaSharedStoreVMConfig<\n\t\tStoreState,\n\t\tActions,\n\t\tStore,\n\t\tRecord<string, never>,\n\t\tRecord<string, never>\n\t>,\n): TLankaSharedStoreVMHook<StoreState, Actions>;\n\nexport function createSharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tServices extends object,\n>(\n\tconfig: ILankaSharedStoreVMConfig<StoreState, Actions, Store, Record<string, never>, Services>,\n): TLankaSharedStoreVMHook<StoreState, Actions>;\n\nexport function createSharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tTGateways extends object,\n>(\n\tconfig: ILankaSharedStoreVMConfig<StoreState, Actions, Store, TGateways, Record<string, never>>,\n): TLankaSharedStoreVMHook<StoreState, Actions>;\n\nexport function createSharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tTGateways extends object,\n\tServices extends object,\n>(\n\tconfig: ILankaSharedStoreVMConfig<StoreState, Actions, Store, TGateways, Services>,\n): TLankaSharedStoreVMHook<StoreState, Actions>;\n\nexport function createSharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n>(config: ILankaSharedStoreVMConfig<StoreState, Actions, Store, TGateways, Services>) {\n\tlankaLogger.printViewModelLog(\"START Create ssVM\", config.name);\n\n\ttype TFullState = StoreState & Actions & ILankaScenarioVM;\n\n\t/**\n\t * Unsubscribe functions, plus the event types already subscribed to.\n\t *\n\t * Two separate jobs, kept separate: the array releases subscriptions, the set\n\t * prevents subscribing to one event type twice.\n\t */\n\tlet actions = {} as Actions;\n\n\tconst gateways = resolveLankaDependency(config.gateways);\n\tconst services = resolveLankaDependency(config.services);\n\n\tlet lastStoreStateRef: StoreState | null = null;\n\tlet lastFullStateRef: TFullState | null = null;\n\n\tconst buildFullState = (storeState: StoreState): TFullState => {\n\t\tif (lastStoreStateRef === storeState && lastFullStateRef) {\n\t\t\treturn lastFullStateRef;\n\t\t}\n\n\t\tlastStoreStateRef = storeState;\n\t\tlastFullStateRef = {\n\t\t\t...storeState,\n\t\t\t...actions,\n\t\t\tinitializeScenario,\n\t\t\tresetScenario,\n\t\t};\n\n\t\treturn lastFullStateRef;\n\t};\n\n\tconst getFullState = (): TFullState => buildFullState(config.store.getState());\n\n\tconst ctx: ILankaSharedStoreVMContext<StoreState, TFullState, Store, TGateways, Services> = {\n\t\tset: (partial, replace) => config.store.setState(partial, replace),\n\t\tgetStore: () => config.store.getState(),\n\t\tget: () => getFullState(),\n\t\tstore: config.store,\n\t\tgateways,\n\t\tservices,\n\t\ttrigger: (scenario, data) => scenario.trigger(data),\n\t};\n\n\tconst { initializeScenario, resetScenario } = createLankaScenarioBinder({\n\t\tname: config.name,\n\t\tbindings: config.scenarioHandlers,\n\t\tcontext: () => ctx,\n\t\tonInit: config.onInit,\n\t\tonReset: config.onReset,\n\t});\n\n\tactions = config.createActions(ctx);\n\tlastStoreStateRef = null;\n\tlastFullStateRef = null;\n\tconst isAccessTrackingEnabled = config.enableAccessTrackingOptimization ?? true;\n\n\tconst useTrackedSharedStoreViewModel = createLankaTrackedHook<TFullState>({\n\t\tsubscribe: (onChange) =>\n\t\t\tconfig.store.subscribe((storeState, prevStoreState) => {\n\t\t\t\tonChange(buildFullState(storeState), buildFullState(prevStoreState));\n\t\t\t}),\n\t\treadState: getFullState,\n\t}) as TLankaSharedStoreVMHook<StoreState, Actions>;\n\n\tconst useUntrackedSharedStoreViewModel = ((selector?: (state: TFullState) => unknown) =>\n\t\tuseStore(config.store.getApi(), (storeState) => {\n\t\t\tconst fullState = buildFullState(storeState);\n\n\t\t\tif (selector) {\n\t\t\t\treturn selector(fullState);\n\t\t\t}\n\n\t\t\treturn fullState;\n\t\t})) as TLankaSharedStoreVMHook<StoreState, Actions>;\n\n\tconst useSharedStoreViewModel = isAccessTrackingEnabled\n\t\t? useTrackedSharedStoreViewModel\n\t\t: useUntrackedSharedStoreViewModel;\n\n\tuseSharedStoreViewModel.getState = () => getFullState();\n\tuseSharedStoreViewModel.getStoreState = () => config.store.getState();\n\n\tif (config.scenarioHandlers && config.scenarioHandlers.length > 0) {\n\t\tconst scenarioViewModel: ILankaScenarioVM = {\n\t\t\tinitializeScenario,\n\t\t\tresetScenario,\n\t\t};\n\t\tlankaScenarioBootstrap.registerViewModel(scenarioViewModel, config.name);\n\t}\n\n\tlankaLogger.printViewModelLog(\"FINISH Create ssVM\", config.name);\n\n\treturn useSharedStoreViewModel;\n}\n","import { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\nimport { ALankaSharedStore } from \"../../_abstractions/lanka-shared-store/ALankaSharedStore\";\nimport { createLazyLankaHook } from \"../../_internal/create-lazy-lanka-hook/createLazyLankaHook\";\nimport { createSharedStoreLankaVM } from \"../create-shared-store-lanka-vm/createSharedStoreLankaVM\";\nimport type { ILankaSharedStoreVMConfig } from \"../../_interfaces/ILankaSharedStoreVMConfig\";\n\n/**\n * What a lazy shared-store ViewModel is, in the type as well as at runtime.\n *\n * The overloads used to promise the eager factory's return and nothing else, so\n * `dispose` and `getStoreState` existed on the object and not in the type: a\n * consumer releasing a closed screen's ViewModel got a compile error for calling\n * something that was there.\n */\ntype TLazySharedStoreReturn<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tTGateways extends object,\n\tServices extends object,\n> = ReturnType<typeof createSharedStoreLankaVM<StoreState, Actions, Store, TGateways, Services>> & {\n\tgetState: () => StoreState & Actions & ILankaScenarioVM;\n\tgetStoreState: () => StoreState;\n\tdispose: () => void;\n};\n\nexport function createLazySharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n>(\n\tconfig: ILankaSharedStoreVMConfig<\n\t\tStoreState,\n\t\tActions,\n\t\tStore,\n\t\tRecord<string, never>,\n\t\tRecord<string, never>\n\t>,\n): TLazySharedStoreReturn<StoreState, Actions, Store, Record<string, never>, Record<string, never>>;\n\nexport function createLazySharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tTGateways extends object,\n>(\n\tconfig: ILankaSharedStoreVMConfig<StoreState, Actions, Store, TGateways, Record<string, never>>,\n): TLazySharedStoreReturn<StoreState, Actions, Store, TGateways, Record<string, never>>;\n\nexport function createLazySharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tTGateways extends object,\n\tServices extends object,\n>(\n\tconfig: ILankaSharedStoreVMConfig<StoreState, Actions, Store, TGateways, Services>,\n): TLazySharedStoreReturn<StoreState, Actions, Store, TGateways, Services>;\n\n/**\n * The lazy `createSharedStoreLankaVM`: nothing is built until a screen asks.\n *\n * The mechanism is `createLazyLankaHook`; this file is the one line that says\n * which ViewModel gets built. `dispose` releases THIS ViewModel's scenario\n * subscriptions and never the shared store — the store is shared, other\n * ViewModels stand on it, and taking its state away is not this one's decision.\n * That is the hook's behaviour, not a special case here: it resets the scenario\n * and drops its reference, and a shared store outlives both.\n */\nexport function createLazySharedStoreLankaVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n>(config: ILankaSharedStoreVMConfig<StoreState, Actions, Store, TGateways, Services>) {\n\treturn createLazyLankaHook({\n\t\tname: config.name,\n\t\tkind: \"ssVM\",\n\t\tcreate: () => createSharedStoreLankaVM(config),\n\t});\n}\n","import { ALankaVMEnvironment } from \"../lanka-vm-environment/ALankaVMEnvironment\";\nimport { createSharedStoreLankaVM } from \"../../_factories/create-shared-store-lanka-vm/createSharedStoreLankaVM\";\nimport type { ALankaSharedStore } from \"../lanka-shared-store/ALankaSharedStore\";\nimport type { ILankaScenarioVM } from \"../../../scenario/_interfaces/ILankaScenarioVM\";\nimport type { ILankaSharedStoreVMContext } from \"../../_interfaces/ILankaSharedStoreVMContext\";\nimport type {\n\tILankaSharedStoreScenarioBinding,\n\tTLankaSharedStoreVMHook,\n} from \"../../_interfaces/ILankaSharedStoreVMConfig\";\n\n/**\n * A ViewModel over a store several ViewModels share, written as a class.\n *\n * The third rung of the ladder in `core/README.md`: reach for it only when two\n * ViewModels must CO-EDIT one state — a list and the badge that counts it, a\n * form and the header that says it is dirty. What the class adds over the\n * stateful base is where the state lives: in the store it is given, so `set`\n * writes there and `getStore` reads it.\n *\n * ```ts\n * class BadgeVM extends ALankaSharedStoreVM<ISelection, IBadgeActions, TodoStore> {\n * \tprotected readonly name = \"BadgeVM\";\n *\n * \tpublic constructor(store: TodoStore) {\n * \t\tsuper(store);\n * \t}\n *\n * \tprotected createActions(): IBadgeActions {\n * \t\treturn { clear: () => this.set({ selectedId: null }) };\n * \t}\n * }\n * ```\n *\n * Unlike its two siblings this one is a thin adapter rather than the\n * implementation: the store, the tracked hook and the two memoised state\n * references are the factory's, and duplicating them here would be the second\n * implementation the parity canon exists to prevent. What it gives a class-style\n * consumer is the same protected surface under the same names.\n *\n * Canon: `skills/parity/SKILL.md`.\n */\nexport abstract class ALankaSharedStoreVM<\n\tStoreState extends object,\n\tActions extends object,\n\tStore extends ALankaSharedStore<StoreState>,\n\tTGateways extends object = Record<string, never>,\n\tServices extends object = Record<string, never>,\n> extends ALankaVMEnvironment<TGateways, Services> {\n\t/** Names the ViewModel in the logs and in the scenario registry. */\n\tprotected abstract readonly name: string;\n\n\t/** The store this ViewModel and its siblings share. */\n\tprotected readonly store: Store;\n\n\t/** Writes into the shared store, which every reader of it hears about. */\n\tprotected set!: ILankaSharedStoreVMContext<\n\t\tStoreState,\n\t\tStoreState & Actions & ILankaScenarioVM,\n\t\tStore,\n\t\tTGateways,\n\t\tServices\n\t>[\"set\"];\n\n\t/** Reads the store's own state, without this ViewModel's actions on top. */\n\tprotected getStore!: () => StoreState;\n\n\t/** Reads the store's state WITH the actions, which is what a screen sees. */\n\tprotected get!: () => StoreState & Actions & ILankaScenarioVM;\n\n\t/** Fires a scenario, which every ViewModel bound to it then hears. */\n\tprotected trigger!: ILankaSharedStoreVMContext<\n\t\tStoreState,\n\t\tStoreState & Actions & ILankaScenarioVM,\n\t\tStore,\n\t\tTGateways,\n\t\tServices\n\t>[\"trigger\"];\n\n\tpublic constructor(store: Store) {\n\t\tsuper();\n\t\tthis.store = store;\n\t}\n\n\t/**\n\t * Turn off when one broad consumer reads most fields of the store — proxy\n\t * tracking then costs more than it saves.\n\t */\n\tprotected readonly enableAccessTrackingOptimization: boolean = true;\n\n\t/** The scenarios this ViewModel listens to, unsubscribed for it on reset. */\n\tprotected scenarioHandlers(): ILankaSharedStoreScenarioBinding<\n\t\tunknown,\n\t\tStoreState,\n\t\tActions,\n\t\tStore,\n\t\tTGateways,\n\t\tServices\n\t>[] {\n\t\treturn [];\n\t}\n\n\t/** The actions the screen calls. Written against `this.set` and `this.get`. */\n\tprotected abstract createActions(): Actions;\n\n\t/** Builds the hook a screen calls. One ViewModel per call. */\n\tpublic build(): TLankaSharedStoreVMHook<StoreState, Actions> {\n\t\treturn createSharedStoreLankaVM<StoreState, Actions, Store, TGateways, Services>({\n\t\t\tname: this.name,\n\t\t\tstore: this.store,\n\t\t\tenableAccessTrackingOptimization: this.enableAccessTrackingOptimization,\n\t\t\tgateways: () => this.createGateways(),\n\t\t\tservices: () => this.createServices(),\n\t\t\tscenarioHandlers: this.scenarioHandlers(),\n\t\t\tcreateActions: (context) => {\n\t\t\t\t// The context arrives here and becomes the protected surface, under the\n\t\t\t\t// same names it carries: a consumer who switches styles moves the same\n\t\t\t\t// call from `set(...)` to `this.set(...)` and changes nothing else.\n\t\t\t\tthis.set = context.set;\n\t\t\t\tthis.getStore = context.getStore;\n\t\t\t\tthis.get = context.get;\n\t\t\t\tthis.gateways = context.gateways;\n\t\t\t\tthis.services = context.services;\n\t\t\t\tthis.trigger = context.trigger;\n\n\t\t\t\treturn this.createActions();\n\t\t\t},\n\t\t\tonInit: () => {\n\t\t\t\tthis.onInit();\n\t\t\t},\n\t\t\tonReset: () => {\n\t\t\t\tthis.onReset();\n\t\t\t},\n\t\t});\n\t}\n}\n","import { createStore, StoreApi } from \"zustand/vanilla\";\n\n/**\n * Base abstraction for shared feature stores.\n *\n * A store built on this class is resolved through the shared-store locator and\n * reused across several ViewModels.\n */\nexport abstract class ALankaSharedStore<TState extends object> {\n\tprivate readonly api: StoreApi<TState>;\n\tprivate readonly createInitialState: () => TState;\n\n\tprotected constructor(createInitialState: () => TState) {\n\t\tthis.createInitialState = createInitialState;\n\t\tthis.api = createStore<TState>()(() => this.createInitialState());\n\t}\n\n\tpublic getApi(): StoreApi<TState> {\n\t\treturn this.api;\n\t}\n\n\tpublic getState(): TState {\n\t\treturn this.api.getState();\n\t}\n\n\tpublic setState(\n\t\tpartial: TState | Partial<TState> | ((state: TState) => TState | Partial<TState>),\n\t\treplace?: boolean,\n\t): void {\n\t\tconst resolved = typeof partial === \"function\" ? partial(this.api.getState()) : partial;\n\n\t\tif (replace) {\n\t\t\tthis.api.setState(resolved as TState, true);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.api.setState(resolved);\n\t}\n\n\tpublic subscribe(listener: (state: TState, prevState: TState) => void) {\n\t\treturn this.api.subscribe(listener);\n\t}\n\n\t/**\n\t * Back to what the store was built with.\n\t *\n\t * Public, and it was not: while this was `protected` only a subclass could\n\t * reset, so the class style had a capability the functional one could not\n\t * reach — the asymmetry `skills/parity/SKILL.md` forbids. A shared store needs\n\t * explicit reset points (see the ladder in `core/README.md`), and the\n\t * application that owns them is outside the class either way.\n\t */\n\tpublic reset(): void {\n\t\tthis.api.setState(this.createInitialState(), true);\n\t}\n}\n","import { ALankaSharedStore } from \"../../_abstractions/lanka-shared-store/ALankaSharedStore\";\n\n/**\n * A shared store, without writing a class whose body is one function.\n *\n * A shared store is the third rung of the ladder in `core/README.md`: reach for\n * it only when several ViewModels must CO-EDIT one state. Most stores have no\n * behaviour of their own — the state and how to build it fresh is the whole\n * declaration — and this is the shape for those.\n *\n * One implementation: what comes back is an `ALankaSharedStore`, so a reset, a\n * subscription and the zustand api behave identically either way.\n */\nexport const createLankaSharedStore = <TState extends object>(\n\tcreateInitialState: () => TState,\n): ALankaSharedStore<TState> => {\n\tclass FunctionalSharedStore extends ALankaSharedStore<TState> {\n\t\tpublic constructor() {\n\t\t\tsuper(createInitialState);\n\t\t}\n\t}\n\n\treturn new FunctionalSharedStore();\n};\n"],"mappings":";;;;;;;;;;;;;;AAeO,IAAe,sBAAf,MAGL;AAAA;AAAA,EAES;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,iBAA4B;AACrC,WAAO,CAAC;AAAA,EACT;AAAA;AAAA,EAGU,iBAA2B;AACpC,WAAO,CAAC;AAAA,EACT;AAAA;AAAA,EAGU,SAAe;AAAA,EAAC;AAAA;AAAA,EAGhB,UAAgB;AAAA,EAAC;AAC5B;;;ACvCA,SAAS,cAAuC;;;AC2BzC,IAAM,2BAA2B,CACvC,eACA,YACyB;AACzB,MAAI,CAAC,SAAS;AACb,WAAO;AAAA,MACN,SAAS;AAAA,MACT,YAAY,CAAC,QAAQ;AAAA,MACrB,gBAAgB,CAAC,aAAa;AAAA,MAC9B,QAAQ,MAAM;AAAA,IACf;AAAA,EACD;AAGA,QAAM,gBAAgB,oBAAI,IAAyB;AAEnD,QAAM,aAAa,oBAAI,IAAY;AACnC,MAAI,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module",
|
|
5
|
+
"description": "core: Ten subsystems, two peer dependencies, five extension points.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/lankajs/lanka.git",
|
|
10
|
+
"directory": "core"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/lankajs/lanka/tree/main/core#readme",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./bootstrap": {
|
|
21
|
+
"types": "./dist/bootstrap/index.d.ts",
|
|
22
|
+
"default": "./dist/bootstrap/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./role": {
|
|
25
|
+
"types": "./dist/role/index.d.ts",
|
|
26
|
+
"default": "./dist/role/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./config": {
|
|
29
|
+
"types": "./dist/config/index.d.ts",
|
|
30
|
+
"default": "./dist/config/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./locator": {
|
|
33
|
+
"types": "./dist/locator/index.d.ts",
|
|
34
|
+
"default": "./dist/locator/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./gateway": {
|
|
37
|
+
"types": "./dist/gateway/index.d.ts",
|
|
38
|
+
"default": "./dist/gateway/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./validation": {
|
|
41
|
+
"types": "./dist/validation/index.d.ts",
|
|
42
|
+
"default": "./dist/validation/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./mock": {
|
|
45
|
+
"types": "./dist/mock/index.d.ts",
|
|
46
|
+
"default": "./dist/mock/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./errors": {
|
|
49
|
+
"types": "./dist/errors/index.d.ts",
|
|
50
|
+
"default": "./dist/errors/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./scenario": {
|
|
53
|
+
"types": "./dist/scenario/index.d.ts",
|
|
54
|
+
"default": "./dist/scenario/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./viewmodel": {
|
|
57
|
+
"types": "./dist/viewmodel/index.d.ts",
|
|
58
|
+
"default": "./dist/viewmodel/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./logger": {
|
|
61
|
+
"types": "./dist/logger/index.d.ts",
|
|
62
|
+
"default": "./dist/logger/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./extend": {
|
|
65
|
+
"types": "./dist/_extend/index.d.ts",
|
|
66
|
+
"default": "./dist/_extend/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./internal": {
|
|
69
|
+
"types": "./dist/_internal/index.d.ts",
|
|
70
|
+
"default": "./dist/_internal/index.js"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"sideEffects": false,
|
|
74
|
+
"files": [
|
|
75
|
+
"dist",
|
|
76
|
+
"LICENSE",
|
|
77
|
+
"README.md",
|
|
78
|
+
"skills"
|
|
79
|
+
],
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"@standard-schema/spec": "^1.0.0"
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@lankajs/tool-testing": "^1.0.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": "^19.2.0",
|
|
88
|
+
"zustand": "^5.0.10"
|
|
89
|
+
},
|
|
90
|
+
"scripts": {
|
|
91
|
+
"build": "tsup",
|
|
92
|
+
"lint": "eslint src _playground --max-warnings=0",
|
|
93
|
+
"test": "vitest run",
|
|
94
|
+
"test:coverage": "vitest run --coverage",
|
|
95
|
+
"test:watch": "vitest",
|
|
96
|
+
"bench": "vitest bench --run",
|
|
97
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lanka-core
|
|
3
|
+
description: Write and review code built on the lanka framework — gateways, ViewModels, scenarios, shared stores, the locator, bootstrap and failure handling. Use when a file imports `lanka` or `lanka/*`, when adding a screen that needs data or state, or when diagnosing a lanka app that will not start, a scenario handler that never fires, or a screen that stopped re-rendering.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: lankajs
|
|
7
|
+
package: lanka
|
|
8
|
+
version: "1.0.0"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# lanka — core
|
|
12
|
+
|
|
13
|
+
Layered React application framework: **gateways → ViewModels → views**, scenarios
|
|
14
|
+
over an event bus, a locator for resolution. `reference.md` beside this file is
|
|
15
|
+
the full guide; read it when a detail here is not enough.
|
|
16
|
+
|
|
17
|
+
> [!NOTE]
|
|
18
|
+
> Only what the framework or a gate refuses is binding. Everything else here is a
|
|
19
|
+
> recommendation you can adapt.
|
|
20
|
+
|
|
21
|
+
## Start-up — one line
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const lanka = await startLanka({ apiBaseUrl: "https://api.example.com" });
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Creates, activates, installs plugins, awaits bootstrap. **Every field is
|
|
28
|
+
optional** — `await startLanka()` works. With no `apiBaseUrl` a gateway's paths
|
|
29
|
+
are used as written, which is what an app on its API's origin or one talking to
|
|
30
|
+
several APIs wants; the three failure messages get English defaults you replace
|
|
31
|
+
one at a time through `messages`. `plugins`, `services`, `flags` and a whole
|
|
32
|
+
`host` are fields on the same call.
|
|
33
|
+
|
|
34
|
+
Write the two calls out only when something must happen BETWEEN them:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const lanka = createLanka({ host, flags }); // already active from here
|
|
38
|
+
lanka.locators.singletons.register("SessionService", SessionService);
|
|
39
|
+
await lanka.bootstrap({ services }); // services, then the scenario layer
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Neither `lanka.activate()` nor `lankaScenarioBootstrap.bootstrap()` is something
|
|
43
|
+
an application calls: `createLanka` activates, `bootstrap` raises the scenario
|
|
44
|
+
layer. `activate()` is for choosing between two instances in one process.
|
|
45
|
+
|
|
46
|
+
What must be in order: **register a name before constructing whatever resolves
|
|
47
|
+
it**, and let ViewModels with `scenarioHandlers` exist before `bootstrap()` — it
|
|
48
|
+
binds what exists when it runs.
|
|
49
|
+
|
|
50
|
+
## The layers, and which way imports go
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
View → ViewModel → Gateway → Request / Transport
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Imports go one way.** A ViewModel may reach a gateway; a gateway does not know
|
|
57
|
+
ViewModels exist. Checked by `@lankajs/tool-eslint`, which names the file and the
|
|
58
|
+
line.
|
|
59
|
+
|
|
60
|
+
| Layer | May use | Must never |
|
|
61
|
+
| ------------------- | --------------------------------------------- | -------------------------------------------- |
|
|
62
|
+
| View | its ViewModel's hook | import a gateway; own loading or retry state |
|
|
63
|
+
| ViewModel | gateways, services, scenarios, a shared store | import another ViewModel |
|
|
64
|
+
| Gateway | its request, a validator, a mock handler | import another gateway; hold state |
|
|
65
|
+
| Request / Transport | `fetch`, or whatever the app supplies | know an endpoint or a domain type |
|
|
66
|
+
|
|
67
|
+
**Scenarios** and **the locator** sit across the layers: a scenario is how two
|
|
68
|
+
ViewModels reach each other without importing anything, the locator is how a
|
|
69
|
+
screen asks for a name instead of an object. The only inversion is `.lanka_di/`,
|
|
70
|
+
read by the framework and by nobody else.
|
|
71
|
+
|
|
72
|
+
### Where does a new file go?
|
|
73
|
+
|
|
74
|
+
| The work it does | Where it lives |
|
|
75
|
+
| ---------------------------------- | -------------- |
|
|
76
|
+
| talks to a server, storage, an SDK | a gateway |
|
|
77
|
+
| remembers or decides something | a ViewModel |
|
|
78
|
+
| draws the screen | a component |
|
|
79
|
+
| pure input → output, no memory | a plain helper |
|
|
80
|
+
| announces "something happened" | a scenario |
|
|
81
|
+
|
|
82
|
+
One file doing two of these is two files in a trench coat. Then pick the smallest
|
|
83
|
+
scope that fits today, and point downward — a screen may use a helper, a helper
|
|
84
|
+
may never use a screen.
|
|
85
|
+
|
|
86
|
+
## Which shape do I need?
|
|
87
|
+
|
|
88
|
+
| The need | The shape |
|
|
89
|
+
| ------------------------------------------ | ------------------------------------------------ |
|
|
90
|
+
| talk to a server | a gateway |
|
|
91
|
+
| a screen's state and actions | `createLankaVM` / `ALankaVM` |
|
|
92
|
+
| answer questions about someone else's data | `createStatelessLankaVM` — no store at all |
|
|
93
|
+
| two screens must not disagree | `ALankaSharedStore` + `createSharedStoreLankaVM` |
|
|
94
|
+
| a screen behind a route most never open | `createLazyLankaVM`, and call `dispose()` |
|
|
95
|
+
| one screen must react to another's change | a scenario — never an import between ViewModels |
|
|
96
|
+
| a service resolved by name | `ALankaSingleton` / `createLankaSingleton` |
|
|
97
|
+
|
|
98
|
+
Every role ships **both** a class and a factory over one implementation. Pick the
|
|
99
|
+
style the project already uses; do not mix them for one role.
|
|
100
|
+
|
|
101
|
+
## Gateway — endpoints and nothing else
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
export class TodoGateway extends ALankaGateway {
|
|
105
|
+
constructor() {
|
|
106
|
+
super({ basePath: "/todos" }); // JSON over fetch, unless you say otherwise
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
list(): Promise<ITodo[]> {
|
|
110
|
+
return this.request<ITodo[]>(this.endpoint());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
No state, no error handling, no decisions about what a failure means — those
|
|
116
|
+
belong to the ViewModel that calls it. A gateway **is** where a body stops being
|
|
117
|
+
`unknown`: validate here with `lankaStandardValidator.validate(schema, body, "todos.list")`,
|
|
118
|
+
never in the screen.
|
|
119
|
+
|
|
120
|
+
## ViewModel — state, actions, subscriptions
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
export const createTodosVM = (todoGateway: TodoGateway) =>
|
|
124
|
+
createLankaVM<ITodosState, ITodoActions, { todoGateway: TodoGateway }>({
|
|
125
|
+
name: "TodosVM",
|
|
126
|
+
states: { todos: [], isLoading: false },
|
|
127
|
+
gateways: () => ({ todoGateway }),
|
|
128
|
+
createActions: ({ set, get, gateways, trigger }) => ({
|
|
129
|
+
load: async () => {
|
|
130
|
+
set({ isLoading: true });
|
|
131
|
+
try {
|
|
132
|
+
set({ todos: await gateways.todoGateway.list() });
|
|
133
|
+
} finally {
|
|
134
|
+
set({ isLoading: false });
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
scenarioHandlers: [{ scenario: todoCompleted, handler: ({ set, get }) => (data) => { … } }],
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The class form has the same surface as protected members: `this.set`, `this.get`,
|
|
143
|
+
`this.gateways`, `this.services`, `this.trigger`.
|
|
144
|
+
|
|
145
|
+
Consuming it is a hook: `const { todos, load } = useTodosVM();`
|
|
146
|
+
|
|
147
|
+
## Scenario — a FACT, not a command
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
export const todoCompleted = createLankaScenario<{ id: number }>({
|
|
151
|
+
name: "TodoCompleted",
|
|
152
|
+
eventType: "todo:completed",
|
|
153
|
+
dataTypeName: "ITodoCompleted",
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Name it after what happened (`TodoCompleted`), not after what to do
|
|
158
|
+
(`CompleteTodo`) — that is what lets three screens react differently without
|
|
159
|
+
knowing about each other. Keep exactly one instance per scenario; a second one is
|
|
160
|
+
an event nobody listens to.
|
|
161
|
+
|
|
162
|
+
## "A must affect B" — pick the tool by one question
|
|
163
|
+
|
|
164
|
+
**Do A and B co-own a thing, or does A announce something to independent Bs?**
|
|
165
|
+
|
|
166
|
+
| The link | The tool |
|
|
167
|
+
| -------------------------------------------------------- | ------------------ |
|
|
168
|
+
| one screen owns the state, nothing else needs it | one ViewModel |
|
|
169
|
+
| A announces a fact; B, C, D each react their own way | a **scenario** |
|
|
170
|
+
| A and B edit the same in-flight thing before it is saved | a **shared store** |
|
|
171
|
+
|
|
172
|
+
Read in that order, stop at the first that fits. If the link is describable with
|
|
173
|
+
a past-tense verb, it is a scenario.
|
|
174
|
+
|
|
175
|
+
## Cases
|
|
176
|
+
|
|
177
|
+
**A screen that loads a list.** Gateway method → ViewModel action that sets the
|
|
178
|
+
flag, calls it, clears the flag in `finally` → component reads the hook and
|
|
179
|
+
renders loading / error / content. A `useState` for the rows beside the ViewModel
|
|
180
|
+
means the ViewModel should have held them.
|
|
181
|
+
|
|
182
|
+
**One screen changes something another must see.** The owner's action writes its
|
|
183
|
+
own state and then `trigger(fact, payload)`. Others subscribe through
|
|
184
|
+
`scenarioHandlers` and each decides what the fact means for itself. Trigger
|
|
185
|
+
_with_ the data when the server returned it — subscribers apply instead of
|
|
186
|
+
refetching.
|
|
187
|
+
|
|
188
|
+
**A two-step form, and the world afterwards.** Three tools at once: a **shared
|
|
189
|
+
store** for the draft the two steps co-edit, one **scenario** for "order placed"
|
|
190
|
+
that a header badge and a list on another screen both subscribe to, and the
|
|
191
|
+
orchestration — gateway, trigger, clear the store, navigate — in the ViewModel
|
|
192
|
+
rather than the button. If the next screen's ViewModel is **lazy** it is not
|
|
193
|
+
subscribed yet, so write what it needs before navigating.
|
|
194
|
+
|
|
195
|
+
**A screen behind a rarely-opened route.** `createLazyLankaVM`, and `dispose()`
|
|
196
|
+
when it goes, or its subscriptions outlive it.
|
|
197
|
+
|
|
198
|
+
**A service several screens need.** Register a name at start-up, reach it as
|
|
199
|
+
`lankaSingletons.sessionService`. A test then replaces the object behind the name
|
|
200
|
+
without touching a screen.
|
|
201
|
+
|
|
202
|
+
## Failure
|
|
203
|
+
|
|
204
|
+
`LankaError` carries a kind: `network` · `timeout` · `aborted` · `http` ·
|
|
205
|
+
`schema` · `domain`. Branch on it. `aborted` is shown to nobody — the user left.
|
|
206
|
+
|
|
207
|
+
Refuse locally with the same shape rather than a bare throw:
|
|
208
|
+
`Promise.reject(createLankaApiError(400, ["a search needs a term"]))`.
|
|
209
|
+
|
|
210
|
+
## Never do these
|
|
211
|
+
|
|
212
|
+
- **Never import one ViewModel from another.** Use a scenario; a shared store
|
|
213
|
+
only when several must co-edit one state.
|
|
214
|
+
- **Never call a gateway from a component.** The component then silently owns
|
|
215
|
+
loading, failure and cancellation, and owns none of them.
|
|
216
|
+
- **Never let one gateway call another.** Compose in the ViewModel, where the
|
|
217
|
+
order and the failure are visible.
|
|
218
|
+
- **Never construct a ViewModel before the framework exists.** It resolves
|
|
219
|
+
against no runtime; `startLanka` (or `createLanka`) comes first.
|
|
220
|
+
- **Never validate a response outside the gateway.**
|
|
221
|
+
- **Never `import` your own `.lanka_di` barrels.** They are the framework's one
|
|
222
|
+
reading side.
|
|
223
|
+
- **Never leave a lazy ViewModel undisposed.**
|
|
224
|
+
|
|
225
|
+
## Symptom → cause
|
|
226
|
+
|
|
227
|
+
| What you see | What it is |
|
|
228
|
+
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
|
|
229
|
+
| a scenario handler never fires | `lanka.bootstrap()` was never awaited, or the ViewModel was built after it |
|
|
230
|
+
| a locator name resolves to a refusal | registered after construction, or never registered |
|
|
231
|
+
| the screen freezes with no error | a key read through a getter, past the tracking proxy — set `enableAccessTrackingOptimization: false` on that ViewModel |
|
|
232
|
+
| "module not found" for `@lanka_di/…` | `@lankajs/tool-di` is not installed, or the alias is missing |
|
|
233
|
+
| a test sees another test's events | the instance was replaced without `dispose()` — use `resetLanka()` |
|
|
234
|
+
|
|
235
|
+
Do **not** fix the frozen screen by destructuring a value "for the side effect":
|
|
236
|
+
it reads as dead code and the next refactor deletes it.
|
|
237
|
+
|
|
238
|
+
## More
|
|
239
|
+
|
|
240
|
+
`reference.md` — the full guide: host contract, flags, transports, middleware,
|
|
241
|
+
scopes, mock mode, the logger, plugins, roles, and the complete import map.
|