@playfast/reform 0.0.5 → 0.0.7
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/dist/boundary/boundary.d.ts +72 -0
- package/dist/boundary/boundary.d.ts.map +1 -0
- package/dist/boundary/boundary.js +83 -0
- package/dist/boundary/boundary.js.map +1 -0
- package/dist/calc/asyncCalc.d.ts +91 -0
- package/dist/calc/asyncCalc.d.ts.map +1 -0
- package/dist/calc/asyncCalc.js +95 -0
- package/dist/calc/asyncCalc.js.map +1 -0
- package/{src/calc/asyncData.ts → dist/calc/asyncData.d.ts} +22 -53
- package/dist/calc/asyncData.d.ts.map +1 -0
- package/dist/calc/asyncData.js +34 -0
- package/dist/calc/asyncData.js.map +1 -0
- package/dist/calc/calc.d.ts +57 -0
- package/dist/calc/calc.d.ts.map +1 -0
- package/dist/calc/calc.js +58 -0
- package/dist/calc/calc.js.map +1 -0
- package/dist/calc/calcFamily.d.ts +57 -0
- package/dist/calc/calcFamily.d.ts.map +1 -0
- package/dist/calc/calcFamily.js +124 -0
- package/dist/calc/calcFamily.js.map +1 -0
- package/dist/calc/compose.d.ts +16 -0
- package/dist/calc/compose.d.ts.map +1 -0
- package/dist/calc/compose.js +7 -0
- package/dist/calc/compose.js.map +1 -0
- package/dist/channel/channel.d.ts +115 -0
- package/dist/channel/channel.d.ts.map +1 -0
- package/dist/channel/channel.js +138 -0
- package/dist/channel/channel.js.map +1 -0
- package/dist/compose/composition.d.ts +72 -0
- package/dist/compose/composition.d.ts.map +1 -0
- package/dist/compose/composition.js +46 -0
- package/dist/compose/composition.js.map +1 -0
- package/{src/compose/host.ts → dist/compose/host.d.ts} +8 -6
- package/dist/compose/host.d.ts.map +1 -0
- package/dist/compose/host.js +6 -0
- package/dist/compose/host.js.map +1 -0
- package/dist/compose/props.d.ts +13 -0
- package/dist/compose/props.d.ts.map +1 -0
- package/{src/compose/props.ts → dist/compose/props.js} +5 -3
- package/dist/compose/props.js.map +1 -0
- package/dist/compose/provide.d.ts +22 -0
- package/dist/compose/provide.d.ts.map +1 -0
- package/dist/compose/provide.js +28 -0
- package/dist/compose/provide.js.map +1 -0
- package/{src/compose/slot.ts → dist/compose/slot.d.ts} +19 -36
- package/dist/compose/slot.d.ts.map +1 -0
- package/dist/compose/slot.js +23 -0
- package/dist/compose/slot.js.map +1 -0
- package/dist/compose/ui.d.ts +135 -0
- package/dist/compose/ui.d.ts.map +1 -0
- package/dist/compose/ui.js +63 -0
- package/dist/compose/ui.js.map +1 -0
- package/dist/definition/definition.d.ts +33 -0
- package/dist/definition/definition.d.ts.map +1 -0
- package/dist/definition/definition.js +42 -0
- package/dist/definition/definition.js.map +1 -0
- package/dist/event/event.d.ts +33 -0
- package/dist/event/event.d.ts.map +1 -0
- package/dist/event/event.js +30 -0
- package/dist/event/event.js.map +1 -0
- package/dist/event/eventGroup.d.ts +9 -0
- package/dist/event/eventGroup.d.ts.map +1 -0
- package/dist/event/eventGroup.js +4 -0
- package/dist/event/eventGroup.js.map +1 -0
- package/{src/feature/feature.ts → dist/feature/feature.d.ts} +92 -178
- package/dist/feature/feature.d.ts.map +1 -0
- package/dist/feature/feature.js +98 -0
- package/dist/feature/feature.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/{src/internal/capture.ts → dist/internal/capture.d.ts} +11 -13
- package/dist/internal/capture.d.ts.map +1 -0
- package/dist/internal/capture.js +12 -0
- package/dist/internal/capture.js.map +1 -0
- package/{src/internal/ctx.ts → dist/internal/ctx.d.ts} +4 -8
- package/dist/internal/ctx.d.ts.map +1 -0
- package/dist/internal/ctx.js +2 -0
- package/dist/internal/ctx.js.map +1 -0
- package/dist/internal/errors.d.ts +89 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +102 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/inspect.d.ts +17 -0
- package/dist/internal/inspect.d.ts.map +1 -0
- package/dist/internal/inspect.js +32 -0
- package/dist/internal/inspect.js.map +1 -0
- package/dist/internal/queryDriver.d.ts +65 -0
- package/dist/internal/queryDriver.d.ts.map +1 -0
- package/dist/internal/queryDriver.js +134 -0
- package/dist/internal/queryDriver.js.map +1 -0
- package/dist/internal/reuse.d.ts +10 -0
- package/dist/internal/reuse.d.ts.map +1 -0
- package/dist/internal/reuse.js +68 -0
- package/dist/internal/reuse.js.map +1 -0
- package/dist/internal/scheduler.d.ts +47 -0
- package/dist/internal/scheduler.d.ts.map +1 -0
- package/dist/internal/scheduler.js +70 -0
- package/dist/internal/scheduler.js.map +1 -0
- package/{src/internal/seeds.ts → dist/internal/seeds.d.ts} +3 -6
- package/dist/internal/seeds.d.ts.map +1 -0
- package/dist/internal/seeds.js +17 -0
- package/dist/internal/seeds.js.map +1 -0
- package/dist/internal/sources.d.ts +39 -0
- package/dist/internal/sources.d.ts.map +1 -0
- package/dist/internal/sources.js +59 -0
- package/dist/internal/sources.js.map +1 -0
- package/dist/internal/stateRegistry.d.ts +2 -0
- package/dist/internal/stateRegistry.d.ts.map +1 -0
- package/dist/internal/stateRegistry.js +28 -0
- package/dist/internal/stateRegistry.js.map +1 -0
- package/dist/internal/store.d.ts +47 -0
- package/dist/internal/store.d.ts.map +1 -0
- package/dist/internal/store.js +73 -0
- package/dist/internal/store.js.map +1 -0
- package/{src/internal/track.ts → dist/internal/track.d.ts} +11 -15
- package/dist/internal/track.d.ts.map +1 -0
- package/dist/internal/track.js +19 -0
- package/dist/internal/track.js.map +1 -0
- package/dist/procedure/procedure.d.ts +40 -0
- package/dist/procedure/procedure.d.ts.map +1 -0
- package/dist/procedure/procedure.js +50 -0
- package/dist/procedure/procedure.js.map +1 -0
- package/dist/reducer/reducer.d.ts +44 -0
- package/dist/reducer/reducer.d.ts.map +1 -0
- package/dist/reducer/reducer.js +63 -0
- package/dist/reducer/reducer.js.map +1 -0
- package/dist/remote/remoteState.d.ts +119 -0
- package/dist/remote/remoteState.d.ts.map +1 -0
- package/dist/remote/remoteState.js +270 -0
- package/dist/remote/remoteState.js.map +1 -0
- package/dist/runtime/bus.d.ts +27 -0
- package/dist/runtime/bus.d.ts.map +1 -0
- package/{src/runtime/bus.ts → dist/runtime/bus.js} +8 -23
- package/dist/runtime/bus.js.map +1 -0
- package/dist/runtime/loop.d.ts +45 -0
- package/dist/runtime/loop.d.ts.map +1 -0
- package/dist/runtime/loop.js +117 -0
- package/dist/runtime/loop.js.map +1 -0
- package/dist/scene/scene.d.ts +44 -0
- package/dist/scene/scene.d.ts.map +1 -0
- package/dist/scene/scene.js +31 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/state/state.d.ts +37 -0
- package/dist/state/state.d.ts.map +1 -0
- package/dist/state/state.js +46 -0
- package/dist/state/state.js.map +1 -0
- package/dist/state/stateFamily.d.ts +79 -0
- package/dist/state/stateFamily.d.ts.map +1 -0
- package/dist/state/stateFamily.js +99 -0
- package/dist/state/stateFamily.js.map +1 -0
- package/dist/state/stateGroup.d.ts +50 -0
- package/dist/state/stateGroup.d.ts.map +1 -0
- package/dist/state/stateGroup.js +54 -0
- package/dist/state/stateGroup.js.map +1 -0
- package/{src/state/token.ts → dist/state/token.d.ts} +13 -21
- package/dist/state/token.d.ts.map +1 -0
- package/dist/state/token.js +20 -0
- package/dist/state/token.js.map +1 -0
- package/dist/synced/syncedStore.d.ts +51 -0
- package/dist/synced/syncedStore.d.ts.map +1 -0
- package/dist/synced/syncedStore.js +43 -0
- package/dist/synced/syncedStore.js.map +1 -0
- package/{src/ui/node.ts → dist/ui/node.d.ts} +3 -3
- package/dist/ui/node.d.ts.map +1 -0
- package/dist/ui/node.js +2 -0
- package/dist/ui/node.js.map +1 -0
- package/{src/ui/trigger.ts → dist/ui/trigger.d.ts} +2 -1
- package/dist/ui/trigger.d.ts.map +1 -0
- package/dist/ui/trigger.js +2 -0
- package/dist/ui/trigger.js.map +1 -0
- package/dist/wire/tree.d.ts +66 -0
- package/dist/wire/tree.d.ts.map +1 -0
- package/dist/wire/tree.js +60 -0
- package/dist/wire/tree.js.map +1 -0
- package/dist/wire/triggers.d.ts +44 -0
- package/dist/wire/triggers.d.ts.map +1 -0
- package/dist/wire/triggers.js +31 -0
- package/dist/wire/triggers.js.map +1 -0
- package/package.json +32 -11
- package/src/boundary/boundary.ts +0 -192
- package/src/calc/asyncCalc.ts +0 -267
- package/src/calc/calc.ts +0 -120
- package/src/calc/calcFamily.ts +0 -194
- package/src/calc/compose.ts +0 -69
- package/src/channel/channel.ts +0 -265
- package/src/compose/composition.ts +0 -112
- package/src/compose/provide.ts +0 -70
- package/src/compose/ui.ts +0 -97
- package/src/definition/definition.ts +0 -74
- package/src/event/event.ts +0 -65
- package/src/event/eventGroup.ts +0 -14
- package/src/index.ts +0 -140
- package/src/internal/errors.ts +0 -69
- package/src/internal/inspect.ts +0 -34
- package/src/internal/queryDriver.ts +0 -247
- package/src/internal/reuse.ts +0 -73
- package/src/internal/scheduler.ts +0 -91
- package/src/internal/sources.ts +0 -104
- package/src/internal/store.ts +0 -105
- package/src/procedure/procedure.ts +0 -89
- package/src/reducer/reducer.ts +0 -137
- package/src/remote/remoteState.ts +0 -571
- package/src/runtime/loop.ts +0 -169
- package/src/scene/scene.ts +0 -76
- package/src/state/state.ts +0 -91
- package/src/state/stateFamily.ts +0 -171
- package/src/state/stateGroup.ts +0 -78
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Module-load registry of the DI tag identifiers minted by `State.make` /
|
|
4
|
+
* `StateFamily.make`. Two distinct definitions that claim one identifier (e.g.
|
|
5
|
+
* `State.make('open')` in two different features) otherwise collapse silently —
|
|
6
|
+
* `Layer.merge` resolves identical tags to the rightmost, with no error. Here we
|
|
7
|
+
* surface the clash.
|
|
8
|
+
*
|
|
9
|
+
* Warned, not thrown — mirroring duplicate reducer/procedure names: a cross-
|
|
10
|
+
* feature clash is a footgun, but a module may legitimately be re-evaluated under
|
|
11
|
+
* the same identifier (HMR), so a hard throw would punish dev reloads. The
|
|
12
|
+
* `warned` set keeps that to one warning per identifier regardless of reloads.
|
|
13
|
+
* In-group clashes (where every member is addressable by name) are a harder error
|
|
14
|
+
* — see `StateGroup.make`, which throws.
|
|
15
|
+
*/
|
|
16
|
+
const claimed = new Set();
|
|
17
|
+
const warned = new Set();
|
|
18
|
+
export const claimStateTag = (identifier) => {
|
|
19
|
+
if (!claimed.has(identifier)) {
|
|
20
|
+
claimed.add(identifier);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (warned.has(identifier))
|
|
24
|
+
return;
|
|
25
|
+
warned.add(identifier);
|
|
26
|
+
Effect.runSync(Effect.logWarning(`reform: duplicate state tag '${identifier}' — two definitions collide and the last merged wins; namespace the name per feature`));
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=stateRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateRegistry.js","sourceRoot":"","sources":["../../src/internal/stateRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;AACjC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;AAEhC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,UAAkB,EAAQ,EAAE;IACxD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACvB,OAAM;IACR,CAAC;IACD,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;QAAE,OAAM;IAClC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IACtB,MAAM,CAAC,OAAO,CACZ,MAAM,CAAC,UAAU,CACf,gCAAgC,UAAU,sFAAsF,CACjI,CACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Inspectable } from './inspect';
|
|
2
|
+
import { type Scheduler } from './scheduler';
|
|
3
|
+
/**
|
|
4
|
+
* A reactive cell living outside Effect. The single source of truth for one
|
|
5
|
+
* slice of state. `set` is internal: only the reduce loop ever holds a Store
|
|
6
|
+
* (reducers return values, the loop writes them), which is how "state changes
|
|
7
|
+
* only in the reduce loop" is enforced structurally — there is no public writer.
|
|
8
|
+
*
|
|
9
|
+
* This is the synchronous, React-facing analog of Effect's `SubscriptionRef`
|
|
10
|
+
* (a `Ref` + `PubSub` + a `changes` `Stream`). We don't use `SubscriptionRef`
|
|
11
|
+
* directly because `useSyncExternalStore` requires a *synchronous* `getSnapshot`
|
|
12
|
+
* and a *synchronous* `subscribe` returning an unsubscribe thunk, whereas
|
|
13
|
+
* `SubscriptionRef.get` is an `Effect` and its `changes` is a `Stream` (a fiber
|
|
14
|
+
* per subscription). Mutable state is held in a `MutableRef` (Effect's mutable
|
|
15
|
+
* cell), so there is no reassigned binding.
|
|
16
|
+
*
|
|
17
|
+
* `getSnapshot` + `subscribe` are the stable pair the React bridge binds to;
|
|
18
|
+
* `getSnapshot` returns the same reference until the value actually changes.
|
|
19
|
+
* `getVersion` returns a monotonic counter bumped on every real change — the
|
|
20
|
+
* host sums it across a render's tracked stores for a `useSyncExternalStore`
|
|
21
|
+
* snapshot, which closes the tear/dropped-update window a value snapshot can't.
|
|
22
|
+
*/
|
|
23
|
+
export interface Store<in out A> extends Inspectable {
|
|
24
|
+
get(): A;
|
|
25
|
+
set(value: A): void;
|
|
26
|
+
getSnapshot(): A;
|
|
27
|
+
getVersion(): number;
|
|
28
|
+
subscribe(listener: () => void): () => void;
|
|
29
|
+
}
|
|
30
|
+
export declare const makeStore: <A>(initial: A, scheduler?: Scheduler) => Store<A>;
|
|
31
|
+
/**
|
|
32
|
+
* A read-only `Store` whose value is computed from upstream sources.
|
|
33
|
+
*
|
|
34
|
+
* Reads are pull-fresh: `get`/`getSnapshot` call `compute` directly, so a
|
|
35
|
+
* headless snapshot always reflects the current source state without waiting for
|
|
36
|
+
* a notification (`compute` must memoize so an unchanged read returns a stable
|
|
37
|
+
* reference — `useSyncExternalStore` requires it). *Notifications*, by contrast,
|
|
38
|
+
* run through the same coalescing scheduler as `makeStore`: an upstream change
|
|
39
|
+
* recomputes once and wakes subscribers only when the output actually moves (by
|
|
40
|
+
* `Equal.equals`), so every store kind shares one notification timing. `set` is
|
|
41
|
+
* a no-op — the only writer is the upstream subscription.
|
|
42
|
+
*/
|
|
43
|
+
export declare const makeDerivedStore: <A>(compute: () => A, subscribeUpstream: (onChange: () => void) => () => void, scheduler?: Scheduler) => {
|
|
44
|
+
readonly store: Store<A>;
|
|
45
|
+
readonly unsubscribe: () => void;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/internal/store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAe,MAAM,WAAW,CAAA;AACzD,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,aAAa,CAAA;AAE9D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAE,SAAQ,WAAW;IAClD,GAAG,IAAI,CAAC,CAAA;IACR,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACnB,WAAW,IAAI,CAAC,CAAA;IAChB,UAAU,IAAI,MAAM,CAAA;IACpB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;CAC5C;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,SAAS,CAAC,EAAE,YAAW,SAA4B,KAAG,KAAK,CAAC,CAAC,CAwBzF,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAChC,SAAS,MAAM,CAAC,EAChB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,EACvD,YAAW,SAA4B,KACtC;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,IAAI,CAAA;CA8B9D,CAAA"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Equal, MutableRef } from 'effect';
|
|
2
|
+
import { inspectable } from './inspect';
|
|
3
|
+
import { defaultScheduler } from './scheduler';
|
|
4
|
+
export const makeStore = (initial, scheduler = defaultScheduler) => {
|
|
5
|
+
// The store is a mutable reactive slot by design, so its value lives in a
|
|
6
|
+
// `MutableRef` we update in place (no reassigned binding).
|
|
7
|
+
const value = MutableRef.make(initial);
|
|
8
|
+
const version = MutableRef.make(0);
|
|
9
|
+
const listeners = new Set();
|
|
10
|
+
return {
|
|
11
|
+
get: () => MutableRef.get(value),
|
|
12
|
+
getSnapshot: () => MutableRef.get(value),
|
|
13
|
+
getVersion: () => MutableRef.get(version),
|
|
14
|
+
set: (next) => {
|
|
15
|
+
if (Equal.equals(MutableRef.get(value), next))
|
|
16
|
+
return;
|
|
17
|
+
MutableRef.set(value, next);
|
|
18
|
+
MutableRef.update(version, (n) => n + 1);
|
|
19
|
+
scheduler.schedule(listeners);
|
|
20
|
+
},
|
|
21
|
+
subscribe: (listener) => {
|
|
22
|
+
listeners.add(listener);
|
|
23
|
+
return () => {
|
|
24
|
+
listeners.delete(listener);
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
...inspectable(() => ({ _id: 'reform/Store', value: MutableRef.get(value) })),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A read-only `Store` whose value is computed from upstream sources.
|
|
32
|
+
*
|
|
33
|
+
* Reads are pull-fresh: `get`/`getSnapshot` call `compute` directly, so a
|
|
34
|
+
* headless snapshot always reflects the current source state without waiting for
|
|
35
|
+
* a notification (`compute` must memoize so an unchanged read returns a stable
|
|
36
|
+
* reference — `useSyncExternalStore` requires it). *Notifications*, by contrast,
|
|
37
|
+
* run through the same coalescing scheduler as `makeStore`: an upstream change
|
|
38
|
+
* recomputes once and wakes subscribers only when the output actually moves (by
|
|
39
|
+
* `Equal.equals`), so every store kind shares one notification timing. `set` is
|
|
40
|
+
* a no-op — the only writer is the upstream subscription.
|
|
41
|
+
*/
|
|
42
|
+
export const makeDerivedStore = (compute, subscribeUpstream, scheduler = defaultScheduler) => {
|
|
43
|
+
const listeners = new Set();
|
|
44
|
+
const version = MutableRef.make(0);
|
|
45
|
+
// The last output we notified against — tracked only here, never touched by
|
|
46
|
+
// reads, so a `get` racing ahead of `onChange` can't suppress a notification.
|
|
47
|
+
const seen = MutableRef.make({ value: compute() });
|
|
48
|
+
const onChange = () => {
|
|
49
|
+
const previous = MutableRef.get(seen);
|
|
50
|
+
const next = compute();
|
|
51
|
+
MutableRef.set(seen, { value: next });
|
|
52
|
+
if (previous === undefined || !Equal.equals(previous.value, next)) {
|
|
53
|
+
MutableRef.update(version, (n) => n + 1);
|
|
54
|
+
scheduler.schedule(listeners);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const unsubscribe = subscribeUpstream(onChange);
|
|
58
|
+
const store = {
|
|
59
|
+
get: compute,
|
|
60
|
+
getSnapshot: compute,
|
|
61
|
+
getVersion: () => MutableRef.get(version),
|
|
62
|
+
set: () => { },
|
|
63
|
+
subscribe: (listener) => {
|
|
64
|
+
listeners.add(listener);
|
|
65
|
+
return () => {
|
|
66
|
+
listeners.delete(listener);
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
...inspectable(() => ({ _id: 'reform/Store', value: compute() })),
|
|
70
|
+
};
|
|
71
|
+
return { store, unsubscribe };
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0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IAC/C,MAAM,KAAK,GAAa;QACtB,GAAG,EAAE,OAAO;QACZ,WAAW,EAAE,OAAO;QACpB,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC;QACzC,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;QACb,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC,CAAA;QACH,CAAC;QACD,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;KAClE,CAAA;IACD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAA;AAC/B,CAAC,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Context, Effect
|
|
2
|
-
import type { Store } from './store'
|
|
3
|
-
|
|
1
|
+
import { Context, Effect } from 'effect';
|
|
2
|
+
import type { Store } from './store';
|
|
4
3
|
/**
|
|
5
4
|
* Anything a render can depend on: a source it can subscribe to for changes and
|
|
6
5
|
* snapshot a monotonic version from. `Store` (and the calc/family stores)
|
|
@@ -10,28 +9,25 @@ import type { Store } from './store'
|
|
|
10
9
|
* window a per-store value snapshot cannot.
|
|
11
10
|
*/
|
|
12
11
|
export interface Subscribable {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
subscribe(listener: () => void): () => void;
|
|
13
|
+
getVersion(): number;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
/** A per-render dependency sink. The renderer provides one; reads record into it. */
|
|
18
16
|
export interface Tracker {
|
|
19
|
-
|
|
17
|
+
add(source: Subscribable): void;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
/**
|
|
23
20
|
* The active render's dependency tracker (D5). Present only while a composition
|
|
24
21
|
* is rendering under `@reform/react`; absent in procedures and headless reads.
|
|
25
22
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
declare const CurrentTrackerBase: Context.TagClass<CurrentTracker, 'reform/Tracker', Tracker>;
|
|
24
|
+
export declare class CurrentTracker extends CurrentTrackerBase {
|
|
25
|
+
}
|
|
28
26
|
/**
|
|
29
27
|
* Read a store's current snapshot and, if a tracker is active, record the store
|
|
30
28
|
* as a dependency of the current render. One read API, two behaviors by context
|
|
31
29
|
* (D5): inside a render it subscribes the slice; elsewhere it just snapshots.
|
|
32
30
|
*/
|
|
33
|
-
export const readTracked
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return store.getSnapshot()
|
|
37
|
-
})
|
|
31
|
+
export declare const readTracked: <A>(store: Store<A>) => Effect.Effect<A>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=track.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../../src/internal/track.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;IAC3C,UAAU,IAAI,MAAM,CAAA;CACrB;AAED,qFAAqF;AACrF,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;CAChC;AAED;;;GAGG;AACH,QAAA,MAAM,kBAAkB,EAAE,OAAO,CAAC,QAAQ,CAAC,cAAc,EAAE,gBAAgB,EAAE,OAAO,CAC1B,CAAA;AAC1D,qBAAa,cAAe,SAAQ,kBAAkB;CAAG;AAEzD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAI5D,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context, Effect, Option } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* The active render's dependency tracker (D5). Present only while a composition
|
|
4
|
+
* is rendering under `@reform/react`; absent in procedures and headless reads.
|
|
5
|
+
*/
|
|
6
|
+
const CurrentTrackerBase = Context.Tag('reform/Tracker')();
|
|
7
|
+
export class CurrentTracker extends CurrentTrackerBase {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Read a store's current snapshot and, if a tracker is active, record the store
|
|
11
|
+
* as a dependency of the current render. One read API, two behaviors by context
|
|
12
|
+
* (D5): inside a render it subscribes the slice; elsewhere it just snapshots.
|
|
13
|
+
*/
|
|
14
|
+
export const readTracked = (store) => Effect.map(Effect.serviceOption(CurrentTracker), (tracker) => {
|
|
15
|
+
if (Option.isSome(tracker))
|
|
16
|
+
tracker.value.add(store);
|
|
17
|
+
return store.getSnapshot();
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=track.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track.js","sourceRoot":"","sources":["../../src/internal/track.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAqBhD;;;GAGG;AACH,MAAM,kBAAkB,GACtB,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAA2B,CAAA;AAC1D,MAAM,OAAO,cAAe,SAAQ,kBAAkB;CAAG;AAEzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAI,KAAe,EAAoB,EAAE,CAClE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE;IAC3D,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACpD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAA;AAC5B,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Effect, Layer } from 'effect';
|
|
2
|
+
import type { YieldWrap } from 'effect/Utils';
|
|
3
|
+
import { type ChannelClass, Procedures } from '../channel/channel';
|
|
4
|
+
import { type Manifest } from '../definition/definition';
|
|
5
|
+
import { type AnyEvent, type EventType } from '../event/event';
|
|
6
|
+
import { type Ctx } from '../internal/ctx';
|
|
7
|
+
import { Bus } from '../runtime/bus';
|
|
8
|
+
/** The reflectable descriptor a procedure carries. */
|
|
9
|
+
export interface ProcedureManifest extends Manifest {
|
|
10
|
+
readonly kind: 'Procedure';
|
|
11
|
+
}
|
|
12
|
+
export interface ProcedureClass<Events extends ReadonlyArray<AnyEvent>> {
|
|
13
|
+
new (): {};
|
|
14
|
+
readonly manifest: ProcedureManifest;
|
|
15
|
+
/** The trigger events (marker data; read by `Procedure.live`). */
|
|
16
|
+
readonly events: Events;
|
|
17
|
+
/** The channel this procedure's runs are scheduled on (marker data). */
|
|
18
|
+
readonly channel: ChannelClass;
|
|
19
|
+
}
|
|
20
|
+
export interface ProcedureConfig<Events extends ReadonlyArray<AnyEvent>> {
|
|
21
|
+
readonly events: Events;
|
|
22
|
+
/** The scheduling lane. Replaces the old `concurrency` option. */
|
|
23
|
+
readonly channel: ChannelClass;
|
|
24
|
+
}
|
|
25
|
+
export type AnyProcedure = ProcedureClass<ReadonlyArray<AnyEvent>>;
|
|
26
|
+
/**
|
|
27
|
+
* A cross-event-loop flow. The *definition* declares its trigger events and the
|
|
28
|
+
* channel it runs on; the *implementation* is the effectful body. Procedures no
|
|
29
|
+
* longer subscribe to the bus themselves — the single drain loop routes events
|
|
30
|
+
* to the channel, which runs the registered bodies under its policy.
|
|
31
|
+
*/
|
|
32
|
+
export declare const make: <const Events extends ReadonlyArray<AnyEvent>>(name: string, config: ProcedureConfig<Events>) => ProcedureClass<Events>;
|
|
33
|
+
/**
|
|
34
|
+
* Register the flow body into its channel. The body may read state and dispatch
|
|
35
|
+
* events, but never writes state (the core invariant); its context requirements
|
|
36
|
+
* (RPC clients, etc.) are captured here so the channel fiber can run it with no
|
|
37
|
+
* outstanding R.
|
|
38
|
+
*/
|
|
39
|
+
export declare const live: <Events extends ReadonlyArray<AnyEvent>, Eff extends YieldWrap<Effect.Effect<any, any, any>>, Done>(procedure: ProcedureClass<Events>, body: (event: EventType<Events[number]>) => Generator<Eff, Done, never>) => Layer.Layer<never, never, Procedures | Bus | Ctx<Eff>>;
|
|
40
|
+
//# sourceMappingURL=procedure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../../src/procedure/procedure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,KAAK,YAAY,EAAuB,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACvF,OAAO,EAAE,KAAK,QAAQ,EAAmB,MAAM,0BAA0B,CAAA;AACzE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,GAAG,EAAiB,MAAM,gBAAgB,CAAA;AAEnD,sDAAsD;AACtD,MAAM,WAAW,iBAAkB,SAAQ,QAAQ;IACjD,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,aAAa,CAAC,QAAQ,CAAC;IACpE,QAAQ,EAAE,CAAA;IACV,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;CAC/B;AAED,MAAM,WAAW,eAAe,CAAC,MAAM,SAAS,aAAa,CAAC,QAAQ,CAAC;IACrE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;CAC/B;AAED,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAA;AAElE;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,CAAC,MAAM,SAAS,aAAa,CAAC,QAAQ,CAAC,EAC/D,MAAM,MAAM,EACZ,QAAQ,eAAe,CAAC,MAAM,CAAC,KAC9B,cAAc,CAAC,MAAM,CAKpB,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GACf,MAAM,SAAS,aAAa,CAAC,QAAQ,CAAC,EACtC,GAAG,SAAS,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,EACnD,IAAI,EAEJ,WAAW,cAAc,CAAC,MAAM,CAAC,EACjC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,KACtE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CA6BvD,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Effect, Layer } from 'effect';
|
|
2
|
+
import { Procedures } from '../channel/channel';
|
|
3
|
+
import { definitionClass } from '../definition/definition';
|
|
4
|
+
import {} from '../event/event';
|
|
5
|
+
import {} from '../internal/ctx';
|
|
6
|
+
import { Bus, narrowHandled } from '../runtime/bus';
|
|
7
|
+
/**
|
|
8
|
+
* A cross-event-loop flow. The *definition* declares its trigger events and the
|
|
9
|
+
* channel it runs on; the *implementation* is the effectful body. Procedures no
|
|
10
|
+
* longer subscribe to the bus themselves — the single drain loop routes events
|
|
11
|
+
* to the channel, which runs the registered bodies under its policy.
|
|
12
|
+
*/
|
|
13
|
+
export const make = (name, config) => definitionClass({
|
|
14
|
+
manifest: { kind: 'Procedure', name },
|
|
15
|
+
events: config.events,
|
|
16
|
+
channel: config.channel,
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Register the flow body into its channel. The body may read state and dispatch
|
|
20
|
+
* events, but never writes state (the core invariant); its context requirements
|
|
21
|
+
* (RPC clients, etc.) are captured here so the channel fiber can run it with no
|
|
22
|
+
* outstanding R.
|
|
23
|
+
*/
|
|
24
|
+
export const live = (procedure, body) => {
|
|
25
|
+
const name = procedure.manifest.name;
|
|
26
|
+
const channelName = procedure.channel.manifest.name;
|
|
27
|
+
const handles = new Set(procedure.events.map((e) => e.tag));
|
|
28
|
+
// Scoped registration (see `Reducer.live`): an eager procedure's scope is the
|
|
29
|
+
// root runtime's, so behavior is unchanged; a lazy feature's procedure registers
|
|
30
|
+
// on mount and unregisters on unmount, so it stops running and is reclaimed.
|
|
31
|
+
return Layer.scopedDiscard(Effect.gen(function* () {
|
|
32
|
+
const procedures = yield* Procedures;
|
|
33
|
+
if (procedures.entries.some((e) => e.name === name)) {
|
|
34
|
+
yield* Effect.logWarning(`reform: duplicate procedure name '${name}' registered`);
|
|
35
|
+
}
|
|
36
|
+
// Snapshot the body's full context (Bus + RPC clients) so `run` is total.
|
|
37
|
+
const runtime = yield* Effect.runtime();
|
|
38
|
+
const entry = {
|
|
39
|
+
name,
|
|
40
|
+
channelName,
|
|
41
|
+
// The channel only routes events whose tag is in `handles`, so at runtime
|
|
42
|
+
// `event` is always one of `Events`; `narrowHandled` restores the body's
|
|
43
|
+
// declared event union from the erased `Tagged` envelope.
|
|
44
|
+
handles,
|
|
45
|
+
run: (event) => Effect.provide(Effect.gen(() => body(narrowHandled(event))), runtime),
|
|
46
|
+
};
|
|
47
|
+
yield* Effect.acquireRelease(Effect.sync(() => procedures.register(entry)), () => Effect.sync(() => procedures.unregister(entry)));
|
|
48
|
+
}));
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=procedure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../../src/procedure/procedure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEtC,OAAO,EAA0C,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACvF,OAAO,EAAiB,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACzE,OAAO,EAAiC,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAY,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAwBnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,IAAY,EACZ,MAA+B,EACP,EAAE,CAC1B,eAAe,CAAyB;IACtC,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAoB,EAAE,IAAI,EAA8B;IAC1E,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC,OAAO;CACxB,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAKlB,SAAiC,EACjC,IAAuE,EACf,EAAE;IAC1D,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAA;IACpC,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAA;IACnD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,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|
+
import { type Manifest } from '../definition/definition';
|
|
3
|
+
import { type AnyEvent, type EventType } from '../event/event';
|
|
4
|
+
import type { Store } from '../internal/store';
|
|
5
|
+
import { type AnyState, type StateValue } from '../state/state';
|
|
6
|
+
import { type AnyFamily, type FamilyKey, type FamilyStore, type FamilyValue, Tombstone } from '../state/stateFamily';
|
|
7
|
+
import { Reducers } from '../runtime/loop';
|
|
8
|
+
/** The reflectable descriptor a reducer carries, like every other primitive's `*Manifest`. */
|
|
9
|
+
export interface ReducerManifest extends Manifest {
|
|
10
|
+
readonly kind: 'Reducer';
|
|
11
|
+
}
|
|
12
|
+
export interface StateReducerConfig<S extends AnyState, Events extends ReadonlyArray<AnyEvent>> {
|
|
13
|
+
readonly states: readonly [S];
|
|
14
|
+
readonly events: Events;
|
|
15
|
+
}
|
|
16
|
+
export interface FamilyReducerConfig<F extends AnyFamily, Events extends ReadonlyArray<AnyEvent>> {
|
|
17
|
+
readonly family: F;
|
|
18
|
+
readonly keyOf: (event: EventType<Events[number]>) => FamilyKey<F>;
|
|
19
|
+
readonly events: Events;
|
|
20
|
+
}
|
|
21
|
+
export interface StateReducerClass<S extends AnyState, Events extends ReadonlyArray<AnyEvent>> {
|
|
22
|
+
new (): {};
|
|
23
|
+
readonly manifest: ReducerManifest;
|
|
24
|
+
/** Marker data read by `Reducer.live`. */
|
|
25
|
+
readonly config: StateReducerConfig<S, Events>;
|
|
26
|
+
readonly handles: ReadonlySet<string>;
|
|
27
|
+
}
|
|
28
|
+
export interface FamilyReducerClass<F extends AnyFamily, Events extends ReadonlyArray<AnyEvent>> {
|
|
29
|
+
new (): {};
|
|
30
|
+
readonly manifest: ReducerManifest;
|
|
31
|
+
readonly config: FamilyReducerConfig<F, Events>;
|
|
32
|
+
readonly handles: ReadonlySet<string>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reducers are the only writers of state. The *definition* (`Reducer.make`)
|
|
36
|
+
* declares which state and events it touches; the *implementation*
|
|
37
|
+
* (`Reducer.live`) is the pure fold. An unhandled event is a no-op because
|
|
38
|
+
* it is never in `handles`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function make<S extends AnyState, const Events extends ReadonlyArray<AnyEvent>>(name: string, config: StateReducerConfig<S, Events>): StateReducerClass<S, Events>;
|
|
41
|
+
export declare function make<F extends AnyFamily, const Events extends ReadonlyArray<AnyEvent>>(name: string, config: FamilyReducerConfig<F, Events>): FamilyReducerClass<F, Events>;
|
|
42
|
+
export declare function live<S extends AnyState, Events extends ReadonlyArray<AnyEvent>>(reducer: StateReducerClass<S, Events>, fold: (value: StateValue<S>, event: EventType<Events[number]>) => StateValue<S>): Layer.Layer<never, never, Reducers | Store<StateValue<S>>>;
|
|
43
|
+
export declare function live<F extends AnyFamily, Events extends ReadonlyArray<AnyEvent>>(reducer: FamilyReducerClass<F, Events>, fold: (entry: FamilyValue<F>, event: EventType<Events[number]>) => FamilyValue<F> | Tombstone): Layer.Layer<never, never, Reducers | FamilyStore<FamilyKey<F>, FamilyValue<F>>>;
|
|
44
|
+
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/reducer/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,KAAK,QAAQ,EAAmB,MAAM,0BAA0B,CAAA;AAEzE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EACL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,SAAS,EACV,MAAM,sBAAsB,CAAA;AAE7B,OAAO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AAC,KAAK,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,GAC5F,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Effect, Layer } from 'effect';
|
|
2
|
+
import { definitionClass } from '../definition/definition';
|
|
3
|
+
import { AsyncReducer } from '../internal/errors';
|
|
4
|
+
import {} from '../event/event';
|
|
5
|
+
import {} from '../state/state';
|
|
6
|
+
import { Tombstone, } from '../state/stateFamily';
|
|
7
|
+
import { narrowHandled } from '../runtime/bus';
|
|
8
|
+
import { Reducers } from '../runtime/loop';
|
|
9
|
+
export function make(name, config) {
|
|
10
|
+
return definitionClass({
|
|
11
|
+
manifest: { kind: 'Reducer', name },
|
|
12
|
+
config,
|
|
13
|
+
handles: new Set(config.events.map((e) => e.tag)),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** Reject an accidentally-async fold up front: a reducer must be a pure sync write. */
|
|
17
|
+
const sync = (value) => {
|
|
18
|
+
// Loose `!= null` so a reducer returning `undefined` doesn't crash the guard.
|
|
19
|
+
if (value != null && typeof value.then === 'function') {
|
|
20
|
+
throw new AsyncReducer();
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
export function live(reducer, fold) {
|
|
25
|
+
const { config, handles } = reducer;
|
|
26
|
+
const name = reducer.manifest.name;
|
|
27
|
+
// Scoped registration: register on build, unregister on scope close. For an eager
|
|
28
|
+
// app the scope is the root runtime's (closes only at dispose), so behavior is
|
|
29
|
+
// unchanged; for a lazy feature the scope is the feature's, so unmount removes the
|
|
30
|
+
// entry — it stops folding and is reclaimed instead of leaking onto a dead store.
|
|
31
|
+
return Layer.scopedDiscard(Effect.gen(function* () {
|
|
32
|
+
const reducers = yield* Reducers;
|
|
33
|
+
if (reducers.entries.some((e) => e.name === name)) {
|
|
34
|
+
yield* Effect.logWarning(`reform: duplicate reducer name '${name}' registered`);
|
|
35
|
+
}
|
|
36
|
+
const entry = yield* Effect.gen(function* () {
|
|
37
|
+
if ('family' in config) {
|
|
38
|
+
const family = yield* config.family.store;
|
|
39
|
+
return {
|
|
40
|
+
name,
|
|
41
|
+
handles,
|
|
42
|
+
apply: (event) => {
|
|
43
|
+
// The loop only invokes `apply` for events in `handles`, so `event`
|
|
44
|
+
// is one of this reducer's declared events; `narrowHandled` restores
|
|
45
|
+
// that typed view from the erased `Tagged` envelope `keyOf` is fed.
|
|
46
|
+
const key = config.keyOf(narrowHandled(event));
|
|
47
|
+
const next = fold(family.at(key).get(), event);
|
|
48
|
+
// A fold may return the eviction sentinel to drop the key's store
|
|
49
|
+
// (bounding an otherwise-unbounded family) instead of a new value.
|
|
50
|
+
if (next === Tombstone)
|
|
51
|
+
family.forget(key);
|
|
52
|
+
else
|
|
53
|
+
family.at(key).set(sync(next));
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const store = yield* config.states[0].store;
|
|
58
|
+
return { name, handles, apply: (event) => store.set(sync(fold(store.get(), event))) };
|
|
59
|
+
});
|
|
60
|
+
yield* Effect.acquireRelease(Effect.sync(() => reducers.register(entry)), () => Effect.sync(() => reducers.unregister(entry)));
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.js","sourceRoot":"","sources":["../../src/reducer/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAiB,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAiC,MAAM,gBAAgB,CAAA;AAE9D,OAAO,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AM,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAC7E,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAC9C,CAAA;IACH,CAAC,CAAC,CACH,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from 'effect';
|
|
2
|
+
import { AsyncData } from '../calc/asyncData';
|
|
3
|
+
import * as Channel from '../channel/channel';
|
|
4
|
+
import { type Manifest } from '../definition/definition';
|
|
5
|
+
import * as Event from '../event/event';
|
|
6
|
+
import { type GatedOf } from '../internal/queryDriver';
|
|
7
|
+
import { type InputsObject, type InputStores, type InvalidateBy } from '../internal/sources';
|
|
8
|
+
import { type Store } from '../internal/store';
|
|
9
|
+
import { Bus } from '../runtime/bus';
|
|
10
|
+
import { Reducers } from '../runtime/loop';
|
|
11
|
+
import { type AnySource, StateToken } from '../state/token';
|
|
12
|
+
/** One queued intent: the dispatched event value plus the lifecycle metadata. */
|
|
13
|
+
export interface PendingIntent<I> {
|
|
14
|
+
readonly opId: string;
|
|
15
|
+
/** The dispatched intent event (`{ _tag, ...payload }`). */
|
|
16
|
+
readonly intent: I;
|
|
17
|
+
/** `'sending'` until the RPC acks; `'confirmed'` until the post-ack refetch lands. */
|
|
18
|
+
readonly status: 'sending' | 'confirmed';
|
|
19
|
+
}
|
|
20
|
+
/** The payload of the public `Failed` event: which intent, and what `send` raised. */
|
|
21
|
+
export interface FailedIntent<I> {
|
|
22
|
+
readonly intent: I;
|
|
23
|
+
readonly error: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface RemoteStateManifest<N extends string, A, E> extends Manifest {
|
|
26
|
+
readonly kind: 'RemoteState';
|
|
27
|
+
readonly name: N;
|
|
28
|
+
/** Schema of the server value (`Success` arm / `apply`'s domain). */
|
|
29
|
+
readonly output: Schema.Schema<A, any>;
|
|
30
|
+
readonly error?: Schema.Schema<E, any>;
|
|
31
|
+
/** Whether the query can be disabled (drives the `Idle` arm). */
|
|
32
|
+
readonly gated: boolean;
|
|
33
|
+
/** The mutation vocabulary — intent event tags, reflectable without running logic. */
|
|
34
|
+
readonly intents: ReadonlyArray<string>;
|
|
35
|
+
}
|
|
36
|
+
export interface RemoteStateClass<out N extends string, out Inputs extends ReadonlyArray<AnySource>, in out Intents extends ReadonlyArray<Event.AnyEvent>, in out A, in out E, in out Gated extends boolean> extends Effect.Effect<AsyncData<A, E, Gated>, never, Store<AsyncData<A, E, Gated>>> {
|
|
37
|
+
new (): {};
|
|
38
|
+
readonly manifest: RemoteStateManifest<N, A, E>;
|
|
39
|
+
/** The OVERLAID view (`pending.reduce(apply, truth)`) — what `yield*` reads. */
|
|
40
|
+
readonly store: Context.Tag<Store<AsyncData<A, E, Gated>>, Store<AsyncData<A, E, Gated>>>;
|
|
41
|
+
/** The name, so the class doubles as a `Source` input to another calc. */
|
|
42
|
+
readonly name: N;
|
|
43
|
+
/** Marker data read by `RemoteState.live`. */
|
|
44
|
+
readonly inputs: Inputs;
|
|
45
|
+
/** The intent event definitions (marker data; read by `RemoteState.live`). */
|
|
46
|
+
readonly intents: Intents;
|
|
47
|
+
/** Runtime mirror of `Gated`: whether `disabled` is honored / `Idle` can occur. */
|
|
48
|
+
readonly gated: Gated;
|
|
49
|
+
/** The un-overlaid query lifecycle — for chrome that must show server truth. */
|
|
50
|
+
readonly truth: StateToken<`${N}/truth`, AsyncData<A, E, Gated>>;
|
|
51
|
+
/**
|
|
52
|
+
* The pending queue as a read-only `Source` (badges, "saving…" chrome). Not a
|
|
53
|
+
* `StateClass`, so no user reducer can target it — the hidden queue reducer
|
|
54
|
+
* is its sole writer.
|
|
55
|
+
*/
|
|
56
|
+
readonly pending: StateToken<`${N}/pending`, ReadonlyArray<PendingIntent<Event.EventType<Intents[number]>>>>;
|
|
57
|
+
/** Public fact: a send failed; its intent left the queue and the view reverted. */
|
|
58
|
+
readonly Failed: Event.EventClass<`${N}/Failed`, FailedIntent<Event.EventType<Intents[number]>>>;
|
|
59
|
+
}
|
|
60
|
+
export interface RemoteStateConfig<Inputs extends ReadonlyArray<AnySource>, Intents extends ReadonlyArray<Event.AnyEvent>, A, E, AlwaysOn extends boolean> {
|
|
61
|
+
readonly inputs: Inputs;
|
|
62
|
+
/** Schema of the server value. */
|
|
63
|
+
readonly output: Schema.Schema<A, any>;
|
|
64
|
+
/** Schema of the query failure. Omitted ⇒ infallible query, no `Error` arm. */
|
|
65
|
+
readonly error?: Schema.Schema<E, any>;
|
|
66
|
+
/** `true` ⇒ the query is always on: no `Idle` arm and `disabled` is rejected on `.live`. */
|
|
67
|
+
readonly alwaysOn?: AlwaysOn;
|
|
68
|
+
/** The mutation vocabulary: ordinary `Event.make` definitions. */
|
|
69
|
+
readonly intents: Intents;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Define a remote state: a query (like `AsyncCalc.make`) plus the intent
|
|
73
|
+
* events that mutate it. `yield* TheClass` reads the overlaid view;
|
|
74
|
+
* `TheClass.truth` / `TheClass.pending` / `TheClass.Failed` expose the rest of
|
|
75
|
+
* the surface. The query/send/apply logic is supplied by `RemoteState.live`.
|
|
76
|
+
*/
|
|
77
|
+
export declare const make: <const N extends string, const Inputs extends ReadonlyArray<AnySource>, const Intents extends ReadonlyArray<Event.AnyEvent>, A, E = never, const AlwaysOn extends boolean = false>(name: N, config: RemoteStateConfig<Inputs, Intents, A, E, AlwaysOn>) => RemoteStateClass<N, Inputs, Intents, A, E, GatedOf<AlwaysOn>>;
|
|
78
|
+
/**
|
|
79
|
+
* The `.live` config: the query (same contract as `AsyncCalc.live`), the
|
|
80
|
+
* delivery effect, and the pure per-intent fold.
|
|
81
|
+
*/
|
|
82
|
+
export type RemoteStateLive<Inputs extends ReadonlyArray<AnySource>, Intents extends ReadonlyArray<Event.AnyEvent>, A, E, Gated extends boolean, R, R2> = {
|
|
83
|
+
readonly query: (inputs: InputsObject<Inputs>) => Effect.Effect<A, E, R>;
|
|
84
|
+
/**
|
|
85
|
+
* Deliver one intent to the server. ANY failure (typed failure or defect)
|
|
86
|
+
* settles the intent and dispatches `Failed`; the result value is ignored —
|
|
87
|
+
* truth comes back through the invalidated query, never through the response.
|
|
88
|
+
*/
|
|
89
|
+
readonly send: (intent: Event.EventType<Intents[number]>) => Effect.Effect<unknown, unknown, R2>;
|
|
90
|
+
/**
|
|
91
|
+
* The pure per-intent fold over the server value (typically one
|
|
92
|
+
* `Match.exhaustive` over the intent union). MUST be idempotent against
|
|
93
|
+
* truth that already carries the intent — see the module doc.
|
|
94
|
+
*/
|
|
95
|
+
readonly apply: (value: A, intent: Event.EventType<Intents[number]>) => A;
|
|
96
|
+
/** The send lane. Default: a generated `${name}/sends` merge channel. */
|
|
97
|
+
readonly channel?: Channel.ChannelClass;
|
|
98
|
+
readonly invalidateBy?: InvalidateBy<Inputs>;
|
|
99
|
+
/** Extra refetch triggers (realtime pushes, unrelated mutations) — `AsyncCalc`'s sugar. */
|
|
100
|
+
readonly invalidateOn?: ReadonlyArray<Event.AnyEvent>;
|
|
101
|
+
/** Refetch conciliation — see `AsyncCalc.live`. Mutation bursts favor `'trailing'`. */
|
|
102
|
+
readonly coalesce?: 'switch' | 'trailing';
|
|
103
|
+
/** Structural sharing across refetches AND overlay recomputes — see `AsyncCalc.live`. */
|
|
104
|
+
readonly reuse?: boolean;
|
|
105
|
+
} & (Gated extends true ? {
|
|
106
|
+
readonly disabled?: (inputs: InputsObject<Inputs>) => boolean;
|
|
107
|
+
} : {
|
|
108
|
+
readonly disabled?: never;
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Wire a remote state: the query driver (truth), the overlay (visible view),
|
|
112
|
+
* the hidden queue reducer, the send procedure, and the settle link between
|
|
113
|
+
* them — one layer. Hidden names minted per call, namespaced by the remote
|
|
114
|
+
* state's name: events `…/Queued`/`…/Acked`/`…/Settled`/`…/Invalidated`, state
|
|
115
|
+
* `…/revision`, reducers `…/pending`/`…/revision`, procedure `…/send`, default
|
|
116
|
+
* channel `…/sends`.
|
|
117
|
+
*/
|
|
118
|
+
export declare const live: <N extends string, Inputs extends ReadonlyArray<AnySource>, Intents extends ReadonlyArray<Event.AnyEvent>, A, E, Gated extends boolean, R, R2>(remote: RemoteStateClass<N, Inputs, Intents, A, E, Gated>, config: RemoteStateLive<Inputs, Intents, A, E, Gated, R, R2>) => Layer.Layer<Store<AsyncData<A, E, Gated>> | Store<ReadonlyArray<PendingIntent<Event.EventType<Intents[number]>>>>, never, InputStores<Inputs> | R | R2 | Reducers | Channel.Procedures | Channel.Channels | Bus>;
|
|
119
|
+
//# sourceMappingURL=remoteState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteState.d.ts","sourceRoot":"","sources":["../../src/remote/remoteState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAU,KAAK,EAA+B,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC5F,OAAO,EAAqB,SAAS,EAA2B,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,0BAA0B,CAAA;AACxE,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAEL,KAAK,OAAO,EAKb,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAA+B,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG3E,OAAO,EAAE,GAAG,EAA0B,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAqB,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE7D,OAAO,EAAE,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