lanka 1.1.1 → 1.2.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/dist/_extend/index.js +3 -3
- package/dist/bootstrap/index.js +3 -3
- package/dist/{chunk-GK3E4CVW.js → chunk-5MAQVBI2.js} +4 -4
- package/dist/{chunk-ECM2HZHS.js → chunk-G3I7QIZR.js} +8 -8
- package/dist/gateway/index.js +3 -3
- package/dist/index.js +3 -3
- package/dist/viewmodel/index.d.ts +50 -8
- package/dist/viewmodel/index.js +20 -6
- package/dist/viewmodel/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/lanka-core/SKILL.md +10 -1
- package/skills/lanka-core/reference.md +1 -1
- package/skills/lanka-packages/SKILL.md +1 -1
- /package/dist/{chunk-GK3E4CVW.js.map → chunk-5MAQVBI2.js.map} +0 -0
- /package/dist/{chunk-ECM2HZHS.js.map → chunk-G3I7QIZR.js.map} +0 -0
package/dist/_extend/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
LankaGatewayLocator,
|
|
3
3
|
LankaScenarioLocator,
|
|
4
4
|
createLankaScope
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-5MAQVBI2.js";
|
|
6
6
|
import {
|
|
7
7
|
LankaScenarioVMRegistry,
|
|
8
8
|
LankaScenariosRegistry
|
|
@@ -10,8 +10,6 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
composeLankaRequestMiddleware
|
|
12
12
|
} from "../chunk-YR4MZXMU.js";
|
|
13
|
-
import "../chunk-C2HP7CRD.js";
|
|
14
|
-
import "../chunk-D27MREPB.js";
|
|
15
13
|
import {
|
|
16
14
|
createLankaLocatorProxy
|
|
17
15
|
} from "../chunk-DTO27QFR.js";
|
|
@@ -20,6 +18,8 @@ import {
|
|
|
20
18
|
LankaSharedStoreLocator,
|
|
21
19
|
LankaSingletonLocator
|
|
22
20
|
} from "../chunk-UE2C76OR.js";
|
|
21
|
+
import "../chunk-C2HP7CRD.js";
|
|
22
|
+
import "../chunk-D27MREPB.js";
|
|
23
23
|
import "../chunk-BGVDPDX4.js";
|
|
24
24
|
export {
|
|
25
25
|
ALankaLocator,
|
package/dist/bootstrap/index.js
CHANGED
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
createLanka,
|
|
4
4
|
resetActiveLanka,
|
|
5
5
|
startLanka
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-G3I7QIZR.js";
|
|
7
|
+
import "../chunk-5MAQVBI2.js";
|
|
7
8
|
import "../chunk-UGXSGQPW.js";
|
|
8
|
-
import "../chunk-GK3E4CVW.js";
|
|
9
9
|
import "../chunk-O5ROO7QF.js";
|
|
10
10
|
import "../chunk-XESL274R.js";
|
|
11
11
|
import "../chunk-UJEC7H6K.js";
|
|
12
|
+
import "../chunk-UE2C76OR.js";
|
|
12
13
|
import "../chunk-C2HP7CRD.js";
|
|
13
14
|
import "../chunk-D27MREPB.js";
|
|
14
|
-
import "../chunk-UE2C76OR.js";
|
|
15
15
|
import "../chunk-BGVDPDX4.js";
|
|
16
16
|
export {
|
|
17
17
|
ALankaPlugin,
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
ALankaScenario,
|
|
3
3
|
LankaScenariosRegistry
|
|
4
4
|
} from "./chunk-O5ROO7QF.js";
|
|
5
|
-
import {
|
|
6
|
-
lankaLogger
|
|
7
|
-
} from "./chunk-C2HP7CRD.js";
|
|
8
5
|
import {
|
|
9
6
|
ALankaLocator,
|
|
10
7
|
caseConvert,
|
|
11
8
|
findExportedClass
|
|
12
9
|
} from "./chunk-UE2C76OR.js";
|
|
10
|
+
import {
|
|
11
|
+
lankaLogger
|
|
12
|
+
} from "./chunk-C2HP7CRD.js";
|
|
13
13
|
|
|
14
14
|
// src/locator/gateway/lanka-gateway-locator/LankaGatewayLocator.ts
|
|
15
15
|
import * as GatewaysModule from "@lanka_di/Gateways";
|
|
@@ -136,4 +136,4 @@ export {
|
|
|
136
136
|
LankaScenarioLocator,
|
|
137
137
|
createLankaScope
|
|
138
138
|
};
|
|
139
|
-
//# sourceMappingURL=chunk-
|
|
139
|
+
//# sourceMappingURL=chunk-5MAQVBI2.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
lankaScenarioBootstrap
|
|
3
|
-
} from "./chunk-UGXSGQPW.js";
|
|
4
1
|
import {
|
|
5
2
|
LankaGatewayLocator,
|
|
6
3
|
LankaScenarioLocator,
|
|
7
4
|
createLankaScope
|
|
8
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-5MAQVBI2.js";
|
|
6
|
+
import {
|
|
7
|
+
lankaScenarioBootstrap
|
|
8
|
+
} from "./chunk-UGXSGQPW.js";
|
|
9
9
|
import {
|
|
10
10
|
LankaScenarioVMRegistry,
|
|
11
11
|
LankaScenariosRegistry
|
|
@@ -16,13 +16,13 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
createInFlightCounter
|
|
18
18
|
} from "./chunk-UJEC7H6K.js";
|
|
19
|
-
import {
|
|
20
|
-
lankaLogger
|
|
21
|
-
} from "./chunk-C2HP7CRD.js";
|
|
22
19
|
import {
|
|
23
20
|
LankaSharedStoreLocator,
|
|
24
21
|
LankaSingletonLocator
|
|
25
22
|
} from "./chunk-UE2C76OR.js";
|
|
23
|
+
import {
|
|
24
|
+
lankaLogger
|
|
25
|
+
} from "./chunk-C2HP7CRD.js";
|
|
26
26
|
import {
|
|
27
27
|
getActiveRuntime,
|
|
28
28
|
setActiveRuntime
|
|
@@ -720,4 +720,4 @@ export {
|
|
|
720
720
|
resetActiveLanka,
|
|
721
721
|
ALankaPlugin
|
|
722
722
|
};
|
|
723
|
-
//# sourceMappingURL=chunk-
|
|
723
|
+
//# sourceMappingURL=chunk-G3I7QIZR.js.map
|
package/dist/gateway/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
lankaStandardValidator
|
|
3
|
-
} from "../chunk-GV5DUYST.js";
|
|
4
1
|
import {
|
|
5
2
|
composeLankaRequestMiddleware
|
|
6
3
|
} from "../chunk-YR4MZXMU.js";
|
|
4
|
+
import {
|
|
5
|
+
lankaStandardValidator
|
|
6
|
+
} from "../chunk-GV5DUYST.js";
|
|
7
7
|
import {
|
|
8
8
|
lankaHttpInFlight
|
|
9
9
|
} from "../chunk-UJEC7H6K.js";
|
package/dist/index.js
CHANGED
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
createLanka,
|
|
7
7
|
resetActiveLanka,
|
|
8
8
|
startLanka
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-G3I7QIZR.js";
|
|
10
|
+
import "./chunk-5MAQVBI2.js";
|
|
10
11
|
import "./chunk-UGXSGQPW.js";
|
|
11
|
-
import "./chunk-GK3E4CVW.js";
|
|
12
12
|
import "./chunk-O5ROO7QF.js";
|
|
13
13
|
import {
|
|
14
14
|
createLankaHost
|
|
@@ -20,13 +20,13 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
getLankaHost
|
|
22
22
|
} from "./chunk-RKYKK6MN.js";
|
|
23
|
+
import "./chunk-UE2C76OR.js";
|
|
23
24
|
import {
|
|
24
25
|
lankaLogger
|
|
25
26
|
} from "./chunk-C2HP7CRD.js";
|
|
26
27
|
import {
|
|
27
28
|
getLankaFlags
|
|
28
29
|
} from "./chunk-D27MREPB.js";
|
|
29
|
-
import "./chunk-UE2C76OR.js";
|
|
30
30
|
import "./chunk-BGVDPDX4.js";
|
|
31
31
|
export {
|
|
32
32
|
ALankaPlugin,
|
|
@@ -45,6 +45,30 @@ interface ILankaScenarioBinding<TData, TState extends object, TGateways extends
|
|
|
45
45
|
|
|
46
46
|
type TUnknownLankaScenarioBinding<TState extends object, TGateways extends object, TServices extends object> = ILankaScenarioBinding<unknown, TState & ILankaScenarioVM, TGateways, TServices>;
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Scenario bindings as a ViewModel declares them: the list, or a factory for it.
|
|
50
|
+
*
|
|
51
|
+
* The factory form exists for the same reason `TLankaDependencyBag` has one, and
|
|
52
|
+
* for a sharper case. A ViewModel declared at module level writes its bindings as
|
|
53
|
+
* an array literal, and each entry names its scenario — `lankaScenarios.<name>`,
|
|
54
|
+
* which is a LOCATOR read. Written directly, that read happens while the module
|
|
55
|
+
* is being evaluated, and a module body can run before `createLanka` has: then
|
|
56
|
+
* the locator refuses with "lanka used before an instance existed" and nothing
|
|
57
|
+
* renders.
|
|
58
|
+
*
|
|
59
|
+
* Import order is not a defence. It holds inside one chunk, and a bundler decides
|
|
60
|
+
* chunks — in ES modules the body of an imported chunk runs before the body of
|
|
61
|
+
* the chunk importing it, so an application that put its ViewModels in their own
|
|
62
|
+
* chunks evaluated them ahead of its own `createLanka` call. Measured in a real
|
|
63
|
+
* app: 44 application chunks were statically imported by the entry, and its whole
|
|
64
|
+
* browser-level suite died on the first of them.
|
|
65
|
+
*
|
|
66
|
+
* `gateways` and `services` already accept a factory for the identical reason.
|
|
67
|
+
* Bindings were the one field left out, and they are the field that reads the
|
|
68
|
+
* locator most.
|
|
69
|
+
*/
|
|
70
|
+
type TLankaScenarioBindingsDeclaration<TBinding> = readonly TBinding[] | (() => readonly TBinding[]);
|
|
71
|
+
|
|
48
72
|
type TLankaAnyMutators = any;
|
|
49
73
|
|
|
50
74
|
type TLankaVMEnhancer<TState> = (creator: StateCreator<TState, TLankaAnyMutators, TLankaAnyMutators>) => StateCreator<TState, TLankaAnyMutators, TLankaAnyMutators>;
|
|
@@ -59,7 +83,12 @@ interface ILankaVMConfig<State extends object, Actions extends object, TGateways
|
|
|
59
83
|
enableAccessTrackingOptimization?: boolean;
|
|
60
84
|
states?: State;
|
|
61
85
|
createActions: (ctx: ILankaVMContext<State & Actions & ILankaScenarioVM, TGateways, Services>) => Actions;
|
|
62
|
-
|
|
86
|
+
/**
|
|
87
|
+
* A FACTORY postpones building the list until bind time — see
|
|
88
|
+
* `TLankaScenarioBindingsDeclaration` for the module-scope locator read it
|
|
89
|
+
* exists to avoid.
|
|
90
|
+
*/
|
|
91
|
+
scenarioHandlers?: TLankaScenarioBindingsDeclaration<TUnknownLankaScenarioBinding<State & Actions, TGateways, Services>>;
|
|
63
92
|
/** Non-gateway services. */
|
|
64
93
|
services?: Services | (() => Services);
|
|
65
94
|
/** TGateways (data layer) separated from services. */
|
|
@@ -130,7 +159,8 @@ interface ILankaStatelessScenarioBinding<TData, TState extends object, TGateways
|
|
|
130
159
|
type TLankaStatelessVMConfig$1<Actions extends object, TGateways extends object = Record<string, never>, Services extends object = Record<string, never>> = {
|
|
131
160
|
name: string;
|
|
132
161
|
createActions: (ctx: ILankaStatelessVMContext<Actions & ILankaScenarioVM, TGateways, Services>) => Actions;
|
|
133
|
-
|
|
162
|
+
/** A FACTORY is read at bind time — see `TLankaScenarioBindingsDeclaration`. */
|
|
163
|
+
scenarioHandlers?: TLankaScenarioBindingsDeclaration<ILankaStatelessScenarioBinding<unknown, Actions & ILankaScenarioVM, TGateways, Services>>;
|
|
134
164
|
services?: Services | (() => Services);
|
|
135
165
|
gateways?: TGateways | (() => TGateways);
|
|
136
166
|
onInit?: (ctx: ILankaStatelessVMContext<Actions & ILankaScenarioVM, TGateways, Services>) => void;
|
|
@@ -193,7 +223,8 @@ interface ILankaSharedStoreVMConfig<TStoreState extends object, TActions extends
|
|
|
193
223
|
enableAccessTrackingOptimization?: boolean;
|
|
194
224
|
store: TStore;
|
|
195
225
|
createActions: (ctx: ILankaSharedStoreVMContext<TStoreState, TStoreState & TActions & ILankaScenarioVM, TStore, TGateways, TServices>) => TActions;
|
|
196
|
-
|
|
226
|
+
/** A FACTORY is read at bind time — see `TLankaScenarioBindingsDeclaration`. */
|
|
227
|
+
scenarioHandlers?: TLankaScenarioBindingsDeclaration<ILankaSharedStoreScenarioBinding<unknown, TStoreState, TActions, TStore, TGateways, TServices>>;
|
|
197
228
|
services?: TServices | (() => TServices);
|
|
198
229
|
gateways?: TGateways | (() => TGateways);
|
|
199
230
|
onInit?: (ctx: ILankaSharedStoreVMContext<TStoreState, TStoreState & TActions & ILankaScenarioVM, TStore, TGateways, TServices>) => void;
|
|
@@ -321,8 +352,14 @@ declare abstract class ALankaVM<State extends object, Actions extends object, TG
|
|
|
321
352
|
protected trigger: <TData>(scenario: ILankaScenario<TData>, data?: TData) => void;
|
|
322
353
|
/** The reactive fields the screen reads. */
|
|
323
354
|
protected states(): State;
|
|
324
|
-
/**
|
|
325
|
-
|
|
355
|
+
/**
|
|
356
|
+
* The scenarios this ViewModel listens to, unsubscribed for it on reset.
|
|
357
|
+
*
|
|
358
|
+
* Returning a FACTORY postpones building the list until bind time, which is
|
|
359
|
+
* what a ViewModel declared at module level needs when its entries name their
|
|
360
|
+
* scenarios through the locator. See `TLankaScenarioBindingsDeclaration`.
|
|
361
|
+
*/
|
|
362
|
+
protected scenarioHandlers(): TLankaScenarioBindingsDeclaration<TUnknownLankaScenarioBinding<State & Actions, TGateways, Services>>;
|
|
326
363
|
/** Store middleware — `persist`, `lankaDevtools` — the last one applied outermost. */
|
|
327
364
|
protected enhancers(): TLankaVMEnhancer<State & Actions & ILankaScenarioVM>[];
|
|
328
365
|
/** The actions the screen calls. Written against `this.set` and `this.get`. */
|
|
@@ -385,8 +422,13 @@ declare abstract class ALankaStatelessVM<Actions extends object, TGateways exten
|
|
|
385
422
|
protected get: () => Actions & ILankaScenarioVM;
|
|
386
423
|
/** Fires a scenario, which every ViewModel bound to it then hears. */
|
|
387
424
|
protected trigger: <TData>(scenario: ILankaScenario<TData>, data?: TData) => void;
|
|
388
|
-
/**
|
|
389
|
-
|
|
425
|
+
/**
|
|
426
|
+
* The scenarios this ViewModel listens to, unsubscribed for it on reset.
|
|
427
|
+
*
|
|
428
|
+
* Returning a FACTORY postpones building the list until bind time. See
|
|
429
|
+
* `TLankaScenarioBindingsDeclaration`.
|
|
430
|
+
*/
|
|
431
|
+
protected scenarioHandlers(): TLankaScenarioBindingsDeclaration<ILankaStatelessScenarioBinding<unknown, Actions & ILankaScenarioVM, TGateways, Services>>;
|
|
390
432
|
/** The actions the screen calls. Written against `this.set` and `this.get`. */
|
|
391
433
|
protected abstract createActions(): Actions;
|
|
392
434
|
/**
|
|
@@ -451,7 +493,7 @@ declare abstract class ALankaSharedStoreVM<StoreState extends object, Actions ex
|
|
|
451
493
|
*/
|
|
452
494
|
protected readonly enableAccessTrackingOptimization: boolean;
|
|
453
495
|
/** The scenarios this ViewModel listens to, unsubscribed for it on reset. */
|
|
454
|
-
protected scenarioHandlers(): ILankaSharedStoreScenarioBinding<unknown, StoreState, Actions, Store, TGateways, Services
|
|
496
|
+
protected scenarioHandlers(): TLankaScenarioBindingsDeclaration<ILankaSharedStoreScenarioBinding<unknown, StoreState, Actions, Store, TGateways, Services>>;
|
|
455
497
|
/** The actions the screen calls. Written against `this.set` and `this.get`. */
|
|
456
498
|
protected abstract createActions(): Actions;
|
|
457
499
|
/** Builds the hook a screen calls. One ViewModel per call. */
|
package/dist/viewmodel/index.js
CHANGED
|
@@ -105,6 +105,7 @@ var createLankaBlindSpotTrap = (viewModelName, isArmed) => {
|
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
// src/viewmodel/_internal/create-lanka-scenario-binder/createLankaScenarioBinder.ts
|
|
108
|
+
var readBindings = (declared) => typeof declared === "function" ? declared() : declared ?? [];
|
|
108
109
|
var createLankaScenarioBinder = (config) => {
|
|
109
110
|
const subscriptions = /* @__PURE__ */ new Map();
|
|
110
111
|
let isInitialized = false;
|
|
@@ -115,7 +116,7 @@ var createLankaScenarioBinder = (config) => {
|
|
|
115
116
|
initializeScenario() {
|
|
116
117
|
if (isInitialized) return;
|
|
117
118
|
const context = config.context();
|
|
118
|
-
for (const binding of config.bindings
|
|
119
|
+
for (const binding of readBindings(config.bindings)) {
|
|
119
120
|
const key = binding.scenario.eventType;
|
|
120
121
|
if (subscriptions.has(key)) continue;
|
|
121
122
|
subscriptions.set(
|
|
@@ -221,7 +222,13 @@ var ALankaVM = class extends ALankaVMEnvironment {
|
|
|
221
222
|
states() {
|
|
222
223
|
return {};
|
|
223
224
|
}
|
|
224
|
-
/**
|
|
225
|
+
/**
|
|
226
|
+
* The scenarios this ViewModel listens to, unsubscribed for it on reset.
|
|
227
|
+
*
|
|
228
|
+
* Returning a FACTORY postpones building the list until bind time, which is
|
|
229
|
+
* what a ViewModel declared at module level needs when its entries name their
|
|
230
|
+
* scenarios through the locator. See `TLankaScenarioBindingsDeclaration`.
|
|
231
|
+
*/
|
|
225
232
|
scenarioHandlers() {
|
|
226
233
|
return [];
|
|
227
234
|
}
|
|
@@ -253,6 +260,7 @@ var ALankaVM = class extends ALankaVMEnvironment {
|
|
|
253
260
|
getLankaFlags().isDevelopment === true
|
|
254
261
|
);
|
|
255
262
|
const bindings = this.scenarioHandlers();
|
|
263
|
+
const hasBindings = typeof bindings === "function" || bindings.length > 0;
|
|
256
264
|
const stateCreator = (set, get) => {
|
|
257
265
|
this.set = set;
|
|
258
266
|
this.get = blindSpot.observeGet(get);
|
|
@@ -283,7 +291,7 @@ var ALankaVM = class extends ALankaVMEnvironment {
|
|
|
283
291
|
);
|
|
284
292
|
const store = create()(enhancedCreator);
|
|
285
293
|
const registerScenarioViewModel = (viewModel) => {
|
|
286
|
-
if (
|
|
294
|
+
if (hasBindings) {
|
|
287
295
|
lankaScenarioBootstrap.registerViewModel(viewModel, this.name);
|
|
288
296
|
}
|
|
289
297
|
};
|
|
@@ -417,7 +425,12 @@ var ALankaStatelessVM = class extends ALankaVMEnvironment {
|
|
|
417
425
|
trigger = (scenario, data) => {
|
|
418
426
|
scenario.trigger(data);
|
|
419
427
|
};
|
|
420
|
-
/**
|
|
428
|
+
/**
|
|
429
|
+
* The scenarios this ViewModel listens to, unsubscribed for it on reset.
|
|
430
|
+
*
|
|
431
|
+
* Returning a FACTORY postpones building the list until bind time. See
|
|
432
|
+
* `TLankaScenarioBindingsDeclaration`.
|
|
433
|
+
*/
|
|
421
434
|
scenarioHandlers() {
|
|
422
435
|
return [];
|
|
423
436
|
}
|
|
@@ -461,7 +474,7 @@ var ALankaStatelessVM = class extends ALankaVMEnvironment {
|
|
|
461
474
|
}
|
|
462
475
|
});
|
|
463
476
|
state = { ...state, ...actions, initializeScenario, resetScenario };
|
|
464
|
-
if (bindings.length > 0) {
|
|
477
|
+
if (typeof bindings === "function" || bindings.length > 0) {
|
|
465
478
|
lankaScenarioBootstrap.registerViewModel(state, this.name);
|
|
466
479
|
}
|
|
467
480
|
const useStatelessViewModel = ((selector) => selector ? selector(state) : state);
|
|
@@ -565,7 +578,8 @@ function createSharedStoreLankaVM(config) {
|
|
|
565
578
|
const useSharedStoreViewModel = isAccessTrackingEnabled ? useTrackedSharedStoreViewModel : useUntrackedSharedStoreViewModel;
|
|
566
579
|
useSharedStoreViewModel.getState = () => getFullState();
|
|
567
580
|
useSharedStoreViewModel.getStoreState = () => config.store.getState();
|
|
568
|
-
|
|
581
|
+
const declaredBindings = config.scenarioHandlers;
|
|
582
|
+
if (typeof declaredBindings === "function" || declaredBindings !== void 0 && declaredBindings.length > 0) {
|
|
569
583
|
const scenarioViewModel = {
|
|
570
584
|
initializeScenario,
|
|
571
585
|
resetScenario
|
|
@@ -1 +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 *\n * ## The thenable trap\n *\n * `then` is answered with `undefined`, never with a wrapper, and that line is\n * load-bearing. `await` and `Promise.resolve` decide whether a value is a\n * promise by READING `.then` and checking it is callable: a trap that returns a\n * function for every name says yes to that question for an object that is not a\n * promise. The runtime then calls it as `then(resolve, reject)`, the wrapper\n * forwards to a store member that does not exist, gets `undefined`, and neither\n * callback is ever invoked — so the `await` hangs FOREVER, with no error and no\n * stack.\n *\n * That makes `await someLazyVM` and every `async` function that RETURNS one a\n * silent deadlock, which is a shape a test harness reaches for constantly:\n * `const vm = await load()` resolves a promise with the proxy, and resolution\n * adopts a thenable. It cost an afternoon in a consumer's suite, where nineteen\n * tests timed out at 30s each and named their own first line.\n *\n * `catch` and `finally` are excluded with it. They are not part of the\n * thenable check, but an object answering `then` alone while a caller treats it\n * as a promise is the more confusing half of the same mistake — and no zustand\n * store has a member by either name.\n */\nconst PROMISE_MEMBERS: ReadonlySet<string | symbol> = new Set([\"then\", \"catch\", \"finally\"]);\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\t\tif (PROMISE_MEMBERS.has(property)) return undefined;\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,mBAAkC;AAEtC,SAAO;AAAA,IACN,SAAS;AAAA,IAET,WAAmB,KAAiC;AACnD,aAAO,MAAM;AACZ,cAAM,QAAQ,IAAI;AAClB,cAAM,aAAa;AACnB,YAAI,eAAe,KAAM,QAAO;AAEhC,eAAO,IAAI,MAAM,OAAiB;AAAA,UACjC,IAAI,QAAQ,MAAM,UAAU;AAC3B,gBAAI,OAAO,SAAS,UAAU;AAC7B,kBAAI,OAAO,cAAc,IAAI,UAAU;AACvC,kBAAI,CAAC,MAAM;AACV,uBAAO,oBAAI,IAAY;AACvB,8BAAc,IAAI,Y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AAA,EAC7C;AAAA,EACA;AAAA,EAEP,YAAY,oBAAkC;AACvD,SAAK,qBAAqB;AAC1B,SAAK,MAAM,YAAoB,EAAE,MAAM,KAAK,mBAAmB,CAAC;AAAA,EACjE;AAAA,EAEO,SAA2B;AACjC,WAAO,KAAK;AAAA,EACb;AAAA,EAEO,WAAmB;AACzB,WAAO,KAAK,IAAI,SAAS;AAAA,EAC1B;AAAA,EAEO,SACN,SACA,SACO;AACP,UAAM,WAAW,OAAO,YAAY,aAAa,QAAQ,KAAK,IAAI,SAAS,CAAC,IAAI;AAEhF,QAAI,SAAS;AACZ,WAAK,IAAI,SAAS,UAAoB,IAAI;AAC1C;AAAA,IACD;AAEA,SAAK,IAAI,SAAS,QAAQ;AAAA,EAC3B;AAAA,EAEO,UAAU,UAAsD;AACtE,WAAO,KAAK,IAAI,UAAU,QAAQ;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,QAAc;AACpB,SAAK,IAAI,SAAS,KAAK,mBAAmB,GAAG,IAAI;AAAA,EAClD;AACD;;;AC1CO,IAAM,yBAAyB,CACrC,uBAC+B;AAAA,EAC/B,MAAM,8BAA8B,kBAA0B;AAAA,IACtD,cAAc;AACpB,YAAM,kBAAkB;AAAA,IACzB;AAAA,EACD;AAEA,SAAO,IAAI,sBAAsB;AAClC;","names":[]}
|
|
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 { TLankaScenarioBindingsDeclaration } from \"../../_types/TLankaScenarioBindingsDeclaration\";\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/**\n\t * The scenarios this ViewModel listens to, unsubscribed for it on reset.\n\t *\n\t * Returning a FACTORY postpones building the list until bind time, which is\n\t * what a ViewModel declared at module level needs when its entries name their\n\t * scenarios through the locator. See `TLankaScenarioBindingsDeclaration`.\n\t */\n\tprotected scenarioHandlers(): TLankaScenarioBindingsDeclaration<\n\t\tTUnknownLankaScenarioBinding<State & Actions, TGateways, Services>\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\t//\n\t\t// A FACTORY is passed through unopened — the binder calls it at bind time,\n\t\t// which is the whole point of that form. Its presence is read as \"this\n\t\t// ViewModel has scenarios\": calling it here to count them would be exactly\n\t\t// the module-scope locator read it exists to postpone, and a factory\n\t\t// returning nothing costs one registration of a binder that binds nothing.\n\t\tconst bindings = this.scenarioHandlers();\n\t\tconst hasBindings = typeof bindings === \"function\" || bindings.length > 0;\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 (hasBindings) {\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","import type { TLankaScenarioBindingsDeclaration } from \"../../_types/TLankaScenarioBindingsDeclaration\";\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/**\n\t * What to bind. A ViewModel with none still gets a working binder.\n\t *\n\t * A factory is read at BIND time — like `context` below, and for the same\n\t * reason: an entry that names its scenario through the locator must not be\n\t * built while the declaring module is evaluated. See\n\t * `TLankaScenarioBindingsDeclaration`.\n\t */\n\tbindings?: TLankaScenarioBindingsDeclaration<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 bindings as declared, opened at the moment of binding.\n *\n * Its own function because WHEN this runs is the point: a factory form exists so\n * that the locator lookups inside the entries happen after the framework\n * instance does, and the only call site is inside `initializeScenario`.\n */\nconst readBindings = <TContext>(\n\tdeclared: TLankaScenarioBindingsDeclaration<ILankaScenarioBindingLike<TContext>> | undefined,\n): readonly ILankaScenarioBindingLike<TContext>[] =>\n\ttypeof declared === \"function\" ? declared() : (declared ?? []);\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 readBindings(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 *\n * ## The thenable trap\n *\n * `then` is answered with `undefined`, never with a wrapper, and that line is\n * load-bearing. `await` and `Promise.resolve` decide whether a value is a\n * promise by READING `.then` and checking it is callable: a trap that returns a\n * function for every name says yes to that question for an object that is not a\n * promise. The runtime then calls it as `then(resolve, reject)`, the wrapper\n * forwards to a store member that does not exist, gets `undefined`, and neither\n * callback is ever invoked — so the `await` hangs FOREVER, with no error and no\n * stack.\n *\n * That makes `await someLazyVM` and every `async` function that RETURNS one a\n * silent deadlock, which is a shape a test harness reaches for constantly:\n * `const vm = await load()` resolves a promise with the proxy, and resolution\n * adopts a thenable. It cost an afternoon in a consumer's suite, where nineteen\n * tests timed out at 30s each and named their own first line.\n *\n * `catch` and `finally` are excluded with it. They are not part of the\n * thenable check, but an object answering `then` alone while a caller treats it\n * as a promise is the more confusing half of the same mistake — and no zustand\n * store has a member by either name.\n */\nconst PROMISE_MEMBERS: ReadonlySet<string | symbol> = new Set([\"then\", \"catch\", \"finally\"]);\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\t\tif (PROMISE_MEMBERS.has(property)) return undefined;\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 { TLankaScenarioBindingsDeclaration } from \"../../_types/TLankaScenarioBindingsDeclaration\";\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/**\n\t * The scenarios this ViewModel listens to, unsubscribed for it on reset.\n\t *\n\t * Returning a FACTORY postpones building the list until bind time. See\n\t * `TLankaScenarioBindingsDeclaration`.\n\t */\n\tprotected scenarioHandlers(): TLankaScenarioBindingsDeclaration<\n\t\tILankaStatelessScenarioBinding<unknown, Actions & ILankaScenarioVM, TGateways, Services>\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 (typeof bindings === \"function\" || 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 type { TLankaScenarioBindingsDeclaration } from \"../../_types/TLankaScenarioBindingsDeclaration\";\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\t/** A FACTORY is read at bind time — see `TLankaScenarioBindingsDeclaration`. */\n\tscenarioHandlers?: TLankaScenarioBindingsDeclaration<\n\t\tILankaStatelessScenarioBinding<unknown, Actions & ILankaScenarioVM, TGateways, Services>\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\t// A FACTORY is passed to the binder unopened and counts as \"has scenarios\":\n\t// calling it here to measure its length is the module-scope locator read the\n\t// form exists to postpone. See `TLankaScenarioBindingsDeclaration`.\n\tconst declaredBindings = config.scenarioHandlers;\n\tif (\n\t\ttypeof declaredBindings === \"function\" ||\n\t\t(declaredBindings !== undefined && declaredBindings.length > 0)\n\t) {\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 { TLankaScenarioBindingsDeclaration } from \"../../_types/TLankaScenarioBindingsDeclaration\";\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(): TLankaScenarioBindingsDeclaration<\n\t\tILankaSharedStoreScenarioBinding<unknown, StoreState, Actions, Store, TGateways, Services>\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,mBAAkC;AAEtC,SAAO;AAAA,IACN,SAAS;AAAA,IAET,WAAmB,KAAiC;AACnD,aAAO,MAAM;AACZ,cAAM,QA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MAAM,8BAA8B,kBAA0B;AAAA,IACtD,cAAc;AACpB,YAAM,kBAAkB;AAAA,IACzB;AAAA,EACD;AAEA,SAAO,IAAI,sBAAsB;AAClC;","names":[]}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ license: MIT
|
|
|
5
5
|
metadata:
|
|
6
6
|
author: lankajs
|
|
7
7
|
package: lanka
|
|
8
|
-
version: "1.
|
|
8
|
+
version: "1.2.0"
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
# lanka — core
|
|
@@ -139,6 +139,14 @@ export const createTodosVM = (todoGateway: TodoGateway) =>
|
|
|
139
139
|
});
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
**Naming a scenario through the locator? Declare the handlers as a FACTORY.**
|
|
143
|
+
`scenarioHandlers: () => [{ scenario: lankaScenarios.todoCompleted, … }]` is read
|
|
144
|
+
at bind time. The array form is built where it is written, and for a ViewModel at
|
|
145
|
+
module level that is before `createLanka` can have run. Import order is not a
|
|
146
|
+
defence: it holds inside one chunk and a bundler decides chunks — the body of an
|
|
147
|
+
imported chunk runs before the body of the chunk importing it. `gateways` and
|
|
148
|
+
`services` accept a factory for the same reason.
|
|
149
|
+
|
|
142
150
|
The class form has the same surface as protected members: `this.set`, `this.get`,
|
|
143
151
|
`this.gateways`, `this.services`, `this.trigger`.
|
|
144
152
|
|
|
@@ -231,6 +239,7 @@ Refuse locally with the same shape rather than a bare throw:
|
|
|
231
239
|
| the screen freezes with no error | a key read through a getter, past the tracking proxy — set `enableAccessTrackingOptimization: false` on that ViewModel |
|
|
232
240
|
| "module not found" for `@lanka_di/…` | `@lankajs/tool-di` is not installed, or the alias is missing |
|
|
233
241
|
| a test sees another test's events | the instance was replaced without `dispose()` — use `resetLanka()` |
|
|
242
|
+
| "lanka used before an instance existed", only in a BUILT bundle | a ViewModel read the locator while its own module was evaluated, ahead of `createLanka` — declare `scenarioHandlers` as a factory (below) |
|
|
234
243
|
|
|
235
244
|
Do **not** fix the frozen screen by destructuring a value "for the side effect":
|
|
236
245
|
it reads as dead code and the next refactor deletes it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- Generated from core/GUIDE.md by scripts/skills.mjs. Edit the guide. -->
|
|
2
2
|
|
|
3
|
-
> **`lanka@1.
|
|
3
|
+
> **`lanka@1.2.0`** — this document describes that version.
|
|
4
4
|
>
|
|
5
5
|
> Install: `npm install lanka react zustand` (the peers are not optional; only npm adds a missing one for you).
|
|
6
6
|
>
|
|
File without changes
|
|
File without changes
|