@spearwolf/shadow-objects 0.33.0 → 0.34.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/CHANGELOG.md +320 -61
- package/README.md +57 -13
- package/bundle.js +5 -54
- package/package.json +7 -3
- package/src/ChangeTrailRefusedError.d.ts +27 -0
- package/src/ChangeTrailRefusedError.d.ts.map +1 -0
- package/src/ChangeTrailRefusedError.js +12 -0
- package/src/ChangeTrailRefusedError.js.map +7 -0
- package/src/EntityUuidInUseError.d.ts +19 -0
- package/src/EntityUuidInUseError.d.ts.map +1 -0
- package/src/EntityUuidInUseError.js +11 -0
- package/src/EntityUuidInUseError.js.map +7 -0
- package/src/WorkerTimeoutError.d.ts +25 -0
- package/src/WorkerTimeoutError.d.ts.map +1 -0
- package/src/WorkerTimeoutError.js +12 -0
- package/src/WorkerTimeoutError.js.map +7 -0
- package/src/bundle.d.ts +1 -1
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +1 -1
- package/src/bundle.js.map +2 -2
- package/src/constants.d.ts +9 -2
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +1 -1
- package/src/constants.js.map +2 -2
- package/src/create-worker.bundle.d.ts +1 -1
- package/src/create-worker.bundle.d.ts.map +1 -1
- package/src/create-worker.bundle.js.map +1 -1
- package/src/create-worker.d.ts +1 -1
- package/src/create-worker.d.ts.map +1 -1
- package/src/create-worker.js.map +1 -1
- package/src/elements/ShaeElement.d.ts +70 -2
- package/src/elements/ShaeElement.d.ts.map +1 -1
- package/src/elements/ShaeElement.js +129 -25
- package/src/elements/ShaeElement.js.map +3 -3
- package/src/elements/ShaeEntElement.d.ts +39 -1
- package/src/elements/ShaeEntElement.d.ts.map +1 -1
- package/src/elements/ShaeEntElement.js +397 -167
- package/src/elements/ShaeEntElement.js.map +2 -2
- package/src/elements/ShaeLifecycleElement.d.ts +71 -0
- package/src/elements/ShaeLifecycleElement.d.ts.map +1 -0
- package/src/elements/ShaeLifecycleElement.js +83 -0
- package/src/elements/ShaeLifecycleElement.js.map +7 -0
- package/src/elements/ShaePropElement.d.ts +52 -2
- package/src/elements/ShaePropElement.d.ts.map +1 -1
- package/src/elements/ShaePropElement.js +240 -219
- package/src/elements/ShaePropElement.js.map +2 -2
- package/src/elements/ShaeWorkerElement.d.ts +49 -5
- package/src/elements/ShaeWorkerElement.d.ts.map +1 -1
- package/src/elements/ShaeWorkerElement.js +204 -73
- package/src/elements/ShaeWorkerElement.js.map +2 -2
- package/src/elements/constants.d.ts +6 -0
- package/src/elements/constants.d.ts.map +1 -1
- package/src/elements/constants.js +12 -0
- package/src/elements/constants.js.map +2 -2
- package/src/elements/deferredTeardown.d.ts +24 -0
- package/src/elements/deferredTeardown.d.ts.map +1 -0
- package/src/elements/deferredTeardown.js +30 -0
- package/src/elements/deferredTeardown.js.map +7 -0
- package/src/elements/displayContentsRule.d.ts +25 -0
- package/src/elements/displayContentsRule.d.ts.map +1 -0
- package/src/elements/displayContentsRule.js +37 -0
- package/src/elements/displayContentsRule.js.map +7 -0
- package/src/elements/events.d.ts +10 -7
- package/src/elements/events.d.ts.map +1 -1
- package/src/elements/forwardCustomEvents.d.ts +19 -0
- package/src/elements/forwardCustomEvents.d.ts.map +1 -0
- package/src/elements/forwardCustomEvents.js +47 -0
- package/src/elements/forwardCustomEvents.js.map +7 -0
- package/src/elements/hostedSlots.d.ts +36 -0
- package/src/elements/hostedSlots.d.ts.map +1 -0
- package/src/elements/hostedSlots.js +118 -0
- package/src/elements/hostedSlots.js.map +7 -0
- package/src/elements/parentRemoval.d.ts +18 -0
- package/src/elements/parentRemoval.d.ts.map +1 -0
- package/src/elements/parentRemoval.js +60 -0
- package/src/elements/parentRemoval.js.map +7 -0
- package/src/elements/propValueConverters.d.ts +3 -0
- package/src/elements/propValueConverters.d.ts.map +1 -0
- package/src/elements/propValueConverters.js +54 -0
- package/src/elements/propValueConverters.js.map +7 -0
- package/src/elements/requestEntAncestor.d.ts +32 -0
- package/src/elements/requestEntAncestor.d.ts.map +1 -0
- package/src/elements/requestEntAncestor.js +16 -0
- package/src/elements/requestEntAncestor.js.map +7 -0
- package/src/elements.js.map +1 -1
- package/src/in-the-dark/Entity.d.ts +113 -3
- package/src/in-the-dark/Entity.d.ts.map +1 -1
- package/src/in-the-dark/Entity.js +292 -63
- package/src/in-the-dark/Entity.js.map +3 -3
- package/src/in-the-dark/Kernel.d.ts +76 -17
- package/src/in-the-dark/Kernel.d.ts.map +1 -1
- package/src/in-the-dark/Kernel.js +410 -378
- package/src/in-the-dark/Kernel.js.map +3 -3
- package/src/in-the-dark/Registry.d.ts.map +1 -1
- package/src/in-the-dark/Registry.js +83 -14
- package/src/in-the-dark/Registry.js.map +2 -2
- package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
- package/src/in-the-dark/ShadowObject.js +1 -0
- package/src/in-the-dark/ShadowObject.js.map +2 -2
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts +126 -0
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts.map +1 -0
- package/src/in-the-dark/ShadowObjectCreationScope.js +596 -0
- package/src/in-the-dark/ShadowObjectCreationScope.js.map +7 -0
- package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
- package/src/in-the-dark/SignalsPath.js +2 -2
- package/src/in-the-dark/SignalsPath.js.map +2 -2
- package/src/in-the-dark/events.js.map +1 -1
- package/src/in-the-dark/importModule.d.ts +7 -0
- package/src/in-the-dark/importModule.d.ts.map +1 -1
- package/src/in-the-dark/importModule.js +5 -2
- package/src/in-the-dark/importModule.js.map +2 -2
- package/src/index.d.ts +7 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +5 -1
- package/src/index.js.map +2 -2
- package/src/shadow-objects.d.ts +2 -0
- package/src/shadow-objects.d.ts.map +1 -1
- package/src/shadow-objects.js +2 -0
- package/src/shadow-objects.js.map +2 -2
- package/src/shadow-objects.worker.js +0 -1
- package/src/shadow-objects.worker.js.map +2 -2
- package/src/shae-ent.js.map +1 -1
- package/src/shae-prop.js +2 -2
- package/src/shae-prop.js.map +2 -2
- package/src/shae-worker.js.map +1 -1
- package/src/types.d.ts +35 -4
- package/src/types.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.d.ts +45 -10
- package/src/utils/ConsoleLogger.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.js +51 -26
- package/src/utils/ConsoleLogger.js.map +2 -2
- package/src/utils/FrameLoop.d.ts +42 -3
- package/src/utils/FrameLoop.d.ts.map +1 -1
- package/src/utils/FrameLoop.js +71 -10
- package/src/utils/FrameLoop.js.map +2 -2
- package/src/utils/MicrotaskCollector.d.ts +45 -0
- package/src/utils/MicrotaskCollector.d.ts.map +1 -0
- package/src/utils/MicrotaskCollector.js +33 -0
- package/src/utils/MicrotaskCollector.js.map +7 -0
- package/src/utils/MicrotaskGate.d.ts +17 -0
- package/src/utils/MicrotaskGate.d.ts.map +1 -0
- package/src/utils/MicrotaskGate.js +20 -0
- package/src/utils/MicrotaskGate.js.map +7 -0
- package/src/utils/array-utils.js.map +1 -1
- package/src/utils/attr-utils.d.ts +6 -0
- package/src/utils/attr-utils.d.ts.map +1 -1
- package/src/utils/attr-utils.js +3 -1
- package/src/utils/attr-utils.js.map +2 -2
- package/src/utils/constants.js.map +1 -1
- package/src/utils/generateUUID.d.ts +11 -0
- package/src/utils/generateUUID.d.ts.map +1 -1
- package/src/utils/generateUUID.js +31 -266
- package/src/utils/generateUUID.js.map +2 -2
- package/src/utils/props-utils.d.ts +3 -2
- package/src/utils/props-utils.d.ts.map +1 -1
- package/src/utils/props-utils.js +13 -24
- package/src/utils/props-utils.js.map +2 -2
- package/src/utils/runGuarded.d.ts +27 -0
- package/src/utils/runGuarded.d.ts.map +1 -0
- package/src/utils/runGuarded.js +11 -0
- package/src/utils/runGuarded.js.map +7 -0
- package/src/utils/toMaybe.d.ts.map +1 -1
- package/src/utils/toMaybe.js.map +1 -1
- package/src/utils/toNamespace.d.ts.map +1 -1
- package/src/utils/toNamespace.js.map +1 -1
- package/src/utils/toUrlString.d.ts +12 -0
- package/src/utils/toUrlString.d.ts.map +1 -1
- package/src/utils/toUrlString.js.map +2 -2
- package/src/utils/waitForMessageOfType.d.ts +12 -1
- package/src/utils/waitForMessageOfType.d.ts.map +1 -1
- package/src/utils/waitForMessageOfType.js +16 -1
- package/src/utils/waitForMessageOfType.js.map +2 -2
- package/src/view/ComponentChanges.d.ts +88 -1
- package/src/view/ComponentChanges.d.ts.map +1 -1
- package/src/view/ComponentChanges.js +243 -73
- package/src/view/ComponentChanges.js.map +2 -2
- package/src/view/ComponentContext.d.ts +206 -16
- package/src/view/ComponentContext.d.ts.map +1 -1
- package/src/view/ComponentContext.js +548 -91
- package/src/view/ComponentContext.js.map +2 -2
- package/src/view/ComponentMemory.d.ts +3 -3
- package/src/view/ComponentMemory.d.ts.map +1 -1
- package/src/view/ComponentMemory.js.map +1 -1
- package/src/view/IShadowObjectEnvProxy.d.ts +29 -3
- package/src/view/IShadowObjectEnvProxy.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.d.ts +1 -1
- package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.js +8 -6
- package/src/view/LocalShadowObjectEnv.js.map +2 -2
- package/src/view/RemoteWorkerEnv.d.ts +89 -5
- package/src/view/RemoteWorkerEnv.d.ts.map +1 -1
- package/src/view/RemoteWorkerEnv.js +195 -77
- package/src/view/RemoteWorkerEnv.js.map +2 -2
- package/src/view/ShadowEnv.d.ts +49 -2
- package/src/view/ShadowEnv.d.ts.map +1 -1
- package/src/view/ShadowEnv.js +223 -60
- package/src/view/ShadowEnv.js.map +2 -2
- package/src/view/ViewComponent.d.ts +78 -14
- package/src/view/ViewComponent.d.ts.map +1 -1
- package/src/view/ViewComponent.js +90 -14
- package/src/view/ViewComponent.js.map +2 -2
- package/src/view/cloneChangeTrail.js.map +2 -2
- package/src/worker/MessageRouter.d.ts +14 -0
- package/src/worker/MessageRouter.d.ts.map +1 -1
- package/src/worker/MessageRouter.js +75 -15
- package/src/worker/MessageRouter.js.map +2 -2
- package/src/worker/WorkerRuntime.d.ts +22 -1
- package/src/worker/WorkerRuntime.d.ts.map +1 -1
- package/src/worker/WorkerRuntime.js +60 -8
- package/src/worker/WorkerRuntime.js.map +2 -2
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@spearwolf/shadow-objects",
|
|
3
3
|
"description": "a reactive entity-component framework that feels at home in the shadows",
|
|
4
4
|
"homepage": "https://github.com/spearwolf/shadow-objects/",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.34.0",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Wolfger Schramm",
|
|
8
8
|
"email": "wolfger@spearwolf.de",
|
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
"./ConsoleLogger.js": {
|
|
55
55
|
"import": "./src/utils/ConsoleLogger.js",
|
|
56
56
|
"types": "./src/utils/ConsoleLogger.d.ts"
|
|
57
|
+
},
|
|
58
|
+
"./FrameLoop.js": {
|
|
59
|
+
"import": "./src/utils/FrameLoop.js",
|
|
60
|
+
"types": "./src/utils/FrameLoop.d.ts"
|
|
57
61
|
}
|
|
58
62
|
},
|
|
59
63
|
"sideEffects": [
|
|
@@ -69,7 +73,7 @@
|
|
|
69
73
|
"src/shae-worker.js"
|
|
70
74
|
],
|
|
71
75
|
"dependencies": {
|
|
72
|
-
"@spearwolf/eventize": "^
|
|
73
|
-
"@spearwolf/signalize": "^0.
|
|
76
|
+
"@spearwolf/eventize": "^6.2.0",
|
|
77
|
+
"@spearwolf/signalize": "^1.0.0"
|
|
74
78
|
}
|
|
75
79
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reason a Shadow Environment refuses a change trail it could only apply in part.
|
|
3
|
+
*
|
|
4
|
+
* A change trail is applied entry by entry and the first throw ends the run, so what the Kernel
|
|
5
|
+
* holds afterwards is always a prefix of the trail: the entries in `[0, appliedCount)` are
|
|
6
|
+
* applied, the entry at `appliedCount` is the one that threw, and everything behind it was never
|
|
7
|
+
* attempted. That single number is therefore the whole answer to "how far did it get" — the view
|
|
8
|
+
* side folds the prefix into its bookkeeping and sends the rest again with the next trail.
|
|
9
|
+
*
|
|
10
|
+
* `cause` carries what the entry actually threw. Across a worker boundary that is a
|
|
11
|
+
* `WorkerReportedError` carrying the wording and the name of the throw; the class of the original
|
|
12
|
+
* error and the fields it added do not cross the boundary.
|
|
13
|
+
*
|
|
14
|
+
* A refusal for a reason that says nothing about how far the Kernel got — a confirmation window
|
|
15
|
+
* that ran out, a worker that died, a proxy of someone else's making — is not one of these. The
|
|
16
|
+
* view reads such a reason as "the whole trail may well have been applied", which is the safe
|
|
17
|
+
* direction: a creation the Kernel already holds an entity for is refused, and the same trail
|
|
18
|
+
* comes back to the same refusal for as long as the view keeps sending it.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ChangeTrailRefusedError extends Error {
|
|
21
|
+
/** how many entries of the change trail the Kernel applied before it stopped */
|
|
22
|
+
readonly appliedCount: number;
|
|
23
|
+
/** how many entries the change trail carried */
|
|
24
|
+
readonly entryCount: number;
|
|
25
|
+
constructor(appliedCount: number, entryCount: number, options?: ErrorOptions);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ChangeTrailRefusedError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChangeTrailRefusedError.d.ts","sourceRoot":"","sources":["../../src/ChangeTrailRefusedError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,gFAAgF;IAChF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,gDAAgD;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,YAAY,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAK3E;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class ChangeTrailRefusedError extends Error {
|
|
2
|
+
constructor(appliedCount, entryCount, options) {
|
|
3
|
+
super(`the kernel applied ${appliedCount} of ${entryCount} change trail entries`, options);
|
|
4
|
+
this.name = "ChangeTrailRefusedError";
|
|
5
|
+
this.appliedCount = appliedCount;
|
|
6
|
+
this.entryCount = entryCount;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
ChangeTrailRefusedError
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=ChangeTrailRefusedError.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ChangeTrailRefusedError.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The reason a Shadow Environment refuses a change trail it could only apply in part.\n *\n * A change trail is applied entry by entry and the first throw ends the run, so what the Kernel\n * holds afterwards is always a prefix of the trail: the entries in `[0, appliedCount)` are\n * applied, the entry at `appliedCount` is the one that threw, and everything behind it was never\n * attempted. That single number is therefore the whole answer to \"how far did it get\" \u2014 the view\n * side folds the prefix into its bookkeeping and sends the rest again with the next trail.\n *\n * `cause` carries what the entry actually threw. Across a worker boundary that is a\n * `WorkerReportedError` carrying the wording and the name of the throw; the class of the original\n * error and the fields it added do not cross the boundary.\n *\n * A refusal for a reason that says nothing about how far the Kernel got \u2014 a confirmation window\n * that ran out, a worker that died, a proxy of someone else's making \u2014 is not one of these. The\n * view reads such a reason as \"the whole trail may well have been applied\", which is the safe\n * direction: a creation the Kernel already holds an entity for is refused, and the same trail\n * comes back to the same refusal for as long as the view keeps sending it.\n */\nexport class ChangeTrailRefusedError extends Error {\n /** how many entries of the change trail the Kernel applied before it stopped */\n readonly appliedCount: number;\n\n /** how many entries the change trail carried */\n readonly entryCount: number;\n\n constructor(appliedCount: number, entryCount: number, options?: ErrorOptions) {\n super(`the kernel applied ${appliedCount} of ${entryCount} change trail entries`, options);\n this.name = 'ChangeTrailRefusedError';\n this.appliedCount = appliedCount;\n this.entryCount = entryCount;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAmBO,MAAM,gCAAgC,MAAM;AAAA,EAOjD,YAAY,cAAsB,YAAoB,SAAwB;AAC5E,UAAM,sBAAsB,YAAY,OAAO,UAAU,yBAAyB,OAAO;AACzF,SAAK,OAAO;AACZ,SAAK,eAAe;AACpB,SAAK,aAAa;AAAA,EACpB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the Kernel is asked to create an entity under a uuid it already holds an entity for.
|
|
3
|
+
*
|
|
4
|
+
* A uuid names one entity at a time. The entity behind it keeps its shadow objects, its signals,
|
|
5
|
+
* its contexts, its token and its properties; the creation that was refused leaves nothing of
|
|
6
|
+
* itself anywhere, because the guard stands ahead of every write it would make.
|
|
7
|
+
*
|
|
8
|
+
* The uuid is free again once `Kernel.destroyEntity()` has been through: whoever wants an entity
|
|
9
|
+
* built anew under the same uuid destroys the one that stands first.
|
|
10
|
+
*
|
|
11
|
+
* In a change trail this is the reason underneath a `ChangeTrailRefusedError`: the trail is
|
|
12
|
+
* refused at that entry, and `appliedCount` names the prefix the Kernel did apply.
|
|
13
|
+
*/
|
|
14
|
+
export declare class EntityUuidInUseError extends Error {
|
|
15
|
+
/** the uuid the kernel already holds an entity for */
|
|
16
|
+
readonly uuid: string;
|
|
17
|
+
constructor(uuid: string);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=EntityUuidInUseError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityUuidInUseError.d.ts","sourceRoot":"","sources":["../../src/EntityUuidInUseError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,IAAI,EAAE,MAAM,EAIvB;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class EntityUuidInUseError extends Error {
|
|
2
|
+
constructor(uuid) {
|
|
3
|
+
super(`the kernel cannot create an entity because the uuid ${uuid} is already held by another entity`);
|
|
4
|
+
this.name = "EntityUuidInUseError";
|
|
5
|
+
this.uuid = uuid;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
EntityUuidInUseError
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=EntityUuidInUseError.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/EntityUuidInUseError.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Thrown when the Kernel is asked to create an entity under a uuid it already holds an entity for.\n *\n * A uuid names one entity at a time. The entity behind it keeps its shadow objects, its signals,\n * its contexts, its token and its properties; the creation that was refused leaves nothing of\n * itself anywhere, because the guard stands ahead of every write it would make.\n *\n * The uuid is free again once `Kernel.destroyEntity()` has been through: whoever wants an entity\n * built anew under the same uuid destroys the one that stands first.\n *\n * In a change trail this is the reason underneath a `ChangeTrailRefusedError`: the trail is\n * refused at that entry, and `appliedCount` names the prefix the Kernel did apply.\n */\nexport class EntityUuidInUseError extends Error {\n /** the uuid the kernel already holds an entity for */\n readonly uuid: string;\n\n constructor(uuid: string) {\n super(`the kernel cannot create an entity because the uuid ${uuid} is already held by another entity`);\n this.name = 'EntityUuidInUseError';\n this.uuid = uuid;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAaO,MAAM,6BAA6B,MAAM;AAAA,EAI9C,YAAY,MAAc;AACxB,UAAM,uDAAuD,IAAI,oCAAoC;AACrG,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WorkerReplyType } from './constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* The reason a reply from the worker did not arrive in time.
|
|
4
|
+
*
|
|
5
|
+
* Four replies of a `RemoteWorkerEnv` have a deadline, and `messageType` names the one that stayed
|
|
6
|
+
* out: the `Loaded` greeting of the load handshake, the `ImportedModule` answer to an
|
|
7
|
+
* `importScript()`, the `AppliedChangeTrail` confirmation of a change trail sent with
|
|
8
|
+
* `waitForConfirmation`, and the `Destroyed` receipt of a teardown.
|
|
9
|
+
*
|
|
10
|
+
* `timeout` carries the number of milliseconds that were waited, so a diagnosis knows which of the
|
|
11
|
+
* four values was in force without reaching for the `timeouts` of the `RemoteWorkerEnv`.
|
|
12
|
+
*
|
|
13
|
+
* The error says nothing about what the worker did with the request. A confirmation window that
|
|
14
|
+
* ran out leaves a Shadow Environment that may well have applied the whole change trail, which is
|
|
15
|
+
* why `ShadowEnv` books it as applied; `ChangeTrailRefusedError` is the only refusal that names a
|
|
16
|
+
* number.
|
|
17
|
+
*/
|
|
18
|
+
export declare class WorkerTimeoutError extends Error {
|
|
19
|
+
/** the type of the message that did not arrive */
|
|
20
|
+
readonly messageType: WorkerReplyType;
|
|
21
|
+
/** how many milliseconds were waited for it */
|
|
22
|
+
readonly timeout: number;
|
|
23
|
+
constructor(messageType: WorkerReplyType, timeout: number);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=WorkerTimeoutError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkerTimeoutError.d.ts","sourceRoot":"","sources":["../../src/WorkerTimeoutError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,kDAAkD;IAClD,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;IAEtC,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,YAAY,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAKxD;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class WorkerTimeoutError extends Error {
|
|
2
|
+
constructor(messageType, timeout) {
|
|
3
|
+
super(`no ${messageType} message arrived from the worker within ${timeout}ms`);
|
|
4
|
+
this.name = "WorkerTimeoutError";
|
|
5
|
+
this.messageType = messageType;
|
|
6
|
+
this.timeout = timeout;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
WorkerTimeoutError
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=WorkerTimeoutError.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/WorkerTimeoutError.ts"],
|
|
4
|
+
"sourcesContent": ["import type {WorkerReplyType} from './constants.js';\n\n/**\n * The reason a reply from the worker did not arrive in time.\n *\n * Four replies of a `RemoteWorkerEnv` have a deadline, and `messageType` names the one that stayed\n * out: the `Loaded` greeting of the load handshake, the `ImportedModule` answer to an\n * `importScript()`, the `AppliedChangeTrail` confirmation of a change trail sent with\n * `waitForConfirmation`, and the `Destroyed` receipt of a teardown.\n *\n * `timeout` carries the number of milliseconds that were waited, so a diagnosis knows which of the\n * four values was in force without reaching for the `timeouts` of the `RemoteWorkerEnv`.\n *\n * The error says nothing about what the worker did with the request. A confirmation window that\n * ran out leaves a Shadow Environment that may well have applied the whole change trail, which is\n * why `ShadowEnv` books it as applied; `ChangeTrailRefusedError` is the only refusal that names a\n * number.\n */\nexport class WorkerTimeoutError extends Error {\n /** the type of the message that did not arrive */\n readonly messageType: WorkerReplyType;\n\n /** how many milliseconds were waited for it */\n readonly timeout: number;\n\n constructor(messageType: WorkerReplyType, timeout: number) {\n super(`no ${messageType} message arrived from the worker within ${timeout}ms`);\n this.name = 'WorkerTimeoutError';\n this.messageType = messageType;\n this.timeout = timeout;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAkBO,MAAM,2BAA2B,MAAM;AAAA,EAO5C,YAAY,aAA8B,SAAiB;AACzD,UAAM,MAAM,WAAW,2CAA2C,OAAO,IAAI;AAC7E,SAAK,OAAO;AACZ,SAAK,cAAc;AACnB,SAAK,UAAU;AAAA,EACjB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/bundle.d.ts
CHANGED
package/src/bundle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,gBAAgB,CAAC;AACxB,OAAO,kBAAkB,CAAC;AAE1B,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,gBAAgB,CAAC;AACxB,OAAO,kBAAkB,CAAC;AAE1B,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,4BAA4B,EAAE,OAAO,CAAC;CAC3C"}
|
package/src/bundle.js
CHANGED
package/src/bundle.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/bundle.ts"],
|
|
4
|
-
"sourcesContent": ["import './shae-ent.js';\nimport './shae-prop.js';\nimport './shae-worker.js';\n\ndeclare global {\n
|
|
5
|
-
"mappings": "AAAA,OAAO;AACP,OAAO;AACP,OAAO;
|
|
4
|
+
"sourcesContent": ["import './shae-ent.js';\nimport './shae-prop.js';\nimport './shae-worker.js';\n\ndeclare global {\n var SHADOW_OBJECTS_BUNDLE_LOADED: boolean;\n}\n\nglobalThis.SHADOW_OBJECTS_BUNDLE_LOADED = true;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO;AACP,OAAO;AACP,OAAO;AAMP,WAAW,+BAA+B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NamespaceType } from './types.
|
|
1
|
+
import type { NamespaceType } from './types.js';
|
|
2
2
|
export declare enum ChangeTrailPhase {
|
|
3
3
|
StructuralChanges = 1,
|
|
4
4
|
ContentUpdates = 2,
|
|
@@ -16,7 +16,7 @@ export declare enum ComponentChangeType {
|
|
|
16
16
|
export declare const GlobalNS: NamespaceType;
|
|
17
17
|
export declare const VoidToken = "#void";
|
|
18
18
|
/**
|
|
19
|
-
* The event is dispatched by
|
|
19
|
+
* The event is dispatched by `ComponentContext.reCreateChanges` and forwarded to all `ViewComponent`.
|
|
20
20
|
* The event itself has no other data.
|
|
21
21
|
*/
|
|
22
22
|
export declare const ContextLost = "contextLost";
|
|
@@ -27,6 +27,13 @@ export declare const Loaded = "loaded";
|
|
|
27
27
|
export declare const AppliedChangeTrail = "appliedChangeTrail";
|
|
28
28
|
export declare const ImportedModule = "importedModule";
|
|
29
29
|
export declare const Destroyed = "destroyed";
|
|
30
|
+
/**
|
|
31
|
+
* The four replies a `RemoteWorkerEnv` waits for, each behind a deadline of its own: the `Loaded`
|
|
32
|
+
* greeting of the load handshake, the `ImportedModule` answer to an `importScript()`, the
|
|
33
|
+
* `AppliedChangeTrail` confirmation of a change trail sent with `waitForConfirmation`, and the
|
|
34
|
+
* `Destroyed` receipt of a teardown. A `switch` over the four is exhaustive.
|
|
35
|
+
*/
|
|
36
|
+
export type WorkerReplyType = typeof Loaded | typeof AppliedChangeTrail | typeof ImportedModule | typeof Destroyed;
|
|
30
37
|
/**
|
|
31
38
|
* The `messageToView` event is fired when the kernel receives a message from an entity (to its view component counterpart)
|
|
32
39
|
*/
|
package/src/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAE9C,oBAAY,gBAAgB;IAC1B,iBAAiB,IAAI;IACrB,cAAc,IAAA;IACd,OAAO,IAAA;CACR;AAED,oBAAY,mBAAmB;IAC7B,cAAc,IAAI;IAClB,eAAe,IAAA;IACf,SAAS,IAAA;IACT,WAAW,IAAA;IACX,gBAAgB,IAAA;IAChB,WAAW,IAAA;IACX,UAAU,IAAA;CACX;AAED,eAAO,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAE9C,oBAAY,gBAAgB;IAC1B,iBAAiB,IAAI;IACrB,cAAc,IAAA;IACd,OAAO,IAAA;CACR;AAED,oBAAY,mBAAmB;IAC7B,cAAc,IAAI;IAClB,eAAe,IAAA;IACf,SAAS,IAAA;IACT,WAAW,IAAA;IACX,gBAAgB,IAAA;IAChB,WAAW,IAAA;IACX,UAAU,IAAA;CACX;AAED,eAAO,MAAM,QAAQ,EAAE,aAAmD,CAAC;AAE3E,eAAO,MAAM,SAAS,UAAU,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,eAAO,MAAM,SAAS,cAAc,CAAC;AACrC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,OAAO,YAAY,CAAC;AAEjC,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C,eAAO,MAAM,SAAS,cAAc,CAAC;AAErC;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,MAAM,GAAG,OAAO,kBAAkB,GAAG,OAAO,cAAc,GAAG,OAAO,SAAS,CAAC;AAEnH;;GAEG;AACH,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AACvC,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAC7C,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC,eAAO,MAAM,mBAAmB,kBAAkB,CAAC"}
|
package/src/constants.js
CHANGED
|
@@ -14,7 +14,7 @@ var ComponentChangeType = /* @__PURE__ */ ((ComponentChangeType2) => {
|
|
|
14
14
|
ComponentChangeType2[ComponentChangeType2["SendEvents"] = 7] = "SendEvents";
|
|
15
15
|
return ComponentChangeType2;
|
|
16
16
|
})(ComponentChangeType || {});
|
|
17
|
-
const GlobalNS = /* @__PURE__ */ Symbol.for("
|
|
17
|
+
const GlobalNS = /* @__PURE__ */ Symbol.for("ShadowObjectsGlobalNS");
|
|
18
18
|
const VoidToken = "#void";
|
|
19
19
|
const ContextLost = "contextLost";
|
|
20
20
|
const Configure = "configure";
|
package/src/constants.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/constants.ts"],
|
|
4
|
-
"sourcesContent": ["import type {NamespaceType} from './types.
|
|
5
|
-
"mappings": "AAEO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,oCAAA,uBAAoB,KAApB;AACA,EAAAA,oCAAA;AACA,EAAAA,oCAAA;AAHU,SAAAA;AAAA,GAAA;AAML,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,0CAAA,oBAAiB,KAAjB;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AAPU,SAAAA;AAAA,GAAA;AAUL,MAAM,WAA0B,uBAAO,IAAI,
|
|
4
|
+
"sourcesContent": ["import type {NamespaceType} from './types.js';\n\nexport enum ChangeTrailPhase {\n StructuralChanges = 1,\n ContentUpdates,\n Removal,\n}\n\nexport enum ComponentChangeType {\n CreateEntities = 1,\n DestroyEntities,\n SetParent,\n UpdateOrder,\n ChangeProperties,\n ChangeToken,\n SendEvents,\n}\n\nexport const GlobalNS: NamespaceType = Symbol.for('ShadowObjectsGlobalNS');\n\nexport const VoidToken = '#void';\n\n/**\n * The event is dispatched by `ComponentContext.reCreateChanges` and forwarded to all `ViewComponent`.\n * The event itself has no other data.\n */\nexport const ContextLost = 'contextLost';\n\nexport const Configure = 'configure';\nexport const ChangeTrail = 'changeTrail';\nexport const Destroy = 'destroy';\n\nexport const Loaded = 'loaded';\nexport const AppliedChangeTrail = 'appliedChangeTrail';\nexport const ImportedModule = 'importedModule';\nexport const Destroyed = 'destroyed';\n\n/**\n * The four replies a `RemoteWorkerEnv` waits for, each behind a deadline of its own: the `Loaded`\n * greeting of the load handshake, the `ImportedModule` answer to an `importScript()`, the\n * `AppliedChangeTrail` confirmation of a change trail sent with `waitForConfirmation`, and the\n * `Destroyed` receipt of a teardown. A `switch` over the four is exhaustive.\n */\nexport type WorkerReplyType = typeof Loaded | typeof AppliedChangeTrail | typeof ImportedModule | typeof Destroyed;\n\n/**\n * The `messageToView` event is fired when the kernel receives a message from an entity (to its view component counterpart)\n */\nexport const MessageToView = 'messageToView';\n\nexport const WorkerLoadTimeout = 60000;\nexport const WorkerConfigureTimeout = 60000;\nexport const WorkerChangeTrailTimeout = 5000;\nexport const WorkerDestroyTimeout = 5000;\n\nexport const ShadowObjectsExport = 'shadowObjects';\n"],
|
|
5
|
+
"mappings": "AAEO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,oCAAA,uBAAoB,KAApB;AACA,EAAAA,oCAAA;AACA,EAAAA,oCAAA;AAHU,SAAAA;AAAA,GAAA;AAML,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,0CAAA,oBAAiB,KAAjB;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AAPU,SAAAA;AAAA,GAAA;AAUL,MAAM,WAA0B,uBAAO,IAAI,uBAAuB;AAElE,MAAM,YAAY;AAMlB,MAAM,cAAc;AAEpB,MAAM,YAAY;AAClB,MAAM,cAAc;AACpB,MAAM,UAAU;AAEhB,MAAM,SAAS;AACf,MAAM,qBAAqB;AAC3B,MAAM,iBAAiB;AACvB,MAAM,YAAY;AAalB,MAAM,gBAAgB;AAEtB,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,2BAA2B;AACjC,MAAM,uBAAuB;AAE7B,MAAM,sBAAsB;",
|
|
6
6
|
"names": ["ChangeTrailPhase", "ComponentChangeType"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-worker.bundle.d.ts","sourceRoot":"","sources":["../../src/create-worker.bundle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-worker.bundle.d.ts","sourceRoot":"","sources":["../../src/create-worker.bundle.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/create-worker.bundle.ts"],
|
|
4
|
-
"sourcesContent": ["// @ts-ignore\nimport Worker from './bundle.worker.js';\n\n// This module is converted to __inline__ worker code using the esbuild-plugin-inline-worker plugin.\n// It is done in the `bundle.mjs` build script.\n//\n// `worker/WorkerRuntime.ts` => `shadow-objects.worker.js` => `bundle.worker.js`\n\nexport default () => new Worker()
|
|
4
|
+
"sourcesContent": ["// @ts-ignore\nimport Worker from './bundle.worker.js';\n\n// This module is converted to __inline__ worker code using the esbuild-plugin-inline-worker plugin.\n// It is done in the `bundle.mjs` build script.\n//\n// `worker/WorkerRuntime.ts` => `shadow-objects.worker.js` => `bundle.worker.js`\n\nexport default () => new Worker();\n"],
|
|
5
5
|
"mappings": "AACA,OAAO,YAAY;AAOnB,IAAO,+BAAQ,MAAM,IAAI,OAAO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/create-worker.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-worker.d.ts","sourceRoot":"","sources":["../../src/create-worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-worker.d.ts","sourceRoot":"","sources":["../../src/create-worker.ts"],"names":[],"mappings":""}
|
package/src/create-worker.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/create-worker.ts"],
|
|
4
|
-
"sourcesContent": ["export default () => new Worker(new URL('./shadow-objects.worker.js', import.meta.url), {type: 'module'})
|
|
4
|
+
"sourcesContent": ["export default () => new Worker(new URL('./shadow-objects.worker.js', import.meta.url), {type: 'module'});\n"],
|
|
5
5
|
"mappings": "AAAA,IAAO,wBAAQ,MAAM,IAAI,OAAO,IAAI,IAAI,8BAA8B,YAAY,GAAG,GAAG,EAAC,MAAM,SAAQ,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,81 @@
|
|
|
1
1
|
import { Signal } from '@spearwolf/signalize';
|
|
2
|
-
import type { NamespaceType } from '../types.
|
|
3
|
-
|
|
2
|
+
import type { NamespaceType } from '../types.js';
|
|
3
|
+
import { ShaeLifecycleElement } from './ShaeLifecycleElement.js';
|
|
4
|
+
/**
|
|
5
|
+
* The base of the custom elements that pick an environment through their `ns` attribute.
|
|
6
|
+
*
|
|
7
|
+
* What it adds to {@link ShaeLifecycleElement} is the namespace: the `ns` attribute, the signal
|
|
8
|
+
* behind it, the reflection back onto the attribute, and the two ways to hand an environment on to
|
|
9
|
+
* the next sync. When such an element starts listening and when it lets go is the base's answer,
|
|
10
|
+
* and it is the same answer `<shae-prop>` gets, which shares that base without this layer.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ShaeElement extends ShaeLifecycleElement {
|
|
13
|
+
#private;
|
|
4
14
|
static observedAttributes: string[];
|
|
5
15
|
readonly isShaeElement = true;
|
|
6
16
|
readonly ns$: Signal<NamespaceType>;
|
|
7
17
|
get ns(): NamespaceType;
|
|
8
18
|
set ns(ns: NamespaceType);
|
|
9
19
|
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Take the namespace subscription up, and catch up on what changed while nothing was listening.
|
|
22
|
+
* The namespace half of {@link ShaeLifecycleElement.restore}.
|
|
23
|
+
*
|
|
24
|
+
* The catch-up is the half that is easy to leave out and expensive to miss. A released element
|
|
25
|
+
* still takes writes — the signals are alive — but nothing carries them onto the attributes, so
|
|
26
|
+
* the two drift apart. Writing the signal's value back here settles that before anything reads an
|
|
27
|
+
* attribute again: without it, the attribute read on the way in would push the *old* value back
|
|
28
|
+
* into the signal and the write would be lost without a word. At the first connect the same
|
|
29
|
+
* write is what carries the normalisation of the constructor's attribute read onto the attribute.
|
|
30
|
+
*/
|
|
31
|
+
protected restore(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Writes an attribute back from a signal, or holds the write until the element first connects.
|
|
34
|
+
*
|
|
35
|
+
* A write is parked whenever it happens before the element has connected once — `restore()`'s
|
|
36
|
+
* own writes on the very first connect are one source, carrying every reflecting signal out to
|
|
37
|
+
* its attribute, including whatever the constructor's attribute read normalised; any other
|
|
38
|
+
* write that lands ahead of that first connect is parked the same way. `restore()`'s call sits
|
|
39
|
+
* in front of the gate on purpose: a `setAttribute` from inside it would re-enter
|
|
40
|
+
* `attributeChangedCallback` while the subscriptions are still being set up, and running the
|
|
41
|
+
* writes a few lines further on, once the element is whole, is cheaper than making every
|
|
42
|
+
* subscription survive being read halfway through. A later write for the same attribute
|
|
43
|
+
* replaces the parked one — only the value the signal ends up with is worth writing.
|
|
44
|
+
*
|
|
45
|
+
* What is written back on connect is what the signals already carry, so the
|
|
46
|
+
* `attributeChangedCallback` it triggers sets each signal to the value it is already on. For a
|
|
47
|
+
* signal holding a scalar that is no change and reaches no handler at all; for one holding a
|
|
48
|
+
* fresh object on every read — `forward-custom-events` builds a new `Set` per read — the write
|
|
49
|
+
* counts as a change by identity and the reflecting handler runs once more, where the guard on
|
|
50
|
+
* the attribute value it already wrote stops the second write. Either way the attribute ends up
|
|
51
|
+
* on the value the signal carries.
|
|
52
|
+
*/
|
|
53
|
+
protected reflectAttribute(name: string, write: () => void): void;
|
|
54
|
+
connectedCallback(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Release the namespace reflection. The namespace half of {@link ShaeLifecycleElement.teardown}.
|
|
57
|
+
*
|
|
58
|
+
* `#pendingReflections` is left alone on purpose: it holds every write parked before the
|
|
59
|
+
* element's first connect, and that connect is what drains it — a `destroy()` reached first
|
|
60
|
+
* leaves the map standing for whichever connect comes next.
|
|
61
|
+
*/
|
|
62
|
+
protected teardown(): void;
|
|
10
63
|
attributeChangedCallback(name: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Hand the environment of this element's namespace on to the next `sync()` — the unconfirmed
|
|
66
|
+
* path.
|
|
67
|
+
*
|
|
68
|
+
* Over a worker it learns nothing of a confirmation the Shadow Environment refused, and no
|
|
69
|
+
* `syncfailed` event follows. Whoever needs to know switches `auto-sync` off and runs
|
|
70
|
+
* `syncWait()` from their own loop.
|
|
71
|
+
*/
|
|
11
72
|
syncShadowObjects(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Sync the environment of `ns` instead of the one this element sits in right now.
|
|
75
|
+
*
|
|
76
|
+
* For the moment an element changes namespaces: the environment it leaves has a change trail
|
|
77
|
+
* waiting for it, and `this.ns` no longer points at it.
|
|
78
|
+
*/
|
|
79
|
+
protected syncShadowObjectsOf(ns: NamespaceType): void;
|
|
12
80
|
}
|
|
13
81
|
//# sourceMappingURL=ShaeElement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShaeElement.d.ts","sourceRoot":"","sources":["../../../src/elements/ShaeElement.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ShaeElement.d.ts","sourceRoot":"","sources":["../../../src/elements/ShaeElement.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAErE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAQ/C,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AA0B/D;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,oBAAoB;;IACnD,MAAM,CAAC,kBAAkB,WAAa;IAEtC,QAAQ,CAAC,aAAa,QAAQ;IAE9B,QAAQ,CAAC,GAAG,wBAAyC;IAErD,IAAI,EAAE,IAAI,aAAa,CAEtB;IAED,IAAI,EAAE,CAAC,EAAE,EAAE,aAAa,EAMvB;IAWD,cAQC;IAyBD;;;;;;;;;;OAUG;IACH,UAAmB,OAAO,IAAI,IAAI,CAKjC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,IAAI,GAAG,IAAI,CAOhE;IAEQ,iBAAiB,SAwBzB;IAED;;;;;;OAMG;IACH,UAAmB,QAAQ,IAAI,IAAI,CAKlC;IAED,wBAAwB,CAAC,IAAI,EAAE,MAAM,QAIpC;IAED;;;;;;;OAOG;IACH,iBAAiB,SAEhB;IAED;;;;;OAKG;IACH,SAAS,CAAC,mBAAmB,CAAC,EAAE,EAAE,aAAa,QAE9C;CACF"}
|
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
import { createSignal, Signal } from "@spearwolf/signalize";
|
|
1
|
+
import { createSignal, hibernate, Signal } from "@spearwolf/signalize";
|
|
2
2
|
import { GlobalNS } from "../constants.js";
|
|
3
3
|
import { readNamespaceAttribute } from "../utils/attr-utils.js";
|
|
4
|
+
import { ConsoleLogger } from "../utils/ConsoleLogger.js";
|
|
5
|
+
import { MicrotaskCollector } from "../utils/MicrotaskCollector.js";
|
|
6
|
+
import { runGuarded } from "../utils/runGuarded.js";
|
|
4
7
|
import { toNamespace } from "../utils/toNamespace.js";
|
|
5
8
|
import { ShadowEnv } from "../view/ShadowEnv.js";
|
|
6
9
|
import { ATTR_NS } from "./constants.js";
|
|
10
|
+
import { ShaeLifecycleElement } from "./ShaeLifecycleElement.js";
|
|
7
11
|
const updateNamespace = (el, ns) => {
|
|
8
12
|
ns.set(readNamespaceAttribute(el));
|
|
9
13
|
};
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
if (!nextSyncIsScheduled) {
|
|
15
|
-
nextSyncIsScheduled = true;
|
|
16
|
-
queueMicrotask(() => {
|
|
17
|
-
nextSyncIsScheduled = false;
|
|
18
|
-
for (const ns2 of SyncNamespaces) {
|
|
19
|
-
ShadowEnv.get(ns2)?.sync();
|
|
20
|
-
}
|
|
21
|
-
SyncNamespaces.clear();
|
|
22
|
-
});
|
|
14
|
+
const logger = new ConsoleLogger("ShaeElement");
|
|
15
|
+
const syncCollector = new MicrotaskCollector((namespaces) => {
|
|
16
|
+
for (const ns of namespaces.keys()) {
|
|
17
|
+
runGuarded(logger, () => ShadowEnv.get(ns)?.sync(), "a namespace could not be synced:", ns);
|
|
23
18
|
}
|
|
19
|
+
});
|
|
20
|
+
const collectForSync = (ns) => {
|
|
21
|
+
syncCollector.add(ns);
|
|
24
22
|
};
|
|
25
|
-
class ShaeElement extends
|
|
23
|
+
class ShaeElement extends ShaeLifecycleElement {
|
|
26
24
|
constructor() {
|
|
27
25
|
super();
|
|
28
26
|
this.isShaeElement = true;
|
|
29
27
|
this.ns$ = createSignal(GlobalNS);
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
if (this.getAttribute(ATTR_NS) !== ns) {
|
|
33
|
-
this.setAttribute(ATTR_NS, ns);
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
this.removeAttribute(ATTR_NS);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
28
|
+
/** Whether this element has been in a tree at least once. */
|
|
29
|
+
this.#wasConnected = false;
|
|
39
30
|
updateNamespace(this, this.ns$);
|
|
40
31
|
}
|
|
41
32
|
static {
|
|
@@ -51,13 +42,126 @@ class ShaeElement extends HTMLElement {
|
|
|
51
42
|
this.ns$.set(toNamespace(ns));
|
|
52
43
|
}
|
|
53
44
|
}
|
|
45
|
+
#wasConnected;
|
|
46
|
+
/** Attribute writes that came in before the first connect, the latest one per attribute. */
|
|
47
|
+
#pendingReflections;
|
|
48
|
+
/** Takes the namespace reflection off again. */
|
|
49
|
+
#nsReflection;
|
|
50
|
+
/**
|
|
51
|
+
* Take up everything this element listens to.
|
|
52
|
+
*
|
|
53
|
+
* Private rather than overridable, and called from {@link ShaeElement.restore} alone: a subclass
|
|
54
|
+
* extends the pair `restore()`/`teardown()`, which is where its own signals are there to be
|
|
55
|
+
* subscribed to.
|
|
56
|
+
*/
|
|
57
|
+
#subscribe() {
|
|
58
|
+
this.#nsReflection = this.ns$.onChange((ns) => this.#reflectNamespace(ns));
|
|
59
|
+
}
|
|
60
|
+
#reflectNamespace(ns) {
|
|
61
|
+
this.reflectAttribute(ATTR_NS, () => {
|
|
62
|
+
if (typeof ns === "string" && ns.length > 0) {
|
|
63
|
+
if (this.getAttribute(ATTR_NS) !== ns) {
|
|
64
|
+
this.setAttribute(ATTR_NS, ns);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
this.removeAttribute(ATTR_NS);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Take the namespace subscription up, and catch up on what changed while nothing was listening.
|
|
73
|
+
* The namespace half of {@link ShaeLifecycleElement.restore}.
|
|
74
|
+
*
|
|
75
|
+
* The catch-up is the half that is easy to leave out and expensive to miss. A released element
|
|
76
|
+
* still takes writes — the signals are alive — but nothing carries them onto the attributes, so
|
|
77
|
+
* the two drift apart. Writing the signal's value back here settles that before anything reads an
|
|
78
|
+
* attribute again: without it, the attribute read on the way in would push the *old* value back
|
|
79
|
+
* into the signal and the write would be lost without a word. At the first connect the same
|
|
80
|
+
* write is what carries the normalisation of the constructor's attribute read onto the attribute.
|
|
81
|
+
*/
|
|
82
|
+
restore() {
|
|
83
|
+
super.restore();
|
|
84
|
+
this.#subscribe();
|
|
85
|
+
this.#reflectNamespace(this.ns$.value);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Writes an attribute back from a signal, or holds the write until the element first connects.
|
|
89
|
+
*
|
|
90
|
+
* A write is parked whenever it happens before the element has connected once — `restore()`'s
|
|
91
|
+
* own writes on the very first connect are one source, carrying every reflecting signal out to
|
|
92
|
+
* its attribute, including whatever the constructor's attribute read normalised; any other
|
|
93
|
+
* write that lands ahead of that first connect is parked the same way. `restore()`'s call sits
|
|
94
|
+
* in front of the gate on purpose: a `setAttribute` from inside it would re-enter
|
|
95
|
+
* `attributeChangedCallback` while the subscriptions are still being set up, and running the
|
|
96
|
+
* writes a few lines further on, once the element is whole, is cheaper than making every
|
|
97
|
+
* subscription survive being read halfway through. A later write for the same attribute
|
|
98
|
+
* replaces the parked one — only the value the signal ends up with is worth writing.
|
|
99
|
+
*
|
|
100
|
+
* What is written back on connect is what the signals already carry, so the
|
|
101
|
+
* `attributeChangedCallback` it triggers sets each signal to the value it is already on. For a
|
|
102
|
+
* signal holding a scalar that is no change and reaches no handler at all; for one holding a
|
|
103
|
+
* fresh object on every read — `forward-custom-events` builds a new `Set` per read — the write
|
|
104
|
+
* counts as a change by identity and the reflecting handler runs once more, where the guard on
|
|
105
|
+
* the attribute value it already wrote stops the second write. Either way the attribute ends up
|
|
106
|
+
* on the value the signal carries.
|
|
107
|
+
*/
|
|
108
|
+
reflectAttribute(name, write) {
|
|
109
|
+
if (this.#wasConnected) {
|
|
110
|
+
write();
|
|
111
|
+
} else {
|
|
112
|
+
this.#pendingReflections ??= /* @__PURE__ */ new Map();
|
|
113
|
+
this.#pendingReflections.set(name, write);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
connectedCallback() {
|
|
117
|
+
hibernate(() => {
|
|
118
|
+
super.connectedCallback();
|
|
119
|
+
this.#wasConnected = true;
|
|
120
|
+
const pending = this.#pendingReflections;
|
|
121
|
+
this.#pendingReflections = void 0;
|
|
122
|
+
if (pending) {
|
|
123
|
+
for (const write of pending.values()) {
|
|
124
|
+
write();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Release the namespace reflection. The namespace half of {@link ShaeLifecycleElement.teardown}.
|
|
131
|
+
*
|
|
132
|
+
* `#pendingReflections` is left alone on purpose: it holds every write parked before the
|
|
133
|
+
* element's first connect, and that connect is what drains it — a `destroy()` reached first
|
|
134
|
+
* leaves the map standing for whichever connect comes next.
|
|
135
|
+
*/
|
|
136
|
+
teardown() {
|
|
137
|
+
this.#nsReflection?.();
|
|
138
|
+
this.#nsReflection = void 0;
|
|
139
|
+
super.teardown();
|
|
140
|
+
}
|
|
54
141
|
attributeChangedCallback(name) {
|
|
55
142
|
if (name === ATTR_NS) {
|
|
56
143
|
updateNamespace(this, this.ns$);
|
|
57
144
|
}
|
|
58
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Hand the environment of this element's namespace on to the next `sync()` — the unconfirmed
|
|
148
|
+
* path.
|
|
149
|
+
*
|
|
150
|
+
* Over a worker it learns nothing of a confirmation the Shadow Environment refused, and no
|
|
151
|
+
* `syncfailed` event follows. Whoever needs to know switches `auto-sync` off and runs
|
|
152
|
+
* `syncWait()` from their own loop.
|
|
153
|
+
*/
|
|
59
154
|
syncShadowObjects() {
|
|
60
|
-
|
|
155
|
+
collectForSync(this.ns);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Sync the environment of `ns` instead of the one this element sits in right now.
|
|
159
|
+
*
|
|
160
|
+
* For the moment an element changes namespaces: the environment it leaves has a change trail
|
|
161
|
+
* waiting for it, and `this.ns` no longer points at it.
|
|
162
|
+
*/
|
|
163
|
+
syncShadowObjectsOf(ns) {
|
|
164
|
+
collectForSync(ns);
|
|
61
165
|
}
|
|
62
166
|
}
|
|
63
167
|
export {
|