effectable 0.1.0 → 1.0.0-canary.2
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 +22 -4
- package/build/bootstrap/bootstrap.d.ts.map +1 -1
- package/build/bootstrap/bootstrap.js +12 -6
- package/build/bootstrap/bootstrap.js.map +1 -1
- package/build/bootstrap/types.d.ts +7 -1
- package/build/bootstrap/types.d.ts.map +1 -1
- package/build/component/GraphRuntime.d.ts +226 -18
- package/build/component/GraphRuntime.d.ts.map +1 -1
- package/build/component/GraphRuntime.js +944 -211
- package/build/component/GraphRuntime.js.map +1 -1
- package/build/component/context.d.ts +3 -11
- package/build/component/context.d.ts.map +1 -1
- package/build/component/context.js +24 -23
- package/build/component/context.js.map +1 -1
- package/build/component/h.d.ts +14 -6
- package/build/component/h.d.ts.map +1 -1
- package/build/component/h.js +19 -1
- package/build/component/h.js.map +1 -1
- package/build/component/refs.d.ts +7 -5
- package/build/component/refs.d.ts.map +1 -1
- package/build/component/refs.js +45 -22
- package/build/component/refs.js.map +1 -1
- package/build/component/types.d.ts +16 -5
- package/build/component/types.d.ts.map +1 -1
- package/build/component/types.js.map +1 -1
- package/build/connect/connect.d.ts.map +1 -1
- package/build/connect/connect.js +3 -12
- package/build/connect/connect.js.map +1 -1
- package/build/connect/types.d.ts +2 -2
- package/build/connect/types.d.ts.map +1 -1
- package/build/runtime/BusDecorators.d.ts +6 -0
- package/build/runtime/BusDecorators.d.ts.map +1 -1
- package/build/runtime/BusDecorators.js +117 -56
- package/build/runtime/BusDecorators.js.map +1 -1
- package/build/runtime/CommandBus.d.ts +1 -1
- package/build/runtime/CommandBus.d.ts.map +1 -1
- package/build/runtime/CommandBus.js +6 -3
- package/build/runtime/CommandBus.js.map +1 -1
- package/build/runtime/HandleRegistry.d.ts +2 -1
- package/build/runtime/HandleRegistry.d.ts.map +1 -1
- package/build/runtime/HandleRegistry.js +38 -7
- package/build/runtime/HandleRegistry.js.map +1 -1
- package/build/runtime/QueryBus.d.ts +1 -1
- package/build/runtime/QueryBus.d.ts.map +1 -1
- package/build/runtime/QueryBus.js +6 -3
- package/build/runtime/QueryBus.js.map +1 -1
- package/build/store/createStore.d.ts +2 -2
- package/build/store/createStore.d.ts.map +1 -1
- package/build/store/createStore.js +31 -4
- package/build/store/createStore.js.map +1 -1
- package/build/store/middleware.d.ts +16 -1
- package/build/store/middleware.d.ts.map +1 -1
- package/build/store/middleware.js +16 -15
- package/build/store/middleware.js.map +1 -1
- package/build/store/types.d.ts +11 -4
- package/build/store/types.d.ts.map +1 -1
- package/build/store/types.js.map +1 -1
- package/package.json +20 -2
package/README.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
# Effectable
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/effectable)
|
|
4
|
+
[](https://github.com/iamnikas/effectable/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
[](https://nodejs.org)
|
|
7
|
+
[](https://eslint.org)
|
|
8
|
+
|
|
3
9
|
Reactive layer library: explicit bootstrap-path, Redux-RxJS store, base class with lifecycle, class-based HOC `connect`, and GraphRuntime with a declarative component tree (`h`, `compose`).
|
|
4
10
|
|
|
5
11
|
## Installation
|
|
6
12
|
|
|
7
|
-
Requires **Node.js
|
|
13
|
+
Requires **Node.js 22+** and **npm 9+**.
|
|
8
14
|
|
|
9
15
|
```bash
|
|
10
16
|
npm install effectable
|
|
@@ -42,7 +48,7 @@ Architecture overview: [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
|
|
|
42
48
|
|
|
43
49
|
- Creates `EventBus`, `CommandBus`, `QueryBus`, and `HandleRegistry` when the caller does not pass them explicitly.
|
|
44
50
|
- Mounts the root component via `GraphRuntime` (including ones wrapped with `connect`).
|
|
45
|
-
- Returns a handle with `shutdown()` for graceful teardown: calls `onUnmount` in
|
|
51
|
+
- Returns a handle with `shutdown()` for graceful teardown: calls `onUnmount` children-first, then parent; siblings sequentially in compose order; async `onUnmount` is awaited. Default `shutdown()` is best-effort: it **resolves** even if cleanup or `onUnmount` fails. Pass `{ rejectOnCleanupError: true }` to reject with `Error` (one failure) or `AggregateError` (several). Same option and default as `GraphRuntime.unmount()`.
|
|
46
52
|
- On startup failure, automatically cleans up already created runtime primitives.
|
|
47
53
|
|
|
48
54
|
### Bootstrap-path example
|
|
@@ -145,12 +151,24 @@ export const MyService = connect(store, mapStateToProps)(MyServiceRaw);
|
|
|
145
151
|
- `effectable/connect` — connect, MapStateToProps, ConnectOptions
|
|
146
152
|
- `effectable/runtime` — EventBus, CommandBus, QueryBus, HandleRegistry, BusDecorators (`wireRuntimeBuses`, **`wireRuntimeBusesAll`** — wire several handlers to the same bus set; process code usually reuses the same `commandBus` / `queryBus` / `eventBus` as `bootstrap(...).runtime`, without a second `createRuntimeBuses` / `HandleRegistry`)
|
|
147
153
|
|
|
154
|
+
## Contributing
|
|
155
|
+
|
|
156
|
+
Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/) (enforced by commitlint + lefthook). The same messages drive [semantic-release](https://semantic-release.app/) version bumps (`feat` → minor, `fix`/`perf` → patch, breaking → major).
|
|
157
|
+
|
|
158
|
+
```text
|
|
159
|
+
feat: add HandleRegistry autoRegister example
|
|
160
|
+
fix: buffer setState during onMount
|
|
161
|
+
docs: clarify bootstrap shutdown
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
After `npm ci`, lefthook installs a local `commit-msg` hook. CI also lint-checks PR commits. Prefer Conventional Commits for squash-merge titles too. Unused imports are an ESLint error, and the lefthook pre-commit hook runs `eslint --fix` automatically.
|
|
165
|
+
|
|
148
166
|
## Publishing
|
|
149
167
|
|
|
150
168
|
- **Canary** (`develop`): `npm install effectable@canary`
|
|
151
|
-
- **Stable** (`main`
|
|
169
|
+
- **Stable** (`main`): `npm install effectable`
|
|
152
170
|
|
|
153
|
-
Details: [docs/PUBLISHING.md](docs/PUBLISHING.md).
|
|
171
|
+
Versions are bumped automatically by semantic-release in CI. Details: [docs/PUBLISHING.md](docs/PUBLISHING.md).
|
|
154
172
|
|
|
155
173
|
## License
|
|
156
174
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAwC,MAAM,cAAc,CAAC;AAC/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOzD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAgIjB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EACN,UAAU,SAAS,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,EAC1E,QAAQ,SAAS,cAAc,GAAG,cAAc,EAChD,MAAM,SAAS,YAAY,GAAG,YAAY,EAC1C,MAAM,SAAS,YAAY,GAAG,YAAY,EAE1C,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,EAClC,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,GACnD,OAAO,CAAC,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAwC,MAAM,cAAc,CAAC;AAC/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOzD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAgIjB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EACN,UAAU,SAAS,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,EAC1E,QAAQ,SAAS,cAAc,GAAG,cAAc,EAChD,MAAM,SAAS,YAAY,GAAG,YAAY,EAC1C,MAAM,SAAS,YAAY,GAAG,YAAY,EAE1C,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,EAClC,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,GACnD,OAAO,CAAC,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAkFxE"}
|
|
@@ -147,6 +147,11 @@ async function bootstrap(type, props, options) {
|
|
|
147
147
|
// graphRuntime and rootInstance are guaranteed non-null at this point (running === true).
|
|
148
148
|
const activeGraphRuntime = graphRuntime;
|
|
149
149
|
const activeRootInstance = rootInstance;
|
|
150
|
+
/**
|
|
151
|
+
* Cached shutdown promise for concurrent shutdown callers.
|
|
152
|
+
* Ensures that multiple concurrent shutdown() calls await the same work.
|
|
153
|
+
*/
|
|
154
|
+
let cachedShutdownPromise = null;
|
|
150
155
|
return {
|
|
151
156
|
name,
|
|
152
157
|
rootInstance: activeRootInstance,
|
|
@@ -162,17 +167,18 @@ async function bootstrap(type, props, options) {
|
|
|
162
167
|
}
|
|
163
168
|
await activeGraphRuntime.reconcile((0, component_1.h)(type, props));
|
|
164
169
|
},
|
|
165
|
-
async shutdown() {
|
|
170
|
+
async shutdown(options) {
|
|
171
|
+
if (cachedShutdownPromise !== null) {
|
|
172
|
+
return cachedShutdownPromise;
|
|
173
|
+
}
|
|
166
174
|
if (!running) {
|
|
167
175
|
return;
|
|
168
176
|
}
|
|
169
177
|
running = false;
|
|
170
|
-
|
|
171
|
-
await activeGraphRuntime.unmount();
|
|
172
|
-
}
|
|
173
|
-
finally {
|
|
178
|
+
cachedShutdownPromise = activeGraphRuntime.unmount(options).finally(() => {
|
|
174
179
|
clearOwnedRuntimePrimitives(runtime, owned);
|
|
175
|
-
}
|
|
180
|
+
});
|
|
181
|
+
return cachedShutdownPromise;
|
|
176
182
|
},
|
|
177
183
|
};
|
|
178
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap/bootstrap.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAsKH,
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap/bootstrap.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAsKH,8BA4FC;AAhQD,4CAA+E;AAE/E,wCAKoB;AAapB,mCAGiB;AAEjB,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AAgBjD;;;;;GAKG;AACH,SAAS,uBAAuB,CAK9B,eAA0F;IAK1F,MAAM,kBAAkB,GAAG,OAAO,eAAe,KAAK,WAAW;QAC/D,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC;IAC/B,MAAM,gBAAgB,GAAG,OAAO,eAAe,KAAK,WAAW;QAC7D,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC;IAC7B,MAAM,gBAAgB,GAAG,OAAO,eAAe,KAAK,WAAW;QAC7D,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC;IAC7B,MAAM,sBAAsB,GAAG,OAAO,eAAe,KAAK,WAAW;QACnE,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,eAAe,CAAC,cAAc,CAAC;IAE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GAAG,KAAK,CAAC;YAChB,qBAAqB,GAAG,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;gBACvE,2BAA2B,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;YACH,OAAO,qBAAqB,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -97,9 +97,15 @@ export interface BootstrapHandle<TComponent extends Component<unknown, TProps>,
|
|
|
97
97
|
reconcile(): Promise<void>;
|
|
98
98
|
/**
|
|
99
99
|
* Idempotently shuts down the root runtime: unmounts the tree and clears owned buses.
|
|
100
|
+
* Accepts optional `rejectOnCleanupError` to make teardown errors observable.
|
|
101
|
+
* Default behavior remains non-breaking: resolves even with cleanup errors.
|
|
100
102
|
*
|
|
103
|
+
* @param {object} [options] - shutdown options
|
|
104
|
+
* @param {boolean} [options.rejectOnCleanupError=false] - reject on cleanup errors
|
|
101
105
|
* @returns {Promise<void>}
|
|
102
106
|
*/
|
|
103
|
-
shutdown(
|
|
107
|
+
shutdown(options?: {
|
|
108
|
+
rejectOnCleanupError?: boolean;
|
|
109
|
+
}): Promise<void>;
|
|
104
110
|
}
|
|
105
111
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/bootstrap/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;CAG9B,CAAC;AACX,MAAM,MAAM,wBAAwB,GAClC,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CA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D,kDAAkD;IAClD,QAAQ,EAAE,4BAA4B,CAAC;IACvC;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAAC;IACrB;;;;;OAKG;IACH,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,oBAAoB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE"}
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
* Responsibilities:
|
|
5
5
|
* - Materialize a VirtualServiceNode tree into real component instances (Fiber tree).
|
|
6
6
|
* - Fiber-like reconcile: diff current vs next trees by key + type, assign effectTags.
|
|
7
|
+
* Reconciliation mutates the live graph (not an isolated work-in-progress tree).
|
|
7
8
|
* - Drive lifecycle via LifecycleEngine: startup in topological order (children before parent),
|
|
8
|
-
* shutdown in
|
|
9
|
+
* shutdown in the same order (children before parent).
|
|
9
10
|
* - Inject contexts (@UseContext) and bind refs on mount.
|
|
10
11
|
* - Pass updated props into existing instances during reconcile.
|
|
12
|
+
* - Serialize all graph operations through a single operation queue.
|
|
13
|
+
* - Fail-stop on unrecoverable errors: mark runtime FAILED, reject later reconcile,
|
|
14
|
+
* unmount stays safe.
|
|
11
15
|
*
|
|
12
16
|
* Current limitations:
|
|
13
17
|
* - Work loop is synchronous (no priority lanes — next increment).
|
|
@@ -22,6 +26,22 @@ import type { FiberEffectTag, FiberInspectNode, VirtualServiceNode } from './typ
|
|
|
22
26
|
import type { ContextScope } from './context';
|
|
23
27
|
import type { RuntimeCommand, RuntimeEvent, RuntimeQuery } from '../runtime/types';
|
|
24
28
|
import type { RuntimeBusesBundle } from '../runtime/BusDecorators';
|
|
29
|
+
/**
|
|
30
|
+
* Runtime state literals.
|
|
31
|
+
* Private to GraphRuntime; reduced set without mounting/reconciling.
|
|
32
|
+
*/
|
|
33
|
+
declare const RUNTIME_STATE: {
|
|
34
|
+
readonly IDLE: "idle";
|
|
35
|
+
readonly ACTIVE: "active";
|
|
36
|
+
readonly FAILED: "failed";
|
|
37
|
+
readonly UNMOUNTING: "unmounting";
|
|
38
|
+
readonly UNMOUNTED: "unmounted";
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Runtime state type derived from RUNTIME_STATE.
|
|
42
|
+
* Not exported from package index (internal diagnostic only).
|
|
43
|
+
*/
|
|
44
|
+
type RuntimeState = (typeof RUNTIME_STATE)[keyof typeof RUNTIME_STATE];
|
|
25
45
|
/**
|
|
26
46
|
* Runtime engine for a declarative component tree.
|
|
27
47
|
*
|
|
@@ -35,13 +55,28 @@ import type { RuntimeBusesBundle } from '../runtime/BusDecorators';
|
|
|
35
55
|
export declare class GraphRuntime {
|
|
36
56
|
/** Current root fiber tree (current tree). */
|
|
37
57
|
private currentRoot;
|
|
38
|
-
/** Whether unmount has completed. */
|
|
39
|
-
private unmounted;
|
|
40
58
|
/**
|
|
41
59
|
* Entry counter for {@link continueStableReconcileAsync} (test/debug probe).
|
|
42
60
|
* Not reset automatically — compare before/after around reconcile.
|
|
43
61
|
*/
|
|
44
62
|
private stableAsyncContinueCount;
|
|
63
|
+
/**
|
|
64
|
+
* Backing field for {@link GraphRuntime.state}. Writes and most reads go
|
|
65
|
+
* through the accessor; post-await re-reads use `_state` (TS 6 still narrows getters).
|
|
66
|
+
*/
|
|
67
|
+
private _state;
|
|
68
|
+
/**
|
|
69
|
+
* Runtime state machine.
|
|
70
|
+
* IDLE → ACTIVE (on mount) → FAILED | UNMOUNTING → UNMOUNTED.
|
|
71
|
+
* FAILED is terminal: subsequent reconcile rejects, unmount is safe.
|
|
72
|
+
*/
|
|
73
|
+
private get state();
|
|
74
|
+
private set state(value);
|
|
75
|
+
/**
|
|
76
|
+
* Terminal error captured by failStop().
|
|
77
|
+
* Stored to reject later reconcile calls with the same error.
|
|
78
|
+
*/
|
|
79
|
+
private terminalError;
|
|
45
80
|
/**
|
|
46
81
|
* Runtime buses for auto-wiring decorators on nodes (optional, set in {@link GraphRuntime.mount}).
|
|
47
82
|
*/
|
|
@@ -81,10 +116,45 @@ export declare class GraphRuntime {
|
|
|
81
116
|
* Set via the fourth argument of {@link GraphRuntime.mount}.
|
|
82
117
|
*/
|
|
83
118
|
private onAutoReconcileError;
|
|
119
|
+
/**
|
|
120
|
+
* Operation queue: serializes reconcile and unmount.
|
|
121
|
+
* Each operation is a Promise-returning function executed sequentially.
|
|
122
|
+
*/
|
|
123
|
+
private operationQueue;
|
|
124
|
+
/**
|
|
125
|
+
* Whether an operation is currently running.
|
|
126
|
+
*/
|
|
127
|
+
private operationInProgress;
|
|
128
|
+
/**
|
|
129
|
+
* Cached unmount promise for concurrent unmount callers.
|
|
130
|
+
*/
|
|
131
|
+
private cachedUnmountPromise;
|
|
132
|
+
/**
|
|
133
|
+
* Pending fail-stop teardown work.
|
|
134
|
+
* When failStop nulls currentRoot but destroy is async, this tracks the in-flight cleanup.
|
|
135
|
+
* unmount() must await this before concluding teardown is finished.
|
|
136
|
+
*/
|
|
137
|
+
private pendingTeardown;
|
|
84
138
|
/**
|
|
85
139
|
* Instances are created only via {@link GraphRuntime.mount}; direct `new GraphRuntime()` is unavailable externally.
|
|
86
140
|
*/
|
|
87
141
|
private constructor();
|
|
142
|
+
/**
|
|
143
|
+
* Fail-stop: mark the runtime as failed, disable scheduling, tear down the graph best-effort.
|
|
144
|
+
* After fail-stop:
|
|
145
|
+
* - state is FAILED
|
|
146
|
+
* - terminalError is set
|
|
147
|
+
* - currentRoot is null (even if destroyFiber throws)
|
|
148
|
+
* - later reconcile() rejects with the terminal error
|
|
149
|
+
* - unmount() is safe and joinable
|
|
150
|
+
*
|
|
151
|
+
* No failed reconcile leaves the runtime active with a partial graph.
|
|
152
|
+
* Primary-error rules: cleanup errors attached as rollbackErrors, never replace primary.
|
|
153
|
+
*
|
|
154
|
+
* @param {Error} error - unrecoverable error that triggered fail-stop
|
|
155
|
+
* @returns {void | Promise<void>}
|
|
156
|
+
*/
|
|
157
|
+
private failStop;
|
|
88
158
|
/**
|
|
89
159
|
* Auto-wires runtime-bus decorators onto the instance before {@link LifecycleEngine.runStartup}.
|
|
90
160
|
*
|
|
@@ -101,6 +171,84 @@ export declare class GraphRuntime {
|
|
|
101
171
|
* @returns {void}
|
|
102
172
|
*/
|
|
103
173
|
private disposeEffectableRuntimeBusWiring;
|
|
174
|
+
/**
|
|
175
|
+
* Identity-safe ref clearing: clears ref.current only if it still points to the expected owner.
|
|
176
|
+
* Prevents an old rollback from clearing a ref that a newer materialization already reused.
|
|
177
|
+
* No cast required (Component | null → unknown | null is assignable).
|
|
178
|
+
*
|
|
179
|
+
* @param {RefObject<unknown>} ref - ref object
|
|
180
|
+
* @param {Component<unknown, unknown>} expectedOwner - expected current owner
|
|
181
|
+
* @returns {void}
|
|
182
|
+
*/
|
|
183
|
+
private clearRefSafe;
|
|
184
|
+
/**
|
|
185
|
+
* Centralized ref ownership transition.
|
|
186
|
+
* Handles every ref binding/clearing operation: add, remove, replace.
|
|
187
|
+
*
|
|
188
|
+
* Rules:
|
|
189
|
+
* - Clear previousRef only if it still points to expectedPreviousOwner (identity-safe).
|
|
190
|
+
* - Bind nextRef to instance if nextRef is provided.
|
|
191
|
+
* - previousRef and nextRef can be the same object (ref reuse) or different (ref swap).
|
|
192
|
+
* - Do not let an old disposer clear a newer owner.
|
|
193
|
+
*
|
|
194
|
+
* No casts: Component | null → unknown | null is assignable (widening).
|
|
195
|
+
*
|
|
196
|
+
* @param {RefObject<unknown> | undefined} previousRef - ref to clear (can be undefined if no previous ref)
|
|
197
|
+
* @param {Component<unknown, unknown> | null} expectedPreviousOwner - expected owner of previousRef (null if unknown)
|
|
198
|
+
* @param {RefObject<unknown> | undefined} nextRef - ref to bind to instance (can be undefined if removing ref)
|
|
199
|
+
* @param {Component<unknown, unknown> | null} instance - instance to bind nextRef to (null when clearing only)
|
|
200
|
+
* @returns {void}
|
|
201
|
+
*/
|
|
202
|
+
private commitRef;
|
|
203
|
+
/**
|
|
204
|
+
* Finalize fiber destroy: dispose wiring, clear ref, update status.
|
|
205
|
+
* Collects errors when collectErrors is provided (best-effort cleanup).
|
|
206
|
+
* When collectErrors is null, errors are thrown immediately.
|
|
207
|
+
*
|
|
208
|
+
* Uses commitRef for identity-safe ref clearing.
|
|
209
|
+
*
|
|
210
|
+
* @param {RuntimeFiber<unknown>} fiber - fiber being finalized
|
|
211
|
+
* @param {Error[] | null} collectErrors - array to collect errors (null to throw)
|
|
212
|
+
* @returns {void}
|
|
213
|
+
*/
|
|
214
|
+
private finalizeFiberDestroy;
|
|
215
|
+
/**
|
|
216
|
+
* Transactional rollback for failed fiber materialization.
|
|
217
|
+
* Releases acquired resources in reverse acquisition order:
|
|
218
|
+
* 1. disable scheduler hook
|
|
219
|
+
* 2. dispose runtime bus registrations
|
|
220
|
+
* 3. clear bound ref (identity-safe)
|
|
221
|
+
* 4. run failed-startup cleanup
|
|
222
|
+
* 5. destroy mounted children in reverse order
|
|
223
|
+
* 6. unlink the partial fiber
|
|
224
|
+
* Cleanup is best-effort: one failure does not skip remaining steps.
|
|
225
|
+
* Preserves the original materialization error; cleanup errors are attached.
|
|
226
|
+
* Rollback is idempotent.
|
|
227
|
+
*
|
|
228
|
+
* @param {RuntimeFiber<P>} fiber - fiber being rolled back
|
|
229
|
+
* @param {Error} primaryError - original materialization/startup error
|
|
230
|
+
* @returns {void | Promise<void>}
|
|
231
|
+
*/
|
|
232
|
+
private rollbackFailedMaterialization;
|
|
233
|
+
/**
|
|
234
|
+
* Async continuation of rollback child destruction after one child's destroy returned a Promise.
|
|
235
|
+
*
|
|
236
|
+
* @param {RuntimeFiber<unknown>[]} children - mounted children
|
|
237
|
+
* @param {number} lastIdx - index of the last processed child
|
|
238
|
+
* @param {Promise<void>} pending - Promise from destroying the previous child
|
|
239
|
+
* @param {Error} primaryError - original materialization error
|
|
240
|
+
* @param {Error[]} cleanupErrors - accumulated cleanup errors
|
|
241
|
+
* @returns {Promise<void>}
|
|
242
|
+
*/
|
|
243
|
+
private continueRollbackDestroyAsync;
|
|
244
|
+
/**
|
|
245
|
+
* Attaches cleanup errors to the primary error and rethrows.
|
|
246
|
+
*
|
|
247
|
+
* @param {Error} primaryError - original materialization error
|
|
248
|
+
* @param {Error[]} cleanupErrors - cleanup errors
|
|
249
|
+
* @returns {never}
|
|
250
|
+
*/
|
|
251
|
+
private finalizeRollback;
|
|
104
252
|
/**
|
|
105
253
|
* Injects the scheduler hook onto the component instance after successful startup.
|
|
106
254
|
* The hook is called from {@link Component.setState} and enqueues the fiber for automatic reconcile.
|
|
@@ -138,13 +286,34 @@ export declare class GraphRuntime {
|
|
|
138
286
|
* - If an ancestor of the fiber is already queued → skip (ancestor covers the subtree).
|
|
139
287
|
* - If descendants of the fiber are queued → remove them (fiber covers their subtrees).
|
|
140
288
|
*
|
|
289
|
+
* Skip scheduling when runtime is FAILED.
|
|
290
|
+
*
|
|
141
291
|
* @param {RuntimeFiber<unknown>} fiber - fiber whose subtree needs rebuild
|
|
142
292
|
* @returns {void}
|
|
143
293
|
*/
|
|
144
294
|
private scheduleUpdate;
|
|
295
|
+
/**
|
|
296
|
+
* Enqueues an operation and starts the queue processor if idle.
|
|
297
|
+
* Operations are executed sequentially; concurrent callers await the same in-flight operation.
|
|
298
|
+
* Serialize all graph mutations.
|
|
299
|
+
*
|
|
300
|
+
* @param {() => Promise<void>} operation - operation to enqueue
|
|
301
|
+
* @returns {Promise<void>}
|
|
302
|
+
*/
|
|
303
|
+
private enqueueOperation;
|
|
304
|
+
/**
|
|
305
|
+
* Processes the operation queue: runs operations one at a time.
|
|
306
|
+
* Single serialized owner of tree mutations.
|
|
307
|
+
* Errors from individual operations are propagated to their callers but do not stop the queue.
|
|
308
|
+
*
|
|
309
|
+
* @returns {Promise<void>}
|
|
310
|
+
*/
|
|
311
|
+
private processOperationQueue;
|
|
145
312
|
/**
|
|
146
313
|
* Queues one dirty-flush microtask and publishes {@link activeFlush} for await from `reconcile`.
|
|
147
314
|
*
|
|
315
|
+
* Skip scheduling when runtime is FAILED.
|
|
316
|
+
*
|
|
148
317
|
* @returns {void}
|
|
149
318
|
*/
|
|
150
319
|
private scheduleDirtyFlushMicrotask;
|
|
@@ -154,6 +323,9 @@ export declare class GraphRuntime {
|
|
|
154
323
|
* Guarded by the `flushing` flag against re-entrancy.
|
|
155
324
|
* The chain of repeat passes is capped by {@link GRAPH_RUNTIME_MAX_DIRTY_FLUSH_PASSES}.
|
|
156
325
|
*
|
|
326
|
+
* Respects state (UNMOUNTING/UNMOUNTED/FAILED) to cancel flush when unmount begins or failure occurs.
|
|
327
|
+
* On unrecoverable error, invokes onAutoReconcileError then fail-stops.
|
|
328
|
+
*
|
|
157
329
|
* @returns {Promise<void>}
|
|
158
330
|
*/
|
|
159
331
|
private flushDirtyFibers;
|
|
@@ -180,24 +352,35 @@ export declare class GraphRuntime {
|
|
|
180
352
|
static mount<P = unknown>(root: VirtualServiceNode<P>, initialScope?: ContextScope, runtimeBuses?: RuntimeBusesBundle<RuntimeCommand, RuntimeQuery, RuntimeEvent>, onAutoReconcileError?: (err: unknown) => void): Promise<GraphRuntime>;
|
|
181
353
|
/**
|
|
182
354
|
* Reconciles against a new tree.
|
|
183
|
-
*
|
|
355
|
+
* Diffs the current tree against the new one, computes effectTags, applies changes:
|
|
184
356
|
* - PLACE: create and mount a new node
|
|
185
357
|
* - UPDATE: update props on an existing instance, call onUpdate
|
|
186
358
|
* - DELETE: unmount and destroy a node
|
|
187
359
|
*
|
|
360
|
+
* All reconcile calls are serialized through the operation queue.
|
|
361
|
+
* Rejects with terminal error when runtime is FAILED.
|
|
362
|
+
*
|
|
188
363
|
* @param {VirtualServiceNode<P>} nextTree - new virtual tree
|
|
189
364
|
* @returns {Promise<void>}
|
|
190
|
-
* @throws {Error} if the runtime is
|
|
365
|
+
* @throws {Error} if the runtime state is UNMOUNTING, UNMOUNTED, or FAILED
|
|
191
366
|
*/
|
|
192
367
|
reconcile<P = unknown>(nextTree: VirtualServiceNode<P>): Promise<void>;
|
|
193
368
|
/**
|
|
194
369
|
* Fully unmounts the component tree.
|
|
195
|
-
* Calls onUnmount for each node
|
|
370
|
+
* Calls onUnmount for each node (children before parent) and
|
|
196
371
|
* moves stages to destroyed via LifecycleEngine.
|
|
197
372
|
*
|
|
373
|
+
* Unmount is serialized, cached promise returned for concurrent callers.
|
|
374
|
+
* Safe and joinable even when runtime is FAILED.
|
|
375
|
+
* Collects cleanup errors when `rejectOnCleanupError: true` is passed.
|
|
376
|
+
*
|
|
377
|
+
* @param {object} [options] - unmount options
|
|
378
|
+
* @param {boolean} [options.rejectOnCleanupError=false] - reject on cleanup errors
|
|
198
379
|
* @returns {Promise<void>}
|
|
199
380
|
*/
|
|
200
|
-
unmount(
|
|
381
|
+
unmount(options?: {
|
|
382
|
+
rejectOnCleanupError?: boolean;
|
|
383
|
+
}): Promise<void>;
|
|
201
384
|
/**
|
|
202
385
|
* Returns the root component instance (for testing and introspection).
|
|
203
386
|
*
|
|
@@ -205,7 +388,8 @@ export declare class GraphRuntime {
|
|
|
205
388
|
*/
|
|
206
389
|
getRootInstance(): Component<unknown, unknown> | null;
|
|
207
390
|
/**
|
|
208
|
-
* Whether the runtime is active (unmount has not been called).
|
|
391
|
+
* Whether the runtime is active (not failed and unmount has not been called).
|
|
392
|
+
* Returns false when state is FAILED.
|
|
209
393
|
*
|
|
210
394
|
* @returns {boolean}
|
|
211
395
|
*/
|
|
@@ -232,6 +416,13 @@ export declare class GraphRuntime {
|
|
|
232
416
|
* @returns {number} accumulated counter
|
|
233
417
|
*/
|
|
234
418
|
getStableAsyncContinueCount(): number;
|
|
419
|
+
/**
|
|
420
|
+
* Current runtime state.
|
|
421
|
+
* Test/debug probe; not a production API.
|
|
422
|
+
*
|
|
423
|
+
* @returns {RuntimeState} current state
|
|
424
|
+
*/
|
|
425
|
+
getState(): RuntimeState;
|
|
235
426
|
/**
|
|
236
427
|
* Builds a deep readonly {@link FiberInspectNode} from a RuntimeFiber.
|
|
237
428
|
*
|
|
@@ -263,7 +454,7 @@ export declare class GraphRuntime {
|
|
|
263
454
|
* @param {LifecycleEngine} engine - lifecycle engine
|
|
264
455
|
* @param {VirtualServiceNode<P>} vnode - virtual node
|
|
265
456
|
* @param {VirtualServiceNode[]} childVnodes - all child vnodes
|
|
266
|
-
* @param {
|
|
457
|
+
* @param {ContextScope} childScope - scope for child nodes
|
|
267
458
|
* @param {Promise<RuntimeFiber<unknown>>} pending - Promise for the current child
|
|
268
459
|
* @param {number} pendingIdx - index of the current child
|
|
269
460
|
* @returns {Promise<RuntimeFiber<P>>}
|
|
@@ -275,19 +466,10 @@ export declare class GraphRuntime {
|
|
|
275
466
|
* @template P node props type
|
|
276
467
|
* @param {RuntimeFiber<P>} fiber - fiber of the subtree root node
|
|
277
468
|
* @param {LifecycleEngine} engine - lifecycle engine for this node
|
|
278
|
-
* @param {RuntimeFiber<unknown>[]} childFibers - already mounted child fibers (for rollback on error)
|
|
279
469
|
* @param {PromiseLike<import('./lifecycle').LifecycleTransitionResult>} pendingStartup - Promise of the `runStartup` result
|
|
280
470
|
* @returns {Promise<RuntimeFiber<P>>} ready fiber, or rollback children and rethrow
|
|
281
471
|
*/
|
|
282
472
|
private finalizeMaterializeAsync;
|
|
283
|
-
/**
|
|
284
|
-
* Unmounts already-mounted children when parent startup fails.
|
|
285
|
-
* Returns sync void if all demounts are sync, otherwise a Promise.
|
|
286
|
-
*
|
|
287
|
-
* @param {RuntimeFiber<unknown>[]} childFibers
|
|
288
|
-
* @returns {void | Promise<void>}
|
|
289
|
-
*/
|
|
290
|
-
private destroyChildrenOnError;
|
|
291
473
|
/**
|
|
292
474
|
* Runs fiber-like reconcile for a single node.
|
|
293
475
|
* If type and key match — UPDATE: update props, reconcile children.
|
|
@@ -362,15 +544,35 @@ export declare class GraphRuntime {
|
|
|
362
544
|
* @returns {Promise<RuntimeFiber<unknown>[]>}
|
|
363
545
|
*/
|
|
364
546
|
private continueStableReconcileAsync;
|
|
547
|
+
/**
|
|
548
|
+
* Validates that sibling keys are unique within a list.
|
|
549
|
+
* Follows React v16.5 keyed child reconciliation contract: duplicate keys are invalid.
|
|
550
|
+
* Throws a descriptive error including the duplicate key and parent component identity.
|
|
551
|
+
*
|
|
552
|
+
* @param {Array<{ vnode: { key?: string }; instance?: Component<unknown, unknown> | null }>} items - list of fibers or vnodes
|
|
553
|
+
* @param {RuntimeFiber<unknown>} parentFiber - parent fiber (for error message)
|
|
554
|
+
* @param {string} listName - "current" or "next" (for error message)
|
|
555
|
+
* @returns {void}
|
|
556
|
+
* @throws {Error} when duplicate keys are detected
|
|
557
|
+
*/
|
|
558
|
+
private validateUniqueKeys;
|
|
365
559
|
/**
|
|
366
560
|
* Full-diff reconcile: keyed/unkeyed Map + destroy orphans.
|
|
367
561
|
* Always async — internal branching is too complex for an efficient sync path.
|
|
368
562
|
*
|
|
563
|
+
* Contract: Sibling keys must be unique (React v16.5 keyed child reconciliation).
|
|
564
|
+
* Validates both current and next children BEFORE any side effects.
|
|
565
|
+
* Throws deterministic error on duplicate keys to prevent lifecycle leaks.
|
|
566
|
+
*
|
|
567
|
+
* HOLE 3: On throw during PLACE, cleans up previously placed new nodes
|
|
568
|
+
* to prevent lifecycle leaks. Uses identity-safe check against currentChildren Set.
|
|
569
|
+
*
|
|
369
570
|
* @param {RuntimeFiber<unknown>[]} currentChildren - current child fibers
|
|
370
571
|
* @param {VirtualServiceNode[]} nextVnodes - new vnodes
|
|
371
572
|
* @param {RuntimeFiber<unknown>} parentFiber - parent fiber
|
|
372
573
|
* @param {ContextScope} childScope - children scope
|
|
373
574
|
* @returns {Promise<RuntimeFiber<unknown>[]>}
|
|
575
|
+
* @throws {Error} when duplicate keys are detected in current or next children
|
|
374
576
|
*/
|
|
375
577
|
private reconcileChildrenFullDiff;
|
|
376
578
|
/**
|
|
@@ -406,7 +608,10 @@ export declare class GraphRuntime {
|
|
|
406
608
|
* Returns `void` synchronously if the whole subtree is sync (up to 266x speedup
|
|
407
609
|
* on an 85-node tree); otherwise a Promise. `await` works correctly with either union branch.
|
|
408
610
|
*
|
|
611
|
+
* Collects cleanup errors via `collectErrors` parameter (best-effort cleanup).
|
|
612
|
+
*
|
|
409
613
|
* @param {RuntimeFiber} fiber - fiber to destroy
|
|
614
|
+
* @param {Error[] | null} collectErrors - array to collect cleanup errors (null to throw immediately)
|
|
410
615
|
* @returns {void | Promise<void>}
|
|
411
616
|
*/
|
|
412
617
|
private destroyFiber;
|
|
@@ -417,6 +622,7 @@ export declare class GraphRuntime {
|
|
|
417
622
|
* @param {Fiber[]} children - children list
|
|
418
623
|
* @param {number} pendingIdx - index of the pending child
|
|
419
624
|
* @param {PromiseLike<void>} pending - Promise from destroying the child
|
|
625
|
+
* @param {Error[] | null} collectErrors - array to collect cleanup errors
|
|
420
626
|
* @returns {Promise<void>}
|
|
421
627
|
*/
|
|
422
628
|
private continueDestroyAsync;
|
|
@@ -426,6 +632,7 @@ export declare class GraphRuntime {
|
|
|
426
632
|
*
|
|
427
633
|
* @param {RuntimeFiber<unknown>} fiber
|
|
428
634
|
* @param {PromiseLike<unknown>} pendingShutdown
|
|
635
|
+
* @param {Error[] | null} collectErrors - array to collect cleanup errors
|
|
429
636
|
* @returns {Promise<void>}
|
|
430
637
|
*/
|
|
431
638
|
private finalizeDestroyAsync;
|
|
@@ -454,4 +661,5 @@ export declare class GraphRuntime {
|
|
|
454
661
|
* @returns {FiberEffectTag}
|
|
455
662
|
*/
|
|
456
663
|
export declare function makeFiberEffectTag(tag: FiberEffectTag): FiberEffectTag;
|
|
664
|
+
export {};
|
|
457
665
|
//# sourceMappingURL=GraphRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphRuntime.d.ts","sourceRoot":"","sources":["../../src/component/GraphRuntime.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"GraphRuntime.d.ts","sourceRoot":"","sources":["../../src/component/GraphRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAs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