@xmachines/play-actor 3.0.0 → 4.0.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.
@@ -1,157 +0,0 @@
1
- /**
2
- * The report rules of a provider, in one place.
3
- *
4
- * A provider resolves the store from three inputs — the actor, the view, and the store of
5
- * the caller — and it reports a failure of that resolution to `onError`. This module holds
6
- * the three rules that every renderer had written for itself, beside
7
- * {@link createViewStoreLifecycle}, which already receives the same three inputs on every
8
- * resolve:
9
- *
10
- * - {@link sameViewInputs} answers whether two attempts carry the SAME three inputs.
11
- * - {@link createFailureLatch} reports ONE time for one set of those three. The render
12
- * path of a provider runs again for every tracked change, and a parent that renders
13
- * hands the props over again, so a report on each attempt gives the host one failure
14
- * many times.
15
- * - {@link createReportGuard} keeps the host from defeating the containment: a reset that
16
- * the host starts from INSIDE the report does nothing, a reset after the provider is
17
- * gone does nothing, and a handler that THROWS is contained where the renderer needs it.
18
- *
19
- * The copies disagreed. play-vue held a boolean and cleared it at four sites, play-svelte
20
- * held the three inputs and kept them across a null emission, and play-solid held nothing
21
- * at all while the comment of play-vue said that it did.
22
- *
23
- * @packageDocumentation
24
- */
25
- /**
26
- * The three inputs that a provider resolves a store from.
27
- *
28
- * `ViewStoreLifecycle.resolve` takes exactly these, and every provider names all three in
29
- * its reset rule. The type gives the rule one name, so the comparison below stands one
30
- * time instead of once for each renderer that needs it.
31
- */
32
- export interface ViewInputs {
33
- actor: unknown;
34
- view: unknown;
35
- store: unknown;
36
- }
37
- /**
38
- * Answers whether two sets of inputs are the SAME attempt.
39
- *
40
- * Identity, and not a deep compare: a provider holds the references that it rendered, and
41
- * a new spec object is a new attempt even when it holds equal fields.
42
- */
43
- export declare function sameViewInputs(a: ViewInputs, b: ViewInputs): boolean;
44
- /**
45
- * A report guard of one provider.
46
- *
47
- * The rule it holds: a provider reports a contained failure to the host, and it must do
48
- * that without letting the host defeat the containment. Two things follow — a reset that
49
- * the host calls from INSIDE the report does nothing, because no input changed between
50
- * the two attempts; and every callback that the provider handed out does nothing once the
51
- * provider is gone, because a host can keep a reset (a "Retry" button of a toast outlives
52
- * the route that opened it).
53
- */
54
- export interface ReportGuard {
55
- /** True when a reset that the host starts must do nothing. */
56
- blocked(): boolean;
57
- /**
58
- * True once {@link ReportGuard.dispose} ran, and never for a report that runs.
59
- *
60
- * {@link ReportGuard.blocked} answers a different question: it is true for the
61
- * re-entry of a report as well, and it goes back to false when that report ends. A
62
- * caller that asks whether the guard is SPENT — play-react builds one again after the
63
- * cleanup of `<StrictMode>` disposed it — must read this one: `blocked()` there would
64
- * replace a live guard that is reporting, and the `finally` of that report would then
65
- * clear the re-entry flag of a guard that nobody holds.
66
- */
67
- disposed(): boolean;
68
- /** The provider is gone. */
69
- dispose(): void;
70
- /**
71
- * Delivers one report, with the re-entry flag held for the call.
72
- *
73
- * @param error - The contained failure.
74
- * @param deliver - The call of the handler of the host, or `undefined` when the host
75
- * gave none. Without a handler the guard writes {@link ReportGuardMessages.noHandler}
76
- * to `console.error`: a contained failure that reaches no handler and no caller is
77
- * the one result that nobody can debug. A handler that THROWS is contained where the
78
- * guard carries {@link ReportGuardMessages.handlerThrew}, and it reaches the caller
79
- * where it does not.
80
- */
81
- report(error: unknown, deliver: (() => void) | undefined): void;
82
- }
83
- /**
84
- * What a {@link ReportGuard} writes to `console.error`, and what it therefore contains.
85
- *
86
- * Each message is optional, and each one is a DECISION of the renderer that builds the
87
- * guard. The rule that both serve is one rule: a contained failure is never silent, and
88
- * a handler of the host never defeats the containment.
89
- */
90
- export interface ReportGuardMessages {
91
- /**
92
- * What `console.error` says when the host gave no handler.
93
- *
94
- * Omit it where the framework writes such a failure itself: React logs an error that
95
- * a boundary caught, so play-react would report the same failure two times.
96
- */
97
- noHandler?: string;
98
- /**
99
- * What `console.error` says when the handler of the host THROWS.
100
- *
101
- * A guard that carries this message CONTAINS such a throw. All five renderers carry it,
102
- * so a host learns one rule: a handler of the host never defeats the containment, and a
103
- * host that must escalate raises the failure from a task of its own —
104
- * `queueMicrotask(() => { throw error; })`. Omit it only where a throw must reach the
105
- * caller, which no renderer of this workspace asks for today.
106
- *
107
- * A renderer needs the containment when a throw that leaves the report also stops the
108
- * screen of the fallback: the flag of play-vue schedules a render, the fallback of
109
- * play-solid is the RETURN of the callback that reports, `componentDidCatch` of
110
- * play-react can take the complete React root down, and a throw that leaves the
111
- * `onerror` of Svelte leaves its own `calling_on_error` flag raised, which makes every
112
- * later reset of the host raise `svelte_boundary_reset_onerror`.
113
- */
114
- handlerThrew?: string;
115
- }
116
- /**
117
- * Makes a {@link ReportGuard}.
118
- *
119
- * The flag SAVES and restores, and it is no plain `false` at the end: a handler of the
120
- * host can start a second contained failure inside the first — a fallback that throws, a
121
- * write of the store that drives another emission — and a bare reset in the inner
122
- * `finally` would clear the guard while the outer report still runs.
123
- *
124
- * @param messages - See {@link ReportGuardMessages}. The two messages say what the guard
125
- * writes to `console.error`, and the absence of one says what it lets through.
126
- */
127
- export declare function createReportGuard(messages: ReportGuardMessages): ReportGuard;
128
- /** The record of what a provider reported. See {@link createFailureLatch}. */
129
- export interface FailureLatch {
130
- /**
131
- * Answers whether a failure of these three inputs is new, and records it.
132
- *
133
- * @returns `true` the first time for one set of inputs, and `false` for every repeat
134
- * of the same set. A caller reports only when it returns `true`.
135
- */
136
- shouldReport(actor: unknown, view: unknown, store: unknown): boolean;
137
- /**
138
- * Forgets the record, so the next failure reports again.
139
- *
140
- * A caller clears it on EVERY emission of a view, the null emission included: a view,
141
- * then null, then the same view is a real sequence of an actor, and the second failure
142
- * of that view is a second attempt that the host must hear about. It also clears it on
143
- * a resolution that works, and on a retry that the host starts — the host asked for
144
- * that attempt, so it must hear the result.
145
- */
146
- clear(): void;
147
- }
148
- /**
149
- * Makes a {@link FailureLatch}.
150
- *
151
- * The latch holds the three inputs BESIDE the flag. Clearing on each emission would be
152
- * enough for a provider that can hook every emission, and the identity check covers the
153
- * one that cannot: a render that runs again with nothing changed reports nothing, whether
154
- * or not the provider noticed that it ran.
155
- */
156
- export declare function createFailureLatch(): FailureLatch;
157
- //# sourceMappingURL=failure-latch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"failure-latch.d.ts","sourceRoot":"","sources":["../src/failure-latch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAEpE;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAW;IAC3B,8DAA8D;IAC9D,OAAO,IAAI,OAAO,CAAC;IACnB;;;;;;;;;OASG;IACH,QAAQ,IAAI,OAAO,CAAC;IACpB,4BAA4B;IAC5B,OAAO,IAAI,IAAI,CAAC;IAChB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;CAChE;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,WAAW,CAqC5E;AAED,8EAA8E;AAC9E,MAAM,WAAW,YAAY;IAC5B;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACrE;;;;;;;;OAQG;IACH,KAAK,IAAI,IAAI,CAAC;CACd;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAgBjD"}
@@ -1,110 +0,0 @@
1
- /**
2
- * The report rules of a provider, in one place.
3
- *
4
- * A provider resolves the store from three inputs — the actor, the view, and the store of
5
- * the caller — and it reports a failure of that resolution to `onError`. This module holds
6
- * the three rules that every renderer had written for itself, beside
7
- * {@link createViewStoreLifecycle}, which already receives the same three inputs on every
8
- * resolve:
9
- *
10
- * - {@link sameViewInputs} answers whether two attempts carry the SAME three inputs.
11
- * - {@link createFailureLatch} reports ONE time for one set of those three. The render
12
- * path of a provider runs again for every tracked change, and a parent that renders
13
- * hands the props over again, so a report on each attempt gives the host one failure
14
- * many times.
15
- * - {@link createReportGuard} keeps the host from defeating the containment: a reset that
16
- * the host starts from INSIDE the report does nothing, a reset after the provider is
17
- * gone does nothing, and a handler that THROWS is contained where the renderer needs it.
18
- *
19
- * The copies disagreed. play-vue held a boolean and cleared it at four sites, play-svelte
20
- * held the three inputs and kept them across a null emission, and play-solid held nothing
21
- * at all while the comment of play-vue said that it did.
22
- *
23
- * @packageDocumentation
24
- */
25
- /**
26
- * Answers whether two sets of inputs are the SAME attempt.
27
- *
28
- * Identity, and not a deep compare: a provider holds the references that it rendered, and
29
- * a new spec object is a new attempt even when it holds equal fields.
30
- */
31
- export function sameViewInputs(a, b) {
32
- return a.actor === b.actor && a.view === b.view && a.store === b.store;
33
- }
34
- /**
35
- * Makes a {@link ReportGuard}.
36
- *
37
- * The flag SAVES and restores, and it is no plain `false` at the end: a handler of the
38
- * host can start a second contained failure inside the first — a fallback that throws, a
39
- * write of the store that drives another emission — and a bare reset in the inner
40
- * `finally` would clear the guard while the outer report still runs.
41
- *
42
- * @param messages - See {@link ReportGuardMessages}. The two messages say what the guard
43
- * writes to `console.error`, and the absence of one says what it lets through.
44
- */
45
- export function createReportGuard(messages) {
46
- const { noHandler, handlerThrew } = messages;
47
- let disposed = false;
48
- let reporting = false;
49
- return {
50
- blocked: () => disposed || reporting,
51
- disposed: () => disposed,
52
- dispose() {
53
- disposed = true;
54
- },
55
- report(error, deliver) {
56
- const wasReporting = reporting;
57
- reporting = true;
58
- try {
59
- if (!deliver) {
60
- if (noHandler !== undefined)
61
- console.error(noHandler, error);
62
- return;
63
- }
64
- if (handlerThrew === undefined) {
65
- deliver();
66
- return;
67
- }
68
- // The containment of a handler that throws. The failure belongs to the host,
69
- // and it stops here: a throw that leaves this call reaches the framework of
70
- // the caller, which is the path that the boundary of the renderer closes.
71
- // Write it where a caller can find it.
72
- try {
73
- deliver();
74
- }
75
- catch (handlerFailure) {
76
- console.error(handlerThrew, handlerFailure);
77
- }
78
- }
79
- finally {
80
- reporting = wasReporting;
81
- }
82
- },
83
- };
84
- }
85
- /**
86
- * Makes a {@link FailureLatch}.
87
- *
88
- * The latch holds the three inputs BESIDE the flag. Clearing on each emission would be
89
- * enough for a provider that can hook every emission, and the identity check covers the
90
- * one that cannot: a render that runs again with nothing changed reports nothing, whether
91
- * or not the provider noticed that it ran.
92
- */
93
- export function createFailureLatch() {
94
- // ONE record of the three inputs, and `null` for "nothing reported yet". A flag beside
95
- // three loose fields says the same thing two times, and the two can disagree.
96
- let last = null;
97
- return {
98
- shouldReport(actor, view, store) {
99
- const next = { actor, view, store };
100
- if (last !== null && sameViewInputs(last, next))
101
- return false;
102
- last = next;
103
- return true;
104
- },
105
- clear() {
106
- last = null;
107
- },
108
- };
109
- }
110
- //# sourceMappingURL=failure-latch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"failure-latch.js","sourceRoot":"","sources":["../src/failure-latch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAeH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,CAAa,EAAE,CAAa;IAC1D,OAAO,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,C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AY,CAAC,KAAc,EAAE,IAAa,EAAE,KAAc;YACzD,MAAM,IAAI,GAAe,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;YAChD,IAAI,IAAI,KAAK,IAAI,IAAI,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC9D,IAAI,GAAG,IAAI,CAAC;YACZ,OAAO,IAAI,CAAC;QACb,CAAC;QACD,KAAK;YACJ,IAAI,GAAG,IAAI,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -1,58 +0,0 @@
1
- /**
2
- * The shared provider guards of the ActorProvider implementation of each framework.
3
- *
4
- * Every framework integration (React, Vue, Solid, Svelte, and DOM) does the same
5
- * two steps when it connects the view of an actor to a json-render tree:
6
- *
7
- * 1. It cleans `spec.state` before it seeds a new `@xstate/store` atom
8
- * ({@link toAtomState}).
9
- * 2. It puts an `onRenderError` handler of the component level into the component
10
- * registry, and it does not change the registry of the caller
11
- * ({@link attachRenderErrorHandler}).
12
- *
13
- * Both functions are here. Therefore the semantics of the guards are identical in
14
- * every framework.
15
- *
16
- * @packageDocumentation
17
- */
18
- import type { RenderErrorHandler } from "@xmachines/json-render-core";
19
- /**
20
- * Converts the `state` field of a spec into a plain object for `createAtom`, in a safe way.
21
- *
22
- * `spec.state` has the type `unknown` in `PlaySpec`. At run time it is `null`,
23
- * `undefined`, a primitive, or a plain object, and this depends on the value that
24
- * the author of the machine put in the view spec. `createAtom` requires a plain
25
- * object as its first value, because every other value makes a broken store at run
26
- * time.
27
- *
28
- * The function accepts a plain object only, which means that its prototype is
29
- * `Object.prototype` or `null`, and it returns that object without a change. Every
30
- * other value becomes a new `{}`: `null`, `undefined`, a primitive, an array, an
31
- * instance of a class, and a built-in object such as a Date, a Map, or a Set. A
32
- * broken store therefore never appears at run time.
33
- *
34
- * @param state - The raw `spec.state` value of a `PlaySpec`.
35
- * @returns `state` itself when it is a plain object. In every other case, a new empty object.
36
- */
37
- export declare function toAtomState(state: unknown): Record<string, unknown>;
38
- /**
39
- * Copies a component registry, and puts an `onRenderError` handler into the copy.
40
- *
41
- * The function defines the handler as an own property of the copy. That property is
42
- * not enumerable, and it is configurable (D-19 gives one convention of the
43
- * injection for every framework renderer). The handler therefore replaces each
44
- * handler of the `defineRegistry` level, and it does not appear in an enumeration of
45
- * the component entries of the registry.
46
- *
47
- * The function never changes the registry of the caller: it returns a shallow copy.
48
- * Therefore a caller that needs a handler for each instance, such as an
49
- * `onRenderError` prop of `ActorProvider`, can share one result of `defineRegistry`
50
- * between the providers in a safe way.
51
- *
52
- * @typeParam TRegistry - The component registry type of the framework.
53
- * @param registry - The component registry from `defineRegistry().registry`.
54
- * @param handler - The renderer calls it with `(error, componentName)` when a catalog component throws during a render.
55
- * @returns A shallow copy of `registry`, with `onRenderError` on it.
56
- */
57
- export declare function attachRenderErrorHandler<TRegistry extends object>(registry: TRegistry, handler: RenderErrorHandler): TRegistry;
58
- //# sourceMappingURL=provider-guards.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider-guards.d.ts","sourceRoot":"","sources":["../src/provider-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQnE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,SAAS,MAAM,EAChE,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,kBAAkB,GACzB,SAAS,CAQX"}
@@ -1,73 +0,0 @@
1
- /**
2
- * The shared provider guards of the ActorProvider implementation of each framework.
3
- *
4
- * Every framework integration (React, Vue, Solid, Svelte, and DOM) does the same
5
- * two steps when it connects the view of an actor to a json-render tree:
6
- *
7
- * 1. It cleans `spec.state` before it seeds a new `@xstate/store` atom
8
- * ({@link toAtomState}).
9
- * 2. It puts an `onRenderError` handler of the component level into the component
10
- * registry, and it does not change the registry of the caller
11
- * ({@link attachRenderErrorHandler}).
12
- *
13
- * Both functions are here. Therefore the semantics of the guards are identical in
14
- * every framework.
15
- *
16
- * @packageDocumentation
17
- */
18
- /**
19
- * Converts the `state` field of a spec into a plain object for `createAtom`, in a safe way.
20
- *
21
- * `spec.state` has the type `unknown` in `PlaySpec`. At run time it is `null`,
22
- * `undefined`, a primitive, or a plain object, and this depends on the value that
23
- * the author of the machine put in the view spec. `createAtom` requires a plain
24
- * object as its first value, because every other value makes a broken store at run
25
- * time.
26
- *
27
- * The function accepts a plain object only, which means that its prototype is
28
- * `Object.prototype` or `null`, and it returns that object without a change. Every
29
- * other value becomes a new `{}`: `null`, `undefined`, a primitive, an array, an
30
- * instance of a class, and a built-in object such as a Date, a Map, or a Set. A
31
- * broken store therefore never appears at run time.
32
- *
33
- * @param state - The raw `spec.state` value of a `PlaySpec`.
34
- * @returns `state` itself when it is a plain object. In every other case, a new empty object.
35
- */
36
- export function toAtomState(state) {
37
- if (state !== null && typeof state === "object" && !Array.isArray(state)) {
38
- const proto = Object.getPrototypeOf(state);
39
- if (proto === Object.prototype || proto === null) {
40
- return state;
41
- }
42
- }
43
- return {};
44
- }
45
- /**
46
- * Copies a component registry, and puts an `onRenderError` handler into the copy.
47
- *
48
- * The function defines the handler as an own property of the copy. That property is
49
- * not enumerable, and it is configurable (D-19 gives one convention of the
50
- * injection for every framework renderer). The handler therefore replaces each
51
- * handler of the `defineRegistry` level, and it does not appear in an enumeration of
52
- * the component entries of the registry.
53
- *
54
- * The function never changes the registry of the caller: it returns a shallow copy.
55
- * Therefore a caller that needs a handler for each instance, such as an
56
- * `onRenderError` prop of `ActorProvider`, can share one result of `defineRegistry`
57
- * between the providers in a safe way.
58
- *
59
- * @typeParam TRegistry - The component registry type of the framework.
60
- * @param registry - The component registry from `defineRegistry().registry`.
61
- * @param handler - The renderer calls it with `(error, componentName)` when a catalog component throws during a render.
62
- * @returns A shallow copy of `registry`, with `onRenderError` on it.
63
- */
64
- export function attachRenderErrorHandler(registry, handler) {
65
- const clone = { ...registry };
66
- Object.defineProperty(clone, "onRenderError", {
67
- value: handler,
68
- enumerable: false,
69
- configurable: true,
70
- });
71
- return clone;
72
- }
73
- //# sourceMappingURL=provider-guards.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider-guards.js","sourceRoot":"","sources":["../src/provider-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1E,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAY,CAAC;QACtD,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAClD,OAAO,KAAgC,CAAC;QACzC,CAAC;IACF,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,wBAAwB,CACvC,QAAmB,EACnB,OAA2B;IAE3B,MAAM,KAAK,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC9B,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE;QAC7C,KAAK,EAAE,OAAO;QACd,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -1,82 +0,0 @@
1
- /**
2
- * The lifecycle of the view store — the framework-agnostic decision between a new
3
- * seed and a refresh. Each provider connects it to its own reactivity.
4
- *
5
- * The policy is in one place now. Each renderer held a copy of it before, and those
6
- * copies moved apart into real faults:
7
- *
8
- * - The `viewKey` changed, or this is the first resolve, or the tree provides a
9
- * different actor → NEW SEED: a new store, from the composed state of the view.
10
- * - The `viewKey` did not change → REFRESH: only the /context projection moved.
11
- * Therefore the code replaces the `/context` subtree in place, and the ephemeral
12
- * state at the root level, such as a draft or a toggle, stays.
13
- * - No `viewKey`, from a Viewable that a person built and that stamps no key → a new
14
- * seed for each EMISSION, which is the safe behavior from the time before the
15
- * viewKey.
16
- * - A different actor → the store that stays alive dies with its actor. This is the
17
- * rule of the lifetime.
18
- * - The controlled mode, where the caller gives the store → the caller owns the seed
19
- * and the lifecycle. The machinery owns /context in both modes, and this file
20
- * refreshes it. The caller can move that refresh to a later moment
21
- * ({@link ResolveViewStoreOptions}), and the render path of React needs this,
22
- * because a store must notify no subscriber during a render. The effects of React
23
- * then do the refresh.
24
- *
25
- * Each provider therefore holds the wiring of its reactivity only: the moment of
26
- * the resolve, and the path of the result to the children.
27
- *
28
- * @packageDocumentation
29
- */
30
- import type { StateStore } from "@xmachines/json-render-core";
31
- import type { PlaySpec } from "./abstract-actor.js";
32
- /** The result of a resolve — see {@link ViewStoreLifecycle.resolve}. */
33
- export interface ViewStoreResolution {
34
- /** The store WITHOUT the guard — the reference of the machinery for its own refresh. */
35
- store: StateStore;
36
- /**
37
- * The store to give to the children ($bindState, setState, and a chained set): a
38
- * write under /context throws. There is one wrapper for each store below it, and
39
- * the code caches the identity. Therefore a consumer in the style of
40
- * `useSyncExternalStore` stays stable.
41
- */
42
- guardedStore: StateStore;
43
- /**
44
- * It is true when this resolve made a new store: at the first resolve, on a change
45
- * of the viewKey, in the fallback for each emission, and on a change of the actor. A
46
- * provider that mounts a subtree again for each store, such as the storeKey of Vue,
47
- * uses this field as its key.
48
- */
49
- reseeded: boolean;
50
- }
51
- export interface ResolveViewStoreOptions {
52
- /**
53
- * The controlled mode only: refresh the /context subtree of the external store
54
- * during this resolve. The default is true. Give false where the call site permits
55
- * no notification of the store subscribers, which is the render path of React, and
56
- * refresh from an effect instead.
57
- */
58
- refreshExternalStore?: boolean;
59
- }
60
- export interface ViewStoreLifecycle {
61
- /**
62
- * Brings the store in line with an emission, and returns it with its guard.
63
- *
64
- * @param actor - The actor of the emission. A different actor drops the store that the code kept.
65
- * @param view - The derived view. It is not null: a null emission is a GAP, and not
66
- * a new view. A caller resolves nothing on a null value, and it keeps the store.
67
- * @param externalStore - The controlled mode: the store of the caller.
68
- * @param options - See {@link ResolveViewStoreOptions}.
69
- */
70
- resolve(actor: unknown, view: PlaySpec, externalStore?: StateStore | undefined, options?: ResolveViewStoreOptions): ViewStoreResolution;
71
- /** Drops everything, on an unmount or a disconnect. The next resolve makes a new seed. */
72
- reset(): void;
73
- }
74
- /**
75
- * Creates a coordinator of the lifecycle.
76
- *
77
- * @param createStore - The store factory of the framework. It receives the seed
78
- * that is safe for the prototype (`toAtomState(view.state)`), and the composed
79
- * state carries /context already.
80
- */
81
- export declare function createViewStoreLifecycle(createStore: (seed: Record<string, unknown>) => StateStore): ViewStoreLifecycle;
82
- //# sourceMappingURL=view-store-lifecycle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"view-store-lifecycle.d.ts","sourceRoot":"","sources":["../src/view-store-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIpD,wEAAwE;AACxE,MAAM,WAAW,mBAAmB;IACnC,wFAAwF;IACxF,KAAK,EAAE,UAAU,CAAC;IAClB;;;;;OAKG;IACH,YAAY,EAAE,UAAU,CAAC;IACzB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACvC;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,kBAAkB;IAClC;;;;;;;;OAQG;IACH,OAAO,CACN,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,QAAQ,EACd,aAAa,CAAC,EAAE,UAAU,GAAG,SAAS,EACtC,OAAO,CAAC,EAAE,uBAAuB,GAC/B,mBAAmB,CAAC;IACvB,0FAA0F;IAC1F,KAAK,IAAI,IAAI,CAAC;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACvC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,UAAU,GACxD,kBAAkB,CA4DpB"}
@@ -1,97 +0,0 @@
1
- /**
2
- * The lifecycle of the view store — the framework-agnostic decision between a new
3
- * seed and a refresh. Each provider connects it to its own reactivity.
4
- *
5
- * The policy is in one place now. Each renderer held a copy of it before, and those
6
- * copies moved apart into real faults:
7
- *
8
- * - The `viewKey` changed, or this is the first resolve, or the tree provides a
9
- * different actor → NEW SEED: a new store, from the composed state of the view.
10
- * - The `viewKey` did not change → REFRESH: only the /context projection moved.
11
- * Therefore the code replaces the `/context` subtree in place, and the ephemeral
12
- * state at the root level, such as a draft or a toggle, stays.
13
- * - No `viewKey`, from a Viewable that a person built and that stamps no key → a new
14
- * seed for each EMISSION, which is the safe behavior from the time before the
15
- * viewKey.
16
- * - A different actor → the store that stays alive dies with its actor. This is the
17
- * rule of the lifetime.
18
- * - The controlled mode, where the caller gives the store → the caller owns the seed
19
- * and the lifecycle. The machinery owns /context in both modes, and this file
20
- * refreshes it. The caller can move that refresh to a later moment
21
- * ({@link ResolveViewStoreOptions}), and the render path of React needs this,
22
- * because a store must notify no subscriber during a render. The effects of React
23
- * then do the refresh.
24
- *
25
- * Each provider therefore holds the wiring of its reactivity only: the moment of
26
- * the resolve, and the path of the result to the children.
27
- *
28
- * @packageDocumentation
29
- */
30
- import { guardContextWrites, refreshContextSubtree } from "./context-projection.js";
31
- import { toAtomState } from "./provider-guards.js";
32
- /**
33
- * Creates a coordinator of the lifecycle.
34
- *
35
- * @param createStore - The store factory of the framework. It receives the seed
36
- * that is safe for the prototype (`toAtomState(view.state)`), and the composed
37
- * state carries /context already.
38
- */
39
- export function createViewStoreLifecycle(createStore) {
40
- let internalStore = null;
41
- let lastViewKey = undefined;
42
- let lastView = null;
43
- let lastActor = null;
44
- // The identity cache of the guard: one wrapper for each store below it.
45
- let guardedSource = null;
46
- let guardedStore = null;
47
- const reset = () => {
48
- internalStore = null;
49
- lastViewKey = undefined;
50
- lastView = null;
51
- lastActor = null;
52
- guardedSource = null;
53
- guardedStore = null;
54
- };
55
- return {
56
- reset,
57
- resolve(actor, view, externalStore, options) {
58
- // The rule of the lifetime: a store that stays alive must not outlive its actor.
59
- if (lastActor !== actor) {
60
- const firstResolve = lastActor === null && internalStore === null;
61
- if (!firstResolve)
62
- reset();
63
- lastActor = actor;
64
- }
65
- let resolved;
66
- let reseeded = false;
67
- if (externalStore) {
68
- resolved = externalStore;
69
- if (options?.refreshExternalStore !== false) {
70
- refreshContextSubtree(resolved, view);
71
- }
72
- }
73
- else {
74
- const viewKey = view.viewKey;
75
- let nextStore = internalStore;
76
- if (nextStore === null ||
77
- (viewKey !== undefined ? lastViewKey !== viewKey : lastView !== view)) {
78
- nextStore = createStore(toAtomState(view.state));
79
- internalStore = nextStore;
80
- lastViewKey = viewKey;
81
- reseeded = true;
82
- }
83
- else if (viewKey !== undefined) {
84
- refreshContextSubtree(nextStore, view);
85
- }
86
- lastView = view;
87
- resolved = nextStore;
88
- }
89
- if (guardedSource !== resolved) {
90
- guardedSource = resolved;
91
- guardedStore = guardContextWrites(resolved);
92
- }
93
- return { store: resolved, guardedStore: guardedStore, reseeded };
94
- },
95
- };
96
- }
97
- //# sourceMappingURL=view-store-lifecycle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"view-store-lifecycle.js","sourceRoot":"","sources":["../src/view-store-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;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