@blac/core 2.0.20 → 2.0.22
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/README.md +19 -29
- package/dist/{StateContainerRegistry-CSNm2Ws5.cjs → StateContainerRegistry-141uHhtF.cjs} +300 -397
- package/dist/StateContainerRegistry-141uHhtF.cjs.map +1 -0
- package/dist/{StateContainerRegistry-DVIBTxGZ.js → StateContainerRegistry-BH7aOMWV.js} +299 -406
- package/dist/StateContainerRegistry-BH7aOMWV.js.map +1 -0
- package/dist/{StateContainerRegistry-Dj77cok9.js → StateContainerRegistry-BsH_s0pJ.js} +303 -413
- package/dist/StateContainerRegistry-BsH_s0pJ.js.map +1 -0
- package/dist/{StateContainerRegistry-lIwo-0m3.cjs → StateContainerRegistry-CBLeHObO.cjs} +326 -418
- package/dist/StateContainerRegistry-CBLeHObO.cjs.map +1 -0
- package/dist/{StateContainerRegistry-D9BIRjwv.cjs → StateContainerRegistry-MkT0W4C2.cjs} +322 -411
- package/dist/StateContainerRegistry-MkT0W4C2.cjs.map +1 -0
- package/dist/{StateContainerRegistry-CvBOhAT2.js → StateContainerRegistry-vWgsD-RP.js} +277 -392
- package/dist/StateContainerRegistry-vWgsD-RP.js.map +1 -0
- package/dist/config.d.cts +2 -2
- package/dist/config.d.ts +2 -2
- package/dist/constants.d.cts +4 -20
- package/dist/constants.d.ts +4 -20
- package/dist/core/Cubit.d.ts +14 -10
- package/dist/core/StateContainer.d.ts +68 -8
- package/dist/core/StateContainerRegistry.d.ts +100 -19
- package/dist/core/meta.d.ts +34 -47
- package/dist/core/symbols.d.ts +18 -1
- package/dist/decorators/blac.d.ts +28 -26
- package/dist/{ensure-BKdq5xsY.cjs → ensure-BjhbDW8Z.cjs} +223 -40
- package/dist/ensure-BjhbDW8Z.cjs.map +1 -0
- package/dist/ensure-BnVyd6s4.js +730 -0
- package/dist/ensure-BnVyd6s4.js.map +1 -0
- package/dist/ensure-CneMkpbI.js +731 -0
- package/dist/ensure-CneMkpbI.js.map +1 -0
- package/dist/{ensure-CQimeD0I.cjs → ensure-D15vGnk5.cjs} +348 -124
- package/dist/ensure-D15vGnk5.cjs.map +1 -0
- package/dist/{ensure-B1dEDsZV.cjs → ensure-D3w6YGp9.cjs} +349 -124
- package/dist/ensure-D3w6YGp9.cjs.map +1 -0
- package/dist/{ensure-B2DYCbbI.cjs → ensure-ORVw-WRE.cjs} +214 -39
- package/dist/ensure-ORVw-WRE.cjs.map +1 -0
- package/dist/{ensure-B59ri8oo.js → ensure-dsqWhIuO.js} +192 -39
- package/dist/ensure-dsqWhIuO.js.map +1 -0
- package/dist/{ensure-BSJHkUNX.js → ensure-k-6q7O25.js} +183 -38
- package/dist/ensure-k-6q7O25.js.map +1 -0
- package/dist/index.cjs +212 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -6
- package/dist/index.d.ts +4 -6
- package/dist/index.js +192 -12
- package/dist/index.js.map +1 -1
- package/dist/plugin/BlacPlugin.d.ts +14 -0
- package/dist/plugin/PluginManager.d.ts +21 -11
- package/dist/plugins.cjs +403 -3
- package/dist/plugins.cjs.map +1 -0
- package/dist/plugins.d.cts +6 -2
- package/dist/plugins.d.ts +6 -2
- package/dist/plugins.js +401 -1
- package/dist/plugins.js.map +1 -0
- package/dist/registry/acquire.d.ts +2 -2
- package/dist/registry/config.d.ts +9 -0
- package/dist/registry/management.d.ts +3 -0
- package/dist/registry/queries.d.ts +15 -0
- package/dist/registry/release.d.ts +3 -3
- package/dist/testing.cjs +13 -15
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +2 -4
- package/dist/testing.js.map +1 -1
- package/dist/types/branded.d.ts +3 -3
- package/dist/types/utilities.d.ts +45 -18
- package/dist/utils/static-props.d.ts +25 -1
- package/dist/utils/structural-key.d.ts +0 -7
- package/dist/watch/index.d.ts +1 -1
- package/dist/watch/watch.d.ts +22 -3
- package/package.json +16 -55
- package/dist/StateContainerRegistry-4Ljd9EJx.js +0 -1018
- package/dist/StateContainerRegistry-4Ljd9EJx.js.map +0 -1
- package/dist/StateContainerRegistry-8zNFMAf7.js +0 -1067
- package/dist/StateContainerRegistry-8zNFMAf7.js.map +0 -1
- package/dist/StateContainerRegistry-B1GYx9Xo.js +0 -975
- package/dist/StateContainerRegistry-B1GYx9Xo.js.map +0 -1
- package/dist/StateContainerRegistry-B_ViBLvJ.js +0 -975
- package/dist/StateContainerRegistry-B_ViBLvJ.js.map +0 -1
- package/dist/StateContainerRegistry-Bx2ly-ba.cjs +0 -1162
- package/dist/StateContainerRegistry-Bx2ly-ba.cjs.map +0 -1
- package/dist/StateContainerRegistry-C0dCNlTF.js +0 -1005
- package/dist/StateContainerRegistry-C0dCNlTF.js.map +0 -1
- package/dist/StateContainerRegistry-CEWpc1bj.cjs +0 -1113
- package/dist/StateContainerRegistry-CEWpc1bj.cjs.map +0 -1
- package/dist/StateContainerRegistry-CS18y4au.cjs +0 -1163
- package/dist/StateContainerRegistry-CS18y4au.cjs.map +0 -1
- package/dist/StateContainerRegistry-CSNm2Ws5.cjs.map +0 -1
- package/dist/StateContainerRegistry-CchRjnjX.cjs +0 -1094
- package/dist/StateContainerRegistry-CchRjnjX.cjs.map +0 -1
- package/dist/StateContainerRegistry-CvBOhAT2.js.map +0 -1
- package/dist/StateContainerRegistry-D8nu7Z0T.js +0 -1068
- package/dist/StateContainerRegistry-D8nu7Z0T.js.map +0 -1
- package/dist/StateContainerRegistry-D9BIRjwv.cjs.map +0 -1
- package/dist/StateContainerRegistry-DJQqLrli.cjs +0 -1046
- package/dist/StateContainerRegistry-DJQqLrli.cjs.map +0 -1
- package/dist/StateContainerRegistry-DVIBTxGZ.js.map +0 -1
- package/dist/StateContainerRegistry-Dj77cok9.js.map +0 -1
- package/dist/StateContainerRegistry-FWKzPfS-.cjs +0 -1046
- package/dist/StateContainerRegistry-FWKzPfS-.cjs.map +0 -1
- package/dist/StateContainerRegistry-lIwo-0m3.cjs.map +0 -1
- package/dist/acquire-B1LYXSGj.js +0 -35
- package/dist/acquire-B1LYXSGj.js.map +0 -1
- package/dist/acquire-B1Wuqla6.cjs +0 -46
- package/dist/acquire-B1Wuqla6.cjs.map +0 -1
- package/dist/acquire-BJ3xUEmh.cjs +0 -46
- package/dist/acquire-BJ3xUEmh.cjs.map +0 -1
- package/dist/acquire-BP-ZfUH2.js +0 -35
- package/dist/acquire-BP-ZfUH2.js.map +0 -1
- package/dist/acquire-BRIJVJaA.js +0 -35
- package/dist/acquire-BRIJVJaA.js.map +0 -1
- package/dist/acquire-BZIs6tpN.cjs +0 -46
- package/dist/acquire-BZIs6tpN.cjs.map +0 -1
- package/dist/acquire-B_p1fNEh.cjs +0 -46
- package/dist/acquire-B_p1fNEh.cjs.map +0 -1
- package/dist/acquire-BdsVZBSe.js +0 -35
- package/dist/acquire-BdsVZBSe.js.map +0 -1
- package/dist/acquire-C3nOb3XR.cjs +0 -46
- package/dist/acquire-C3nOb3XR.cjs.map +0 -1
- package/dist/acquire-C4WAS13G.cjs +0 -46
- package/dist/acquire-C4WAS13G.cjs.map +0 -1
- package/dist/acquire-C7beGI55.cjs +0 -46
- package/dist/acquire-C7beGI55.cjs.map +0 -1
- package/dist/acquire-CbMz7gWs.cjs +0 -46
- package/dist/acquire-CbMz7gWs.cjs.map +0 -1
- package/dist/acquire-CwB083au.js +0 -35
- package/dist/acquire-CwB083au.js.map +0 -1
- package/dist/acquire-DHEOEVcj.cjs +0 -46
- package/dist/acquire-DHEOEVcj.cjs.map +0 -1
- package/dist/acquire-DXEQDZGr.js +0 -35
- package/dist/acquire-DXEQDZGr.js.map +0 -1
- package/dist/acquire-Dg-uXwjF.js +0 -35
- package/dist/acquire-Dg-uXwjF.js.map +0 -1
- package/dist/acquire-Don7499S.js +0 -35
- package/dist/acquire-Don7499S.js.map +0 -1
- package/dist/acquire-G8aB3GAx.js +0 -35
- package/dist/acquire-G8aB3GAx.js.map +0 -1
- package/dist/branded-BybA0_xw.cjs +0 -18
- package/dist/branded-BybA0_xw.cjs.map +0 -1
- package/dist/branded-DkbUzncc.js +0 -13
- package/dist/branded-DkbUzncc.js.map +0 -1
- package/dist/config-8pyOC5gv.js +0 -16
- package/dist/config-8pyOC5gv.js.map +0 -1
- package/dist/config-B1l8ZGlU.cjs +0 -32
- package/dist/config-B1l8ZGlU.cjs.map +0 -1
- package/dist/config-C7Ktkjh2.cjs +0 -32
- package/dist/config-C7Ktkjh2.cjs.map +0 -1
- package/dist/config-COT4Xkbc.js +0 -16
- package/dist/config-COT4Xkbc.js.map +0 -1
- package/dist/config-CzcoAvBo.js +0 -16
- package/dist/config-CzcoAvBo.js.map +0 -1
- package/dist/config-D6BoWWPv.js +0 -16
- package/dist/config-D6BoWWPv.js.map +0 -1
- package/dist/config-DOO82lbZ.js +0 -16
- package/dist/config-DOO82lbZ.js.map +0 -1
- package/dist/config-DVM_ESQt.js +0 -16
- package/dist/config-DVM_ESQt.js.map +0 -1
- package/dist/config-DVMnlHLv.cjs +0 -32
- package/dist/config-DVMnlHLv.cjs.map +0 -1
- package/dist/config-DWUq7zEQ.cjs +0 -32
- package/dist/config-DWUq7zEQ.cjs.map +0 -1
- package/dist/config-DXI3kzmA.js +0 -16
- package/dist/config-DXI3kzmA.js.map +0 -1
- package/dist/config-Dk1FxfXj.js +0 -16
- package/dist/config-Dk1FxfXj.js.map +0 -1
- package/dist/config-b2z51Y_C.cjs +0 -32
- package/dist/config-b2z51Y_C.cjs.map +0 -1
- package/dist/config-buwpT7l3.js +0 -16
- package/dist/config-buwpT7l3.js.map +0 -1
- package/dist/config-cwaTn5oy.cjs +0 -32
- package/dist/config-cwaTn5oy.cjs.map +0 -1
- package/dist/config-d9_U58ef.cjs +0 -32
- package/dist/config-d9_U58ef.cjs.map +0 -1
- package/dist/config-hWTayX76.cjs +0 -32
- package/dist/config-hWTayX76.cjs.map +0 -1
- package/dist/config-sCPKPYxZ.cjs +0 -32
- package/dist/config-sCPKPYxZ.cjs.map +0 -1
- package/dist/debug.cjs +0 -14
- package/dist/debug.d.cts +0 -34
- package/dist/debug.d.ts +0 -34
- package/dist/debug.js +0 -4
- package/dist/ensure-B1dEDsZV.cjs.map +0 -1
- package/dist/ensure-B2DYCbbI.cjs.map +0 -1
- package/dist/ensure-B59ri8oo.js.map +0 -1
- package/dist/ensure-B9oOqpOB.cjs +0 -558
- package/dist/ensure-B9oOqpOB.cjs.map +0 -1
- package/dist/ensure-BKdq5xsY.cjs.map +0 -1
- package/dist/ensure-BSJHkUNX.js.map +0 -1
- package/dist/ensure-BfYnvAsI.js +0 -709
- package/dist/ensure-BfYnvAsI.js.map +0 -1
- package/dist/ensure-Bm91o37h.js +0 -536
- package/dist/ensure-Bm91o37h.js.map +0 -1
- package/dist/ensure-C1a8IFWy.js +0 -535
- package/dist/ensure-C1a8IFWy.js.map +0 -1
- package/dist/ensure-CLQEx0Nn.cjs +0 -528
- package/dist/ensure-CLQEx0Nn.cjs.map +0 -1
- package/dist/ensure-CPMiGvov.js +0 -493
- package/dist/ensure-CPMiGvov.js.map +0 -1
- package/dist/ensure-CQimeD0I.cjs.map +0 -1
- package/dist/ensure-DEXSmA-N.js +0 -526
- package/dist/ensure-DEXSmA-N.js.map +0 -1
- package/dist/ensure-DTTTd2h8.js +0 -536
- package/dist/ensure-DTTTd2h8.js.map +0 -1
- package/dist/ensure-Dx86f80B.cjs +0 -567
- package/dist/ensure-Dx86f80B.cjs.map +0 -1
- package/dist/ensure-DzqGej43.js +0 -526
- package/dist/ensure-DzqGej43.js.map +0 -1
- package/dist/ensure-VuiNPccZ.cjs +0 -559
- package/dist/ensure-VuiNPccZ.cjs.map +0 -1
- package/dist/ensure-_Oh8XPm4.cjs +0 -732
- package/dist/ensure-_Oh8XPm4.cjs.map +0 -1
- package/dist/ensure-fsQMjaQL.cjs +0 -567
- package/dist/ensure-fsQMjaQL.cjs.map +0 -1
- package/dist/ensure-vxAGa2v3.js +0 -536
- package/dist/ensure-vxAGa2v3.js.map +0 -1
- package/dist/management-14vsHr4t.cjs +0 -85
- package/dist/management-14vsHr4t.cjs.map +0 -1
- package/dist/management-444tdCBG.js +0 -38
- package/dist/management-444tdCBG.js.map +0 -1
- package/dist/management-7jLjVHJd.js +0 -38
- package/dist/management-7jLjVHJd.js.map +0 -1
- package/dist/management-AFuqQEwz.js +0 -38
- package/dist/management-AFuqQEwz.js.map +0 -1
- package/dist/management-BodVLAfJ.cjs +0 -85
- package/dist/management-BodVLAfJ.cjs.map +0 -1
- package/dist/management-BqGBdL01.js +0 -38
- package/dist/management-BqGBdL01.js.map +0 -1
- package/dist/management-BvUAjril.js +0 -38
- package/dist/management-BvUAjril.js.map +0 -1
- package/dist/management-C-WGcwPD.js +0 -38
- package/dist/management-C-WGcwPD.js.map +0 -1
- package/dist/management-C2wv4vGS.cjs +0 -85
- package/dist/management-C2wv4vGS.cjs.map +0 -1
- package/dist/management-D2pjr38g.js +0 -38
- package/dist/management-D2pjr38g.js.map +0 -1
- package/dist/management-D5WsZoTV.js +0 -38
- package/dist/management-D5WsZoTV.js.map +0 -1
- package/dist/management-DAV9sN-k.cjs +0 -85
- package/dist/management-DAV9sN-k.cjs.map +0 -1
- package/dist/management-Df7Y2sF1.cjs +0 -85
- package/dist/management-Df7Y2sF1.cjs.map +0 -1
- package/dist/management-DwO0nBzL.cjs +0 -85
- package/dist/management-DwO0nBzL.cjs.map +0 -1
- package/dist/management-GcnNJjnm.cjs +0 -85
- package/dist/management-GcnNJjnm.cjs.map +0 -1
- package/dist/management-P_Vi_cvw.js +0 -38
- package/dist/management-P_Vi_cvw.js.map +0 -1
- package/dist/management-QWLpbXlW.cjs +0 -85
- package/dist/management-QWLpbXlW.cjs.map +0 -1
- package/dist/management-iE4x6IQY.cjs +0 -85
- package/dist/management-iE4x6IQY.cjs.map +0 -1
- package/dist/types.cjs +0 -3
- package/dist/types.d.cts +0 -8
- package/dist/types.d.ts +0 -8
- package/dist/types.js +0 -2
- package/dist/watch-B0pUfh-v.cjs +0 -119
- package/dist/watch-B0pUfh-v.cjs.map +0 -1
- package/dist/watch-B91opmva.cjs +0 -70
- package/dist/watch-B91opmva.cjs.map +0 -1
- package/dist/watch-BHfCtbn1.cjs +0 -119
- package/dist/watch-BHfCtbn1.cjs.map +0 -1
- package/dist/watch-BmC-Tyqg.js +0 -59
- package/dist/watch-BmC-Tyqg.js.map +0 -1
- package/dist/watch-Bx0y-Kcc.js +0 -108
- package/dist/watch-Bx0y-Kcc.js.map +0 -1
- package/dist/watch-CKWt788i.cjs +0 -70
- package/dist/watch-CKWt788i.cjs.map +0 -1
- package/dist/watch-CfrSSrRY.js +0 -59
- package/dist/watch-CfrSSrRY.js.map +0 -1
- package/dist/watch-Cnh3PtQA.cjs +0 -70
- package/dist/watch-Cnh3PtQA.cjs.map +0 -1
- package/dist/watch-D01MdwKy.js +0 -108
- package/dist/watch-D01MdwKy.js.map +0 -1
- package/dist/watch-D8hwbFU1.js +0 -59
- package/dist/watch-D8hwbFU1.js.map +0 -1
- package/dist/watch-DPVUwPUY.js +0 -59
- package/dist/watch-DPVUwPUY.js.map +0 -1
- package/dist/watch-DVmvZBMD.cjs +0 -70
- package/dist/watch-DVmvZBMD.cjs.map +0 -1
- package/dist/watch-DkDGmGAx.cjs +0 -119
- package/dist/watch-DkDGmGAx.cjs.map +0 -1
- package/dist/watch-DttHqefn.js +0 -108
- package/dist/watch-DttHqefn.js.map +0 -1
- package/dist/watch-DxdIZjpt.cjs +0 -119
- package/dist/watch-DxdIZjpt.cjs.map +0 -1
- package/dist/watch-DztcJuUy.cjs +0 -119
- package/dist/watch-DztcJuUy.cjs.map +0 -1
- package/dist/watch-IrR8G28N.js +0 -108
- package/dist/watch-IrR8G28N.js.map +0 -1
- package/dist/watch-entry.cjs +0 -4
- package/dist/watch-entry.d.cts +0 -24
- package/dist/watch-entry.d.ts +0 -24
- package/dist/watch-entry.js +0 -2
- package/dist/watch-hx0r92Zc.js +0 -108
- package/dist/watch-hx0r92Zc.js.map +0 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { HydrationStatus, StateContainer } from './StateContainer';
|
|
2
|
-
import { type PluginManager } from '../plugin/PluginManager';
|
|
3
2
|
import { InstanceReadonlyState, StateContainerConstructor } from '../types/utilities';
|
|
4
3
|
/**
|
|
5
4
|
* Entry in the instance registry, tracking the instance and its named references
|
|
6
|
-
* @
|
|
5
|
+
* @typeParam T - Instance type
|
|
6
|
+
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export interface InstanceEntry<T = any> {
|
|
9
9
|
/** The state container instance */
|
|
10
10
|
instance: T;
|
|
11
|
+
/** The key this entry is stored under in its constructor's instances Map. */
|
|
12
|
+
key: string;
|
|
11
13
|
/** Map of active reference IDs to their acquire count (supports paired acquire/release) */
|
|
12
14
|
refs: Map<string, number>;
|
|
13
15
|
/** The args used when this entry was first created; used for dev-warn on arg mismatch. */
|
|
@@ -19,13 +21,15 @@ export interface InstanceEntry<T = any> {
|
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Lifecycle events emitted by the registry
|
|
24
|
+
* @public
|
|
22
25
|
*/
|
|
23
|
-
export type LifecycleEvent = 'created' | 'stateChanged' | 'disposed' | 'refAcquired' | 'refReleased' | 'depsChanged' | 'hydrationChanged';
|
|
26
|
+
export type LifecycleEvent = 'created' | 'stateChanged' | 'disposed' | 'refAcquired' | 'refReleased' | 'depsChanged' | 'hydrationChanged' | 'activated' | 'deactivated';
|
|
24
27
|
/**
|
|
25
28
|
* Listener function type for each lifecycle event
|
|
26
|
-
* @
|
|
29
|
+
* @typeParam E - The lifecycle event type
|
|
30
|
+
* @public
|
|
27
31
|
*/
|
|
28
|
-
export type LifecycleListener<E extends LifecycleEvent> = E extends 'created' ? (container: StateContainer<any, any, any>) => void : E extends 'stateChanged' ? (container: StateContainer<any, any, any>, previousState:
|
|
32
|
+
export type LifecycleListener<E extends LifecycleEvent> = E extends 'created' ? (container: StateContainer<any, any, any>) => void : E extends 'stateChanged' ? (container: StateContainer<any, any, any>, previousState: Readonly<Record<string, unknown>>, currentState: Readonly<Record<string, unknown>>) => void : E extends 'disposed' ? (container: StateContainer<any, any, any>) => void : E extends 'refAcquired' ? (container: StateContainer<any, any, any>, refId: string) => void : E extends 'refReleased' ? (container: StateContainer<any, any, any>, refId: string) => void : E extends 'depsChanged' ? (container: StateContainer<any, any, any>, previousDeps: Readonly<Record<string, unknown>>, currentDeps: Readonly<Record<string, unknown>>) => void : E extends 'hydrationChanged' ? (container: StateContainer<any, any, any>, status: HydrationStatus, previousStatus: HydrationStatus) => void : E extends 'activated' ? (container: StateContainer<any, any, any>, signal: AbortSignal) => void : E extends 'deactivated' ? (container: StateContainer<any, any, any>) => void : never;
|
|
29
33
|
/**
|
|
30
34
|
* Central registry for managing StateContainer instances.
|
|
31
35
|
* Handles instance lifecycle, named ref tracking, and lifecycle event emission.
|
|
@@ -39,13 +43,33 @@ export type LifecycleListener<E extends LifecycleEvent> = E extends 'created' ?
|
|
|
39
43
|
* console.log('State changed:', prev, '->', next);
|
|
40
44
|
* });
|
|
41
45
|
* ```
|
|
46
|
+
*
|
|
47
|
+
* `stateChanged` fires once per emit (microtask-deferred but uncoalesced), so
|
|
48
|
+
* listeners see every intermediate transition. Plugins' `onStateChange` fires
|
|
49
|
+
* once per channel flush with coalesced `prev`/`next` and a `PathSet`. Pick
|
|
50
|
+
* the transition log for devtools/time-travel, the plugin hook for
|
|
51
|
+
* change-driven work.
|
|
42
52
|
*/
|
|
43
53
|
export declare class StateContainerRegistry {
|
|
44
54
|
private readonly instancesByConstructor;
|
|
45
55
|
private readonly types;
|
|
46
|
-
|
|
56
|
+
/**
|
|
57
|
+
* `depend()`-owner to the (Type, key) entries it has resolved. Keyed per
|
|
58
|
+
* resolved key because one handle resolves a different key per `args`.
|
|
59
|
+
* Weak so a bare `new`'d owner that is never disposed cannot pin the map.
|
|
60
|
+
*/
|
|
61
|
+
private readonly _dependentEdges;
|
|
62
|
+
/**
|
|
63
|
+
* Reverse lookup from `$blac.id` to its entry, for `PluginContext.getRefIds`
|
|
64
|
+
* and the O(1) prune on dispose. Ids are `<name>:<key>`, so an entry is
|
|
65
|
+
* matched by instance identity as well.
|
|
66
|
+
*/
|
|
67
|
+
private readonly _entryById;
|
|
47
68
|
private readonly listeners;
|
|
48
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Derived from the listener Set, never a parallel counter: `on()` with the
|
|
71
|
+
* same function twice adds once, so a counter cannot stay in step.
|
|
72
|
+
*/
|
|
49
73
|
get hasStateChangedListeners(): boolean;
|
|
50
74
|
private _pendingStateChanges;
|
|
51
75
|
private _autoRefIdCounter;
|
|
@@ -57,6 +81,35 @@ export declare class StateContainerRegistry {
|
|
|
57
81
|
* release its dependent edges on whatever it `depend()`'d on.
|
|
58
82
|
*/
|
|
59
83
|
private _handleDisposed;
|
|
84
|
+
/**
|
|
85
|
+
* An entry may be disposed only when nothing owns it: no public refs, no
|
|
86
|
+
* `depend()` dependents, and not keepAlive. Every dispose decision goes
|
|
87
|
+
* through here so `release()` and `_releaseDependent` cannot disagree.
|
|
88
|
+
*/
|
|
89
|
+
private _isUnowned;
|
|
90
|
+
/**
|
|
91
|
+
* Pure ownership: refs plus `depend()` dependents, with no keepAlive term.
|
|
92
|
+
* `_isUnowned` is "may be disposed"; this is "nothing is using it", which is
|
|
93
|
+
* what the activation lifecycle keys off — a keepAlive instance still
|
|
94
|
+
* deactivates when its last owner goes.
|
|
95
|
+
*/
|
|
96
|
+
private _hasNoOwners;
|
|
97
|
+
/**
|
|
98
|
+
* Single funnel for the 0↔1 ownership transition. `SET_ACTIVE` is idempotent,
|
|
99
|
+
* so every acquire/release path can call this unconditionally rather than
|
|
100
|
+
* each computing the edge itself. Emits `activated`/`deactivated` for
|
|
101
|
+
* plugins to observe the same transition `onActivate`/`onDeactivate` expose
|
|
102
|
+
* to bloc authors — after `SET_ACTIVE` has already run the instance's own
|
|
103
|
+
* hook, so plugins always see a container that has finished reacting.
|
|
104
|
+
*/
|
|
105
|
+
private _syncActivation;
|
|
106
|
+
/**
|
|
107
|
+
* Record that `dependent` resolved `Type` at `key`, so the edge can be
|
|
108
|
+
* released on the owner's disposal. Keyed per resolved key, not per type:
|
|
109
|
+
* one `depend()` handle resolves a distinct key for every `args` it is
|
|
110
|
+
* called with, and all of them must be swept.
|
|
111
|
+
*/
|
|
112
|
+
private _recordDependentEdge;
|
|
60
113
|
/**
|
|
61
114
|
* Remove the Map entry for `container`, if this registry is tracking it.
|
|
62
115
|
* @returns true if an entry was found and removed
|
|
@@ -84,7 +137,7 @@ export declare class StateContainerRegistry {
|
|
|
84
137
|
/**
|
|
85
138
|
* Get the instances Map for a specific class (public API for stats/debugging)
|
|
86
139
|
*/
|
|
87
|
-
getInstancesMap<T extends StateContainerConstructor>(Type: T):
|
|
140
|
+
getInstancesMap<T extends StateContainerConstructor>(Type: T): ReadonlyMap<string, InstanceEntry>;
|
|
88
141
|
/**
|
|
89
142
|
* Directly insert an instance entry into the registry without going through
|
|
90
143
|
* acquire/release. Creates the internal WeakMap bucket for the constructor if
|
|
@@ -103,7 +156,7 @@ export declare class StateContainerRegistry {
|
|
|
103
156
|
* an args-derived key is never dropped (instance leaks).
|
|
104
157
|
*
|
|
105
158
|
* Resolution order (explicit beats derived):
|
|
106
|
-
* explicit key
|
|
159
|
+
* explicit key \> `static key(args)` \> structural hash of args \> default sentinel.
|
|
107
160
|
*
|
|
108
161
|
* @param Type - The StateContainer class constructor
|
|
109
162
|
* @param instanceKey - Explicit key, or undefined to derive from args
|
|
@@ -132,12 +185,13 @@ export declare class StateContainerRegistry {
|
|
|
132
185
|
* wrapper; `useBloc` and `watch` address a pre-resolved key here.
|
|
133
186
|
* @param Type - The StateContainer class constructor
|
|
134
187
|
* @param instanceKey - Pre-resolved instance key (defaults to 'default')
|
|
135
|
-
* @param options - Acquisition options
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
188
|
+
* @param options - Acquisition options: `canCreate` (create when absent,
|
|
189
|
+
* default true), `countRef` (add a reference, default true), `refId`
|
|
190
|
+
* (named reference for debugging, auto-generated when omitted),
|
|
191
|
+
* `dependent` — the `depend()`-owner resolving this instance, recorded so
|
|
192
|
+
* its dependent edge is released on the owner's disposal — and
|
|
193
|
+
* `sweepIfUnowned`, for callers that create speculatively and claim
|
|
194
|
+
* ownership later (see {@link _scheduleSweep}).
|
|
141
195
|
* @returns The state container instance
|
|
142
196
|
*/
|
|
143
197
|
acquire<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string, options?: {
|
|
@@ -146,7 +200,19 @@ export declare class StateContainerRegistry {
|
|
|
146
200
|
refId?: string;
|
|
147
201
|
args?: unknown;
|
|
148
202
|
dependent?: StateContainer<any, any, any>;
|
|
203
|
+
sweepIfUnowned?: boolean;
|
|
149
204
|
}): InstanceType<T>;
|
|
205
|
+
/**
|
|
206
|
+
* Speculative creates (`useBloc`'s render-time create) leak forever when the
|
|
207
|
+
* render is discarded or never commits — SSR has no commit at all, so nothing
|
|
208
|
+
* ever claims ownership. Sweep at the end of the microtask unless the entry
|
|
209
|
+
* gained an owner or is keepAlive.
|
|
210
|
+
*
|
|
211
|
+
* Opt-in, not automatic: a bare `ensure()` hands the instance to a caller
|
|
212
|
+
* that legitimately holds it without a ref, and sweeping those would make
|
|
213
|
+
* `ensure` unusable across an `await`.
|
|
214
|
+
*/
|
|
215
|
+
private _scheduleSweep;
|
|
150
216
|
/**
|
|
151
217
|
* Borrow an existing instance without adding a ref (borrowing semantics).
|
|
152
218
|
* Tracks cross-bloc dependency for reactive updates.
|
|
@@ -238,6 +304,13 @@ export declare class StateContainerRegistry {
|
|
|
238
304
|
* @returns Array of ref ID strings (empty if instance doesn't exist)
|
|
239
305
|
*/
|
|
240
306
|
getRefIds<T extends StateContainerConstructor>(Type: T, instanceKey?: string): string[];
|
|
307
|
+
/**
|
|
308
|
+
* Get all active reference IDs for an instance by its `$blac.id`, without
|
|
309
|
+
* needing the owning Type. Used by `PluginContext.getRefIds`.
|
|
310
|
+
* @param instanceId - The instance's `$blac.id`
|
|
311
|
+
* @returns Array of ref ID strings (empty if instance doesn't exist)
|
|
312
|
+
*/
|
|
313
|
+
getRefIdsById(instanceId: string): string[];
|
|
241
314
|
/**
|
|
242
315
|
* Check if an instance exists.
|
|
243
316
|
*
|
|
@@ -286,19 +359,27 @@ export declare class StateContainerRegistry {
|
|
|
286
359
|
emit(event: 'refReleased', container: StateContainer<any, any, any>, refId: string): void;
|
|
287
360
|
emit(event: 'depsChanged', container: StateContainer<any, any, any>, previousDeps: Readonly<Record<string, unknown>>, currentDeps: Readonly<Record<string, unknown>>): void;
|
|
288
361
|
emit(event: 'hydrationChanged', container: StateContainer<any, any, any>, status: HydrationStatus, previousStatus: HydrationStatus): void;
|
|
362
|
+
emit(event: 'activated', container: StateContainer<any, any, any>, signal: AbortSignal): void;
|
|
363
|
+
emit(event: 'deactivated', container: StateContainer<any, any, any>): void;
|
|
289
364
|
/**
|
|
290
365
|
* Schedule a deferred stateChanged notification via microtask.
|
|
291
366
|
* Skips entirely when no stateChanged listeners are registered.
|
|
292
367
|
* @internal - Called by StateContainer.applyState
|
|
293
368
|
*/
|
|
294
369
|
notifyStateChanged(container: StateContainer<any, any, any>, previousState: any, newState: any): void;
|
|
370
|
+
/**
|
|
371
|
+
* Deliver one event per emit, in order — deliberately NOT coalesced.
|
|
372
|
+
*
|
|
373
|
+
* This is a transition log: devtools, time-travel debugging and perf
|
|
374
|
+
* monitoring need every intermediate `prev`/`next`, which coalescing would
|
|
375
|
+
* destroy. The plugin `onStateChange` bridge is the coalesced, `PathSet`-
|
|
376
|
+
* carrying lane (see `PluginManager.setupLifecycleHooks`); the two differ on
|
|
377
|
+
* purpose, so a listener picks the lane that matches what it needs.
|
|
378
|
+
*/
|
|
295
379
|
private flushStateChanged;
|
|
296
380
|
}
|
|
297
381
|
/**
|
|
298
382
|
* Global default registry instance
|
|
383
|
+
* @public
|
|
299
384
|
*/
|
|
300
385
|
export declare const globalRegistry: StateContainerRegistry;
|
|
301
|
-
/**
|
|
302
|
-
* Get the global plugin manager
|
|
303
|
-
*/
|
|
304
|
-
export declare function getPluginManager(): PluginManager;
|
package/dist/core/meta.d.ts
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `$blac` meta namespace for `StateContainer`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
9
|
-
* through a proxy receiver throws (`#x` brand checks fail on the proxy). The
|
|
10
|
-
* whole point of this meta object is to be proxy-safe: every getter/method
|
|
11
|
-
* here closes over the *real* container instance captured at `createMeta`
|
|
12
|
-
* time, NEVER over a `this`-receiver. Do not "modernize" the `_`-prefixed
|
|
13
|
-
* TS-private reads below into `#private` access.
|
|
14
|
-
* ──────────────────────────────────────────────────────────────────────────
|
|
4
|
+
* `BlacMeta` and `BlacHydration` are classes whose accessors live on the
|
|
5
|
+
* prototype and read the container through one `#private` back-reference, so
|
|
6
|
+
* a container allocates a single small object here instead of a literal with
|
|
7
|
+
* seven closures. Members are therefore not own-enumerable: `Object.keys` and
|
|
8
|
+
* `JSON.stringify` see an empty object. Read the fields by name.
|
|
15
9
|
*/
|
|
16
10
|
import type { HydrationStatus } from './StateContainer';
|
|
17
11
|
import type { StateContainerConstructor } from '../types/utilities';
|
|
12
|
+
/**
|
|
13
|
+
* Non-enumerable brand carried on every `$blac` object. Used by the clobber
|
|
14
|
+
* guard in `StateContainer` to detect a subclass class-field shadowing the
|
|
15
|
+
* base's own `$blac` property, and by the meta tests. Intentionally NOT
|
|
16
|
+
* re-exported from the package barrel.
|
|
17
|
+
*/
|
|
18
|
+
export declare const META_BRAND: unique symbol;
|
|
18
19
|
/**
|
|
19
20
|
* Hydration sub-surface of {@link BlacMeta}. Exposes the container's
|
|
20
21
|
* hydration state machine — the `begin`/`apply`/`finish`/`fail`/`wait`
|
|
21
22
|
* methods and the `status`/`error`/`isHydrated`/`changedWhileHydrating`
|
|
22
23
|
* getters — namespaced under `$blac`.
|
|
23
24
|
*/
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
export declare class BlacHydration<S extends object> {
|
|
26
|
+
#private;
|
|
27
|
+
/** @internal */
|
|
28
|
+
constructor(container: object);
|
|
29
|
+
get status(): HydrationStatus;
|
|
30
|
+
get error(): Error | undefined;
|
|
31
|
+
get isHydrated(): boolean;
|
|
32
|
+
get changedWhileHydrating(): boolean;
|
|
29
33
|
begin(): void;
|
|
30
34
|
apply(next: S): boolean;
|
|
31
35
|
finish(): void;
|
|
@@ -38,36 +42,19 @@ export interface BlacHydration<S extends object> {
|
|
|
38
42
|
* `createdAt`, `disposed`, `dependencies`, and the hydration methods) under one
|
|
39
43
|
* namespace, keeping the generic names free for userland blocs.
|
|
40
44
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* are never snapshotted.
|
|
45
|
+
* Allocated once per container and frozen. Every accessor reads the
|
|
46
|
+
* container's current `_`-private fields live — values are never snapshotted.
|
|
44
47
|
*/
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
export declare class BlacMeta<S extends object = any> {
|
|
49
|
+
#private;
|
|
50
|
+
/** @internal Called from the `StateContainer` field initializer. */
|
|
51
|
+
constructor(container: object);
|
|
52
|
+
get name(): string;
|
|
53
|
+
get id(): string;
|
|
54
|
+
get debug(): boolean;
|
|
55
|
+
get createdAt(): number;
|
|
56
|
+
get disposed(): boolean;
|
|
57
|
+
get dependencies(): ReadonlyMap<StateContainerConstructor, string>;
|
|
58
|
+
/** Built on first access; identity-stable afterwards. */
|
|
59
|
+
get hydration(): BlacHydration<S>;
|
|
53
60
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Non-enumerable brand carried on every `$blac` object produced by
|
|
56
|
-
* {@link createMeta}. Used by the clobber guard in `StateContainer` to detect
|
|
57
|
-
* a subclass class-field shadowing the base's own `$blac` property, and by the
|
|
58
|
-
* meta tests. Intentionally NOT re-exported from the package barrel.
|
|
59
|
-
*/
|
|
60
|
-
export declare const META_BRAND: unique symbol;
|
|
61
|
-
/**
|
|
62
|
-
* Build the frozen, branded `$blac` meta object for a container.
|
|
63
|
-
*
|
|
64
|
-
* Called from a `StateContainer` field initializer (`$blac = createMeta(this)`).
|
|
65
|
-
* Only the back-reference is captured at this point; every getter/method reads
|
|
66
|
-
* the container's `_`-private fields lazily on access, so field-initializer
|
|
67
|
-
* ordering relative to those private fields is irrelevant.
|
|
68
|
-
*
|
|
69
|
-
* The getters close over `container` (the real instance), never over a
|
|
70
|
-
* `this`-receiver — this is what keeps `$blac` reads safe through
|
|
71
|
-
* `buildTrackedProxy`.
|
|
72
|
-
*/
|
|
73
|
-
export declare function createMeta<S extends object>(container: object): BlacMeta<S>;
|
package/dist/core/symbols.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @internal Apply one owner's (consumer's) deps slice to an instance.
|
|
3
|
-
* Called by framework adapters (e.g.
|
|
3
|
+
* Called by framework adapters (e.g. `@blac/react` useBloc) — not public API.
|
|
4
4
|
*/
|
|
5
5
|
export declare const APPLY_DEPS: unique symbol;
|
|
6
6
|
/**
|
|
@@ -24,3 +24,20 @@ export declare const ON_DISPOSE: unique symbol;
|
|
|
24
24
|
* helpers are the sole callers, mirroring the `APPLY_DEPS` precedent.
|
|
25
25
|
*/
|
|
26
26
|
export declare const INIT_CONFIG: unique symbol;
|
|
27
|
+
/**
|
|
28
|
+
* @internal Run `fn` with `state` temporarily reporting a render's tracking
|
|
29
|
+
* proxy, so getters record the paths they read. Called by `@blac/react`'s
|
|
30
|
+
* `buildTrackedProxy` — not public API.
|
|
31
|
+
*
|
|
32
|
+
* Replaces the old `this`-Proxy receiver: getters now run with `this` bound to
|
|
33
|
+
* the real instance, so ES `#private` works in user blocs.
|
|
34
|
+
*/
|
|
35
|
+
export declare const WITH_TRACKED_STATE: unique symbol;
|
|
36
|
+
/**
|
|
37
|
+
* @internal Drive the activation lifecycle from the registry's 0↔1 ownership
|
|
38
|
+
* transition. Owns the per-instance AbortController so `onActivate`'s signal
|
|
39
|
+
* aborts on the matching deactivation and on dispose.
|
|
40
|
+
*
|
|
41
|
+
* Framework-only — `StateContainerRegistry` is the sole caller.
|
|
42
|
+
*/
|
|
43
|
+
export declare const SET_ACTIVE: unique symbol;
|
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import type { EqualityFn } from '../config';
|
|
2
2
|
/**
|
|
3
|
-
* Configuration options for the
|
|
4
|
-
*
|
|
3
|
+
* Configuration options for the `@blac` decorator. Any combination may be
|
|
4
|
+
* given at once.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
/** Mark bloc to never be auto-disposed when ref count reaches 0 */
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
export interface BlacOptions {
|
|
7
|
+
/** Mark bloc to never be auto-disposed when ref count reaches 0 */
|
|
8
|
+
keepAlive?: true;
|
|
9
|
+
/** Exclude bloc from DevTools tracking (prevents infinite loops) */
|
|
10
|
+
excludeFromDevTools?: true;
|
|
11
|
+
/**
|
|
12
|
+
* Override the global equality check for this bloc.
|
|
13
|
+
* Return `true` to skip the emit (states considered equal).
|
|
14
|
+
*/
|
|
15
|
+
equality?: EqualityFn;
|
|
16
|
+
/**
|
|
17
|
+
* Override the default structural-hash identity key.
|
|
18
|
+
* The function receives `args` and returns the instance key string.
|
|
19
|
+
* Distinct return values → distinct instances; identical values → shared instance.
|
|
20
|
+
* Non-identity fields can be excluded so they don't fork new instances.
|
|
21
|
+
*/
|
|
22
|
+
key?: (args: any) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Explicit, minification-safe identity for this bloc class. Falls back to
|
|
25
|
+
* `constructor.name` when unset, which collides across classes once a
|
|
26
|
+
* minifier shortens class names.
|
|
27
|
+
*/
|
|
28
|
+
name?: string;
|
|
21
29
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Override the default structural-hash identity key.
|
|
24
|
-
* The function receives `args` and returns the instance key string.
|
|
25
|
-
* Distinct return values → distinct instances; identical values → shared instance.
|
|
26
|
-
* Non-identity fields can be excluded so they don't fork new instances.
|
|
27
|
-
*/
|
|
28
|
-
| {
|
|
29
|
-
key: (args: any) => string;
|
|
30
|
-
};
|
|
31
30
|
/**
|
|
32
31
|
* Decorator to configure StateContainer classes.
|
|
33
32
|
*
|
|
@@ -38,6 +37,9 @@ export type BlacOptions =
|
|
|
38
37
|
*
|
|
39
38
|
* @blac({ excludeFromDevTools: true })
|
|
40
39
|
* class InternalBloc extends Cubit<InternalState> {}
|
|
40
|
+
*
|
|
41
|
+
* @blac({ keepAlive: true, key: (args) => args.userId })
|
|
42
|
+
* class UserBloc extends Cubit<UserState> {}
|
|
41
43
|
* ```
|
|
42
44
|
*
|
|
43
45
|
* @example Function syntax (no decorator support needed)
|