@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,8 +1,13 @@
|
|
|
1
|
-
const require_StateContainerRegistry = require("./StateContainerRegistry-
|
|
2
|
-
const require_config = require("./config-hWTayX76.cjs");
|
|
1
|
+
const require_StateContainerRegistry = require("./StateContainerRegistry-MkT0W4C2.cjs");
|
|
3
2
|
let _dirtytalk_structural = require("@dirtytalk/structural");
|
|
4
3
|
//#region src/utils/idGenerator.ts
|
|
5
4
|
/**
|
|
5
|
+
* Centralized ID Generation
|
|
6
|
+
*
|
|
7
|
+
* Provides consistent, collision-resistant ID generation for all BlaC subsystems.
|
|
8
|
+
* Uses timestamp + counter + random suffix for uniqueness.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
6
11
|
* Generate simple ID with timestamp and random (no counter tracking)
|
|
7
12
|
*
|
|
8
13
|
* Format: `${prefix}:${timestamp}_${random}`
|
|
@@ -21,86 +26,133 @@ function generateSimpleId(prefix, affix) {
|
|
|
21
26
|
return `${prefix}:${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
22
27
|
}
|
|
23
28
|
//#endregion
|
|
29
|
+
//#region src/registry/config.ts
|
|
30
|
+
let _registry = require_StateContainerRegistry.globalRegistry;
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
function getRegistry() {
|
|
35
|
+
return _registry;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
function setRegistry(registry) {
|
|
41
|
+
_registry = registry;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
function getStats() {
|
|
47
|
+
return _registry.getStats();
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
24
50
|
//#region src/core/meta.ts
|
|
25
51
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
52
|
+
* `$blac` meta namespace for `StateContainer`.
|
|
53
|
+
*
|
|
54
|
+
* `BlacMeta` and `BlacHydration` are classes whose accessors live on the
|
|
55
|
+
* prototype and read the container through one `#private` back-reference, so
|
|
56
|
+
* a container allocates a single small object here instead of a literal with
|
|
57
|
+
* seven closures. Members are therefore not own-enumerable: `Object.keys` and
|
|
58
|
+
* `JSON.stringify` see an empty object. Read the fields by name.
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* Non-enumerable brand carried on every `$blac` object. Used by the clobber
|
|
62
|
+
* guard in `StateContainer` to detect a subclass class-field shadowing the
|
|
63
|
+
* base's own `$blac` property, and by the meta tests. Intentionally NOT
|
|
64
|
+
* re-exported from the package barrel.
|
|
30
65
|
*/
|
|
31
66
|
const META_BRAND = Symbol("blac.meta");
|
|
32
67
|
const EMPTY_DEPS = /* @__PURE__ */ new Map();
|
|
33
68
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
* Hydration sub-surface of {@link BlacMeta}. Exposes the container's
|
|
70
|
+
* hydration state machine — the `begin`/`apply`/`finish`/`fail`/`wait`
|
|
71
|
+
* methods and the `status`/`error`/`isHydrated`/`changedWhileHydrating`
|
|
72
|
+
* getters — namespaced under `$blac`.
|
|
73
|
+
*/
|
|
74
|
+
var BlacHydration = class {
|
|
75
|
+
#c;
|
|
76
|
+
/** @internal */
|
|
77
|
+
constructor(container) {
|
|
78
|
+
this.#c = container;
|
|
79
|
+
Object.freeze(this);
|
|
80
|
+
}
|
|
81
|
+
get status() {
|
|
82
|
+
return this.#c._hydrationStatus;
|
|
83
|
+
}
|
|
84
|
+
get error() {
|
|
85
|
+
return this.#c._hydrationError;
|
|
86
|
+
}
|
|
87
|
+
get isHydrated() {
|
|
88
|
+
return this.#c._hydrationStatus === "hydrated";
|
|
89
|
+
}
|
|
90
|
+
get changedWhileHydrating() {
|
|
91
|
+
return this.#c._changedWhileHydrating;
|
|
92
|
+
}
|
|
93
|
+
begin() {
|
|
94
|
+
this.#c._beginHydration();
|
|
95
|
+
}
|
|
96
|
+
apply(next) {
|
|
97
|
+
return this.#c._applyHydratedState(next);
|
|
98
|
+
}
|
|
99
|
+
finish() {
|
|
100
|
+
this.#c._finishHydration();
|
|
101
|
+
}
|
|
102
|
+
fail(error) {
|
|
103
|
+
this.#c._failHydration(error);
|
|
104
|
+
}
|
|
105
|
+
wait() {
|
|
106
|
+
return this.#c._waitForHydration();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* The reserved `$blac` instance member on every `StateContainer`. Gathers the
|
|
111
|
+
* container's identity/lifecycle/hydration surface (`name`, `id`, `debug`,
|
|
112
|
+
* `createdAt`, `disposed`, `dependencies`, and the hydration methods) under one
|
|
113
|
+
* namespace, keeping the generic names free for userland blocs.
|
|
40
114
|
*
|
|
41
|
-
*
|
|
42
|
-
* `
|
|
43
|
-
* `buildTrackedProxy`.
|
|
115
|
+
* Allocated once per container and frozen. Every accessor reads the
|
|
116
|
+
* container's current `_`-private fields live — values are never snapshotted.
|
|
44
117
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return c._applyHydratedState(next);
|
|
84
|
-
},
|
|
85
|
-
finish() {
|
|
86
|
-
c._finishHydration();
|
|
87
|
-
},
|
|
88
|
-
fail(error) {
|
|
89
|
-
c._failHydration(error);
|
|
90
|
-
},
|
|
91
|
-
wait() {
|
|
92
|
-
return c._waitForHydration();
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
};
|
|
96
|
-
Object.defineProperty(meta, META_BRAND, {
|
|
97
|
-
value: true,
|
|
98
|
-
enumerable: false,
|
|
99
|
-
writable: false,
|
|
100
|
-
configurable: false
|
|
101
|
-
});
|
|
102
|
-
return Object.freeze(meta);
|
|
103
|
-
}
|
|
118
|
+
var BlacMeta = class {
|
|
119
|
+
#c;
|
|
120
|
+
#hydration;
|
|
121
|
+
/** @internal Called from the `StateContainer` field initializer. */
|
|
122
|
+
constructor(container) {
|
|
123
|
+
this.#c = container;
|
|
124
|
+
Object.freeze(this);
|
|
125
|
+
}
|
|
126
|
+
get name() {
|
|
127
|
+
return this.#c._name;
|
|
128
|
+
}
|
|
129
|
+
get id() {
|
|
130
|
+
const c = this.#c;
|
|
131
|
+
return c._instanceId ??= generateSimpleId(require_StateContainerRegistry.getBlacName(c.constructor), "main");
|
|
132
|
+
}
|
|
133
|
+
get debug() {
|
|
134
|
+
return this.#c._debug;
|
|
135
|
+
}
|
|
136
|
+
get createdAt() {
|
|
137
|
+
return this.#c._createdAt;
|
|
138
|
+
}
|
|
139
|
+
get disposed() {
|
|
140
|
+
return this.#c._disposed;
|
|
141
|
+
}
|
|
142
|
+
get dependencies() {
|
|
143
|
+
return this.#c._dependencies ?? EMPTY_DEPS;
|
|
144
|
+
}
|
|
145
|
+
/** Built on first access; identity-stable afterwards. */
|
|
146
|
+
get hydration() {
|
|
147
|
+
return this.#hydration ??= new BlacHydration(this.#c);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
Object.defineProperty(BlacMeta.prototype, META_BRAND, {
|
|
151
|
+
value: true,
|
|
152
|
+
enumerable: false,
|
|
153
|
+
writable: false,
|
|
154
|
+
configurable: false
|
|
155
|
+
});
|
|
104
156
|
//#endregion
|
|
105
157
|
//#region src/core/StateContainer.ts
|
|
106
158
|
/**
|
|
@@ -111,6 +163,8 @@ function createMeta(container) {
|
|
|
111
163
|
* @internal — exported for `@blac/react`; not part of the public API.
|
|
112
164
|
*/
|
|
113
165
|
const DEP_BRAND = Symbol("blac.depHandle");
|
|
166
|
+
const EMPTY_RECORD = Object.freeze({});
|
|
167
|
+
let deactivatedReason;
|
|
114
168
|
/**
|
|
115
169
|
* Shallow per-key `Object.is` comparison of two plain records. Keys are
|
|
116
170
|
* considered: a key present in one but not the other (regardless of value)
|
|
@@ -167,7 +221,7 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
167
221
|
const owners = this._depsByOwner ??= /* @__PURE__ */ new Map();
|
|
168
222
|
const prevSlice = owners.get(ownerId);
|
|
169
223
|
if (prevSlice && shallowEqualRecord(prevSlice, slice)) return;
|
|
170
|
-
if (
|
|
224
|
+
if (require_StateContainerRegistry.IS_DEV) for (const key of Object.keys(slice)) for (const [otherOwner, otherSlice] of owners) {
|
|
171
225
|
if (otherOwner === ownerId) continue;
|
|
172
226
|
if (key in otherSlice && otherSlice[key] !== slice[key]) console.warn(`[${this._name}] multiple owners writing dep \`${String(key)}\`; last write wins`);
|
|
173
227
|
}
|
|
@@ -182,6 +236,42 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
182
236
|
if (!this._depsByOwner?.delete(ownerId)) return;
|
|
183
237
|
this.reconcileDeps();
|
|
184
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* @internal Subscribe to this instance's own disposal. Delegates to the
|
|
241
|
+
* per-instance `'dispose'` system event — used by `watch()` in place of
|
|
242
|
+
* filtering the global registry `'disposed'` event.
|
|
243
|
+
*/
|
|
244
|
+
[require_StateContainerRegistry.ON_DISPOSE](handler) {
|
|
245
|
+
return this.onSystemEvent("dispose", handler);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* @internal Drive the 0↔1 ownership transition. Idempotent: repeated calls
|
|
249
|
+
* with the same value are no-ops, so the registry can call it from every
|
|
250
|
+
* acquire/release without tracking edges itself.
|
|
251
|
+
*
|
|
252
|
+
* Returns which real transition (if any) just happened, so the registry can
|
|
253
|
+
* emit the matching `activated`/`deactivated` plugin event without exposing
|
|
254
|
+
* `_activation` itself — `'none'` for an idempotent no-op call.
|
|
255
|
+
*/
|
|
256
|
+
[require_StateContainerRegistry.SET_ACTIVE](active) {
|
|
257
|
+
if (this._disposed) return "none";
|
|
258
|
+
if (active === (this._activation !== null)) return "none";
|
|
259
|
+
if (active) {
|
|
260
|
+
this._activation = new AbortController();
|
|
261
|
+
this.onActivate(this._activation.signal);
|
|
262
|
+
return {
|
|
263
|
+
kind: "activated",
|
|
264
|
+
signal: this._activation.signal
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
this._abortActivation();
|
|
268
|
+
this.onDeactivate();
|
|
269
|
+
return "deactivated";
|
|
270
|
+
}
|
|
271
|
+
_abortActivation() {
|
|
272
|
+
this._activation?.abort(deactivatedReason ??= new DOMException("The bloc was deactivated", "AbortError"));
|
|
273
|
+
this._activation = null;
|
|
274
|
+
}
|
|
185
275
|
reconcileDeps() {
|
|
186
276
|
const prev = this._deps;
|
|
187
277
|
const next = {};
|
|
@@ -193,6 +283,31 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
193
283
|
this._registry.emit("depsChanged", this, prev, next);
|
|
194
284
|
}
|
|
195
285
|
onDepsChanged(_next, _prev) {}
|
|
286
|
+
get state() {
|
|
287
|
+
return this._stateOverride ?? super.state;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @internal Run `fn` (with `this` = this instance, so a prototype getter can
|
|
291
|
+
* be passed directly) while `state` reports `tracked` and dep handles read
|
|
292
|
+
* off `this` route through `onDepHandle`. Restored in `finally`, and
|
|
293
|
+
* nestable — getters reading other getters stay in tracked context.
|
|
294
|
+
*
|
|
295
|
+
* The dep hook lives here rather than in the adapter's proxy because getters
|
|
296
|
+
* now run with `this` = the real instance (so ES `#private` works), which
|
|
297
|
+
* means a `this.someDep` read never passes through the proxy's trap.
|
|
298
|
+
*/
|
|
299
|
+
[require_StateContainerRegistry.WITH_TRACKED_STATE](tracked, fn, onDepHandle) {
|
|
300
|
+
const prevState = this._stateOverride;
|
|
301
|
+
const prevHook = this._depHandleHook;
|
|
302
|
+
this._stateOverride = tracked;
|
|
303
|
+
this._depHandleHook = onDepHandle;
|
|
304
|
+
try {
|
|
305
|
+
return fn.call(this);
|
|
306
|
+
} finally {
|
|
307
|
+
this._stateOverride = prevState;
|
|
308
|
+
this._depHandleHook = prevHook;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
196
311
|
get args() {
|
|
197
312
|
return this._config.args;
|
|
198
313
|
}
|
|
@@ -218,10 +333,17 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
218
333
|
const resolve = (args) => {
|
|
219
334
|
const effectiveArgs = args ?? defaultArgs;
|
|
220
335
|
const key = this._registry.resolveKey(Type, void 0, effectiveArgs);
|
|
221
|
-
return this._registry.
|
|
336
|
+
return this._registry.acquire(Type, key, {
|
|
337
|
+
canCreate: true,
|
|
338
|
+
countRef: false,
|
|
339
|
+
args: effectiveArgs,
|
|
340
|
+
dependent: this
|
|
341
|
+
});
|
|
222
342
|
};
|
|
223
343
|
const handle = {
|
|
224
344
|
track: (options) => {
|
|
345
|
+
const wrapped = this._depHandleHook?.(handle);
|
|
346
|
+
if (wrapped !== void 0 && wrapped !== handle) return wrapped.track(options);
|
|
225
347
|
const instance = resolve(options?.args);
|
|
226
348
|
return [instance.state, instance];
|
|
227
349
|
},
|
|
@@ -241,40 +363,46 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
241
363
|
constructor(initialState, options) {
|
|
242
364
|
super(initialState, options);
|
|
243
365
|
this._depsByOwner = null;
|
|
244
|
-
this._deps =
|
|
366
|
+
this._deps = EMPTY_RECORD;
|
|
245
367
|
this._disposed = false;
|
|
246
368
|
this._hydrationStatus = "idle";
|
|
247
369
|
this._changedWhileHydrating = false;
|
|
248
370
|
this._hydrationPromise = null;
|
|
249
371
|
this._hydrationPromiseSettled = false;
|
|
250
|
-
this._config =
|
|
372
|
+
this._config = EMPTY_RECORD;
|
|
251
373
|
this._initCalled = false;
|
|
374
|
+
this._activation = null;
|
|
252
375
|
this._emitWindowStart = 0;
|
|
253
376
|
this._emitCount = 0;
|
|
254
377
|
this._emitRateWarned = false;
|
|
255
|
-
this._systemEventHandlers =
|
|
378
|
+
this._systemEventHandlers = null;
|
|
256
379
|
this._dependencies = null;
|
|
257
380
|
this._pendingChange = null;
|
|
258
381
|
this._bridgeUnsub = null;
|
|
259
|
-
this._registry =
|
|
382
|
+
this._registry = getRegistry();
|
|
260
383
|
this._equalityFn = require_StateContainerRegistry.getBlacConfig().equality;
|
|
261
|
-
this._name = this.constructor
|
|
384
|
+
this._name = require_StateContainerRegistry.getBlacName(this.constructor);
|
|
262
385
|
this._debug = false;
|
|
263
|
-
this._instanceId = generateSimpleId(this.constructor.name, "main");
|
|
264
386
|
this._createdAt = Date.now();
|
|
265
|
-
this.$blac =
|
|
387
|
+
this.$blac = new BlacMeta(this);
|
|
266
388
|
this.onSystemEvent = (event, handler) => {
|
|
267
|
-
|
|
389
|
+
const all = this._systemEventHandlers ??= /* @__PURE__ */ new Map();
|
|
390
|
+
let handlers = all.get(event);
|
|
268
391
|
if (!handlers) {
|
|
269
392
|
handlers = /* @__PURE__ */ new Set();
|
|
270
|
-
|
|
393
|
+
all.set(event, handlers);
|
|
271
394
|
}
|
|
272
395
|
handlers.add(handler);
|
|
396
|
+
if (event === "stateChanged" && this._bridgeUnsub === null) this._bridgeUnsub = this.channel.subscribe(() => _dirtytalk_structural.ALL_PATHS, () => this._drainPending());
|
|
273
397
|
return () => {
|
|
274
398
|
handlers?.delete(handler);
|
|
399
|
+
if (event === "stateChanged" && handlers?.size === 0) {
|
|
400
|
+
this._bridgeUnsub?.();
|
|
401
|
+
this._bridgeUnsub = null;
|
|
402
|
+
this._pendingChange = null;
|
|
403
|
+
}
|
|
275
404
|
};
|
|
276
405
|
};
|
|
277
|
-
this._bridgeUnsub = this.channel.subscribe(() => _dirtytalk_structural.ALL_PATHS, () => this._drainPending());
|
|
278
406
|
}
|
|
279
407
|
/**
|
|
280
408
|
* Called once after construction with the args passed at acquire time, before the first
|
|
@@ -283,6 +411,24 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
283
411
|
*/
|
|
284
412
|
init(_args) {}
|
|
285
413
|
/**
|
|
414
|
+
* Called when this instance goes from unowned to owned (first ref or first
|
|
415
|
+
* `depend()` dependent). Override to start work that should only run while
|
|
416
|
+
* something is actually using the instance — fetches, timers, listeners.
|
|
417
|
+
*
|
|
418
|
+
* `signal` aborts on the matching {@link onDeactivate} and on dispose, so
|
|
419
|
+
* async work started here can be cancelled without extra bookkeeping.
|
|
420
|
+
*
|
|
421
|
+
* Runs before the first `useBlocDeps` slice is applied, so `this.deps` is
|
|
422
|
+
* empty on first activation — use `onDepsChanged` for deps-driven work.
|
|
423
|
+
*/
|
|
424
|
+
onActivate(_signal) {}
|
|
425
|
+
/**
|
|
426
|
+
* Called when this instance goes from owned back to unowned while surviving
|
|
427
|
+
* in the registry (i.e. `keepAlive`). A disposed instance does NOT get this
|
|
428
|
+
* callback — `dispose()` is the teardown path for that case.
|
|
429
|
+
*/
|
|
430
|
+
onDeactivate() {}
|
|
431
|
+
/**
|
|
286
432
|
* @internal Framework-only configuration entry point (registry + testing
|
|
287
433
|
* helpers). Writes the `_`-private identity fields directly, resolves
|
|
288
434
|
* per-class equality, emits the registry `created` event, and runs `init()`
|
|
@@ -290,17 +436,18 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
290
436
|
*/
|
|
291
437
|
[require_StateContainerRegistry.INIT_CONFIG](config) {
|
|
292
438
|
this._config = { ...config };
|
|
293
|
-
|
|
439
|
+
const className = require_StateContainerRegistry.getBlacName(this.constructor);
|
|
440
|
+
this._name = this._config.name || className;
|
|
294
441
|
this._debug = this._config.debug ?? false;
|
|
295
|
-
this._instanceId = generateSimpleId(
|
|
442
|
+
this._instanceId = generateSimpleId(className, this._config.instanceId);
|
|
296
443
|
const perClass = require_StateContainerRegistry.getClassEquality(this.constructor);
|
|
297
444
|
this._equalityFn = perClass ?? require_StateContainerRegistry.getBlacConfig().equality;
|
|
298
|
-
this._registry.emit("created", this);
|
|
299
445
|
if (!this._initCalled) {
|
|
300
446
|
this._initCalled = true;
|
|
301
447
|
this.init(this._config.args);
|
|
302
448
|
}
|
|
303
|
-
|
|
449
|
+
this._registry.emit("created", this);
|
|
450
|
+
if (require_StateContainerRegistry.IS_DEV) {
|
|
304
451
|
if (!this.$blac?.[META_BRAND]) console.warn(`[blac] ${this.constructor.name} appears to declare its own \`$blac\` member, which shadows the reserved meta namespace. \`$blac\` is reserved by StateContainer — remove the subclass field.`);
|
|
305
452
|
}
|
|
306
453
|
}
|
|
@@ -316,9 +463,11 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
316
463
|
this.emitSystemEvent("dispose", void 0);
|
|
317
464
|
this._bridgeUnsub?.();
|
|
318
465
|
this._bridgeUnsub = null;
|
|
319
|
-
this.
|
|
466
|
+
this._abortActivation();
|
|
467
|
+
this._systemEventHandlers = null;
|
|
320
468
|
this._pendingChange = null;
|
|
321
469
|
this._registry.emit("disposed", this);
|
|
470
|
+
super.dispose();
|
|
322
471
|
if (this._debug) console.log(`[${this._name}] Disposed successfully`);
|
|
323
472
|
}
|
|
324
473
|
emit(next) {
|
|
@@ -334,22 +483,17 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
334
483
|
* preserved.
|
|
335
484
|
*/
|
|
336
485
|
patch(partial) {
|
|
337
|
-
if (this._disposed)
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const prev = this.state;
|
|
341
|
-
let allEqual = true;
|
|
342
|
-
for (const key of partialKeys) if (!Object.is(prev[key], partial[key])) {
|
|
343
|
-
allEqual = false;
|
|
344
|
-
break;
|
|
486
|
+
if (this._disposed) {
|
|
487
|
+
this._warnDisposedMutation("patch");
|
|
488
|
+
return;
|
|
345
489
|
}
|
|
346
|
-
|
|
347
|
-
if (process.env.NODE_ENV !== "production") this._checkEmitRate();
|
|
490
|
+
const prev = super.state;
|
|
348
491
|
super.patch(partial);
|
|
349
|
-
const next =
|
|
492
|
+
const next = super.state;
|
|
350
493
|
if (Object.is(prev, next)) return;
|
|
494
|
+
if (require_StateContainerRegistry.IS_DEV && !this._emitRateWarned) this._checkEmitRate();
|
|
351
495
|
if (this._hydrationStatus === "hydrating") this._changedWhileHydrating = true;
|
|
352
|
-
if (this._pendingChange) this._pendingChange.next = next;
|
|
496
|
+
if (this._bridgeUnsub !== null) if (this._pendingChange) this._pendingChange.next = next;
|
|
353
497
|
else this._pendingChange = {
|
|
354
498
|
prev,
|
|
355
499
|
next
|
|
@@ -357,13 +501,16 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
357
501
|
if (this._registry.hasStateChangedListeners) this._registry.notifyStateChanged(this, prev, next);
|
|
358
502
|
}
|
|
359
503
|
applyState(next, source) {
|
|
360
|
-
if (this._disposed)
|
|
361
|
-
|
|
504
|
+
if (this._disposed) {
|
|
505
|
+
this._warnDisposedMutation("emit");
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const prev = super.state;
|
|
362
509
|
if (prev === next) return;
|
|
363
510
|
if (this._equalityFn(prev, next)) return;
|
|
364
|
-
if (
|
|
511
|
+
if (require_StateContainerRegistry.IS_DEV && !this._emitRateWarned) this._checkEmitRate();
|
|
365
512
|
if (this._hydrationStatus === "hydrating" && source !== "hydration") this._changedWhileHydrating = true;
|
|
366
|
-
if (this._pendingChange) this._pendingChange.next = next;
|
|
513
|
+
if (this._bridgeUnsub !== null) if (this._pendingChange) this._pendingChange.next = next;
|
|
367
514
|
else this._pendingChange = {
|
|
368
515
|
prev,
|
|
369
516
|
next
|
|
@@ -380,7 +527,7 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
380
527
|
const pending = this._pendingChange;
|
|
381
528
|
if (!pending) return;
|
|
382
529
|
this._pendingChange = null;
|
|
383
|
-
const handlers = this._systemEventHandlers
|
|
530
|
+
const handlers = this._systemEventHandlers?.get("stateChanged");
|
|
384
531
|
if (handlers && handlers.size > 0) {
|
|
385
532
|
const payload = {
|
|
386
533
|
state: pending.next,
|
|
@@ -409,9 +556,15 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
409
556
|
this.ensureHydrationPromise();
|
|
410
557
|
this.setHydrationStatus("hydrating");
|
|
411
558
|
}
|
|
559
|
+
_warnDisposedMutation(op) {
|
|
560
|
+
if (require_StateContainerRegistry.IS_DEV) console.warn(`[blac] ${this._name}: ${op}() after dispose ignored. This usually means an async method resolved after the last consumer unmounted. Guard with \`if (this.$blac.disposed) return\` after each \`await\`, or abort the work from \`onSystemEvent('dispose', ...)\`.`);
|
|
561
|
+
}
|
|
412
562
|
_applyHydratedState(next) {
|
|
413
563
|
if (this._disposed) return false;
|
|
414
|
-
if (this._hydrationStatus !== "hydrating" || this._changedWhileHydrating)
|
|
564
|
+
if (this._hydrationStatus !== "hydrating" || this._changedWhileHydrating) {
|
|
565
|
+
if (require_StateContainerRegistry.IS_DEV && this._changedWhileHydrating) console.warn(`[blac] ${this._name}: persisted state discarded because the container emitted while hydrating.`);
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
415
568
|
this.applyState(next, "hydration");
|
|
416
569
|
return true;
|
|
417
570
|
}
|
|
@@ -473,7 +626,7 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
473
626
|
this._rejectHydrationPromise?.(error);
|
|
474
627
|
}
|
|
475
628
|
emitSystemEvent(event, payload) {
|
|
476
|
-
const handlers = this._systemEventHandlers
|
|
629
|
+
const handlers = this._systemEventHandlers?.get(event);
|
|
477
630
|
if (!handlers) return;
|
|
478
631
|
for (const handler of handlers) try {
|
|
479
632
|
handler(payload);
|
|
@@ -489,7 +642,7 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
489
642
|
*/
|
|
490
643
|
_checkEmitRate() {
|
|
491
644
|
const limit = require_StateContainerRegistry.getBlacConfig().maxEmitsPerSecond;
|
|
492
|
-
if (!(limit > 0) || !Number.isFinite(limit)
|
|
645
|
+
if (!(limit > 0) || !Number.isFinite(limit)) return;
|
|
493
646
|
const now = Date.now();
|
|
494
647
|
if (now - this._emitWindowStart >= 1e3) {
|
|
495
648
|
this._emitWindowStart = now;
|
|
@@ -506,19 +659,60 @@ var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
|
|
|
506
659
|
//#endregion
|
|
507
660
|
//#region src/core/Cubit.ts
|
|
508
661
|
/**
|
|
509
|
-
* `Cubit<S>` is a `StateContainer<S>`
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* `
|
|
513
|
-
*
|
|
662
|
+
* `Cubit<S>` is a `StateContainer<S>` that exposes mutation publicly.
|
|
663
|
+
*
|
|
664
|
+
* That is the whole difference, and it is a real one: on `StateContainer`
|
|
665
|
+
* `emit` / `patch` / `update` are `protected`, so a container mutates itself
|
|
666
|
+
* from its own methods and callers go through the API it chooses to publish.
|
|
667
|
+
* `Cubit` re-declares the three as `public` for the cases where a caller
|
|
668
|
+
* legitimately drives state from outside — test helpers, devtools
|
|
669
|
+
* time-travel, benchmarks.
|
|
670
|
+
*
|
|
671
|
+
* Reach for `StateContainer` when business logic should live in the class,
|
|
672
|
+
* and `Cubit` when the caller owns the transitions.
|
|
673
|
+
*/
|
|
674
|
+
var Cubit = class extends StateContainer {
|
|
675
|
+
emit(next) {
|
|
676
|
+
super.emit(next);
|
|
677
|
+
}
|
|
678
|
+
patch(partial) {
|
|
679
|
+
super.patch(partial);
|
|
680
|
+
}
|
|
681
|
+
update(fn) {
|
|
682
|
+
super.update(fn);
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/registry/acquire.ts
|
|
687
|
+
/**
|
|
688
|
+
* Acquire an instance with ref tracking (ownership semantics). Instance
|
|
689
|
+
* identity is derived purely from `args` (via the class's `static key(args)`,
|
|
690
|
+
* a structural hash of `args`, or the default sentinel when there are none).
|
|
514
691
|
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
* wants "skip if no real change" patch semantics can wrap `patch`
|
|
519
|
-
* themselves or call `emit` after a manual equality check.
|
|
692
|
+
* @param BlocClass - The StateContainer class constructor
|
|
693
|
+
* @param opts - `args` derives the instance key; `refId` names the reference
|
|
694
|
+
* for debugging and is auto-generated when omitted.
|
|
520
695
|
*/
|
|
521
|
-
|
|
696
|
+
function acquire(BlocClass, opts) {
|
|
697
|
+
const registry = getRegistry();
|
|
698
|
+
const key = registry.resolveKey(BlocClass, void 0, opts?.args);
|
|
699
|
+
return registry.acquire(BlocClass, key, {
|
|
700
|
+
canCreate: true,
|
|
701
|
+
countRef: true,
|
|
702
|
+
refId: opts?.refId,
|
|
703
|
+
args: opts?.args
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Resolve the storage key an instance would be acquired under, given its
|
|
708
|
+
* construction `args`. This is the canonical key-computation path. Callers that
|
|
709
|
+
* both acquire and release against the `@internal` registry tier (e.g.
|
|
710
|
+
* `@blac/react` `useBloc`) must use this once and pass the same resolved key to
|
|
711
|
+
* both, so the ref is dropped under the key it was taken.
|
|
712
|
+
*/
|
|
713
|
+
function resolveInstanceKey(BlocClass, args) {
|
|
714
|
+
return getRegistry().resolveKey(BlocClass, void 0, args);
|
|
715
|
+
}
|
|
522
716
|
//#endregion
|
|
523
717
|
//#region src/registry/ensure.ts
|
|
524
718
|
/**
|
|
@@ -526,7 +720,7 @@ var Cubit = class extends StateContainer {};
|
|
|
526
720
|
* identity is derived purely from `args`, matching `acquire`.
|
|
527
721
|
*/
|
|
528
722
|
function ensure(BlocClass, opts) {
|
|
529
|
-
const registry =
|
|
723
|
+
const registry = getRegistry();
|
|
530
724
|
const key = registry.resolveKey(BlocClass, void 0, opts?.args);
|
|
531
725
|
return registry.ensure(BlocClass, key, opts?.args);
|
|
532
726
|
}
|
|
@@ -549,11 +743,41 @@ Object.defineProperty(exports, "StateContainer", {
|
|
|
549
743
|
return StateContainer;
|
|
550
744
|
}
|
|
551
745
|
});
|
|
746
|
+
Object.defineProperty(exports, "acquire", {
|
|
747
|
+
enumerable: true,
|
|
748
|
+
get: function() {
|
|
749
|
+
return acquire;
|
|
750
|
+
}
|
|
751
|
+
});
|
|
552
752
|
Object.defineProperty(exports, "ensure", {
|
|
553
753
|
enumerable: true,
|
|
554
754
|
get: function() {
|
|
555
755
|
return ensure;
|
|
556
756
|
}
|
|
557
757
|
});
|
|
758
|
+
Object.defineProperty(exports, "getRegistry", {
|
|
759
|
+
enumerable: true,
|
|
760
|
+
get: function() {
|
|
761
|
+
return getRegistry;
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
Object.defineProperty(exports, "getStats", {
|
|
765
|
+
enumerable: true,
|
|
766
|
+
get: function() {
|
|
767
|
+
return getStats;
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
Object.defineProperty(exports, "resolveInstanceKey", {
|
|
771
|
+
enumerable: true,
|
|
772
|
+
get: function() {
|
|
773
|
+
return resolveInstanceKey;
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
Object.defineProperty(exports, "setRegistry", {
|
|
777
|
+
enumerable: true,
|
|
778
|
+
get: function() {
|
|
779
|
+
return setRegistry;
|
|
780
|
+
}
|
|
781
|
+
});
|
|
558
782
|
|
|
559
|
-
//# sourceMappingURL=ensure-
|
|
783
|
+
//# sourceMappingURL=ensure-D15vGnk5.cjs.map
|