@fluixi/reactive 1.0.0-alpha.53
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/LICENSE +21 -0
- package/README.md +343 -0
- package/dist/cdn/reactive.cjs +1 -0
- package/dist/cdn/reactive.d.ts +11 -0
- package/dist/cdn/reactive.d.ts.map +1 -0
- package/dist/cdn/reactive.global.js +1 -0
- package/dist/cdn/reactive.js +10 -0
- package/dist/cdn/reactive.mjs +1 -0
- package/dist/cdn/signal.cjs +1 -0
- package/dist/cdn/signal.d.ts +19 -0
- package/dist/cdn/signal.d.ts.map +1 -0
- package/dist/cdn/signal.global.js +1 -0
- package/dist/cdn/signal.js +18 -0
- package/dist/cdn/signal.mjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/lib/index.cjs +1 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +4 -0
- package/dist/lib/index.mjs +1 -0
- package/dist/lib/observable/index.cjs +1 -0
- package/dist/lib/observable/index.d.ts +4 -0
- package/dist/lib/observable/index.d.ts.map +1 -0
- package/dist/lib/observable/index.js +3 -0
- package/dist/lib/observable/index.mjs +1 -0
- package/dist/lib/observable/observable.cjs +1 -0
- package/dist/lib/observable/observable.d.ts +383 -0
- package/dist/lib/observable/observable.d.ts.map +1 -0
- package/dist/lib/observable/observable.js +339 -0
- package/dist/lib/observable/observable.mjs +1 -0
- package/dist/lib/observable/subscription.cjs +1 -0
- package/dist/lib/observable/subscription.d.ts +70 -0
- package/dist/lib/observable/subscription.d.ts.map +1 -0
- package/dist/lib/observable/subscription.js +190 -0
- package/dist/lib/observable/subscription.mjs +1 -0
- package/dist/lib/observable/types.cjs +1 -0
- package/dist/lib/observable/types.d.ts +44 -0
- package/dist/lib/observable/types.d.ts.map +1 -0
- package/dist/lib/observable/types.js +1 -0
- package/dist/lib/observable/types.mjs +0 -0
- package/dist/lib/signal/cached-resource.cjs +1 -0
- package/dist/lib/signal/cached-resource.d.ts +94 -0
- package/dist/lib/signal/cached-resource.d.ts.map +1 -0
- package/dist/lib/signal/cached-resource.js +257 -0
- package/dist/lib/signal/cached-resource.mjs +1 -0
- package/dist/lib/signal/graph/children.cjs +1 -0
- package/dist/lib/signal/graph/children.d.ts +2 -0
- package/dist/lib/signal/graph/children.d.ts.map +1 -0
- package/dist/lib/signal/graph/children.js +30 -0
- package/dist/lib/signal/graph/children.mjs +1 -0
- package/dist/lib/signal/graph/compat.cjs +1 -0
- package/dist/lib/signal/graph/compat.d.ts +64 -0
- package/dist/lib/signal/graph/compat.d.ts.map +1 -0
- package/dist/lib/signal/graph/compat.js +178 -0
- package/dist/lib/signal/graph/compat.mjs +1 -0
- package/dist/lib/signal/graph/core.cjs +1 -0
- package/dist/lib/signal/graph/core.d.ts +95 -0
- package/dist/lib/signal/graph/core.d.ts.map +1 -0
- package/dist/lib/signal/graph/core.js +254 -0
- package/dist/lib/signal/graph/core.mjs +1 -0
- package/dist/lib/signal/graph/derived.cjs +1 -0
- package/dist/lib/signal/graph/derived.d.ts +14 -0
- package/dist/lib/signal/graph/derived.d.ts.map +1 -0
- package/dist/lib/signal/graph/derived.js +81 -0
- package/dist/lib/signal/graph/derived.mjs +1 -0
- package/dist/lib/signal/graph/detect.cjs +1 -0
- package/dist/lib/signal/graph/detect.d.ts +16 -0
- package/dist/lib/signal/graph/detect.d.ts.map +1 -0
- package/dist/lib/signal/graph/detect.js +36 -0
- package/dist/lib/signal/graph/detect.mjs +1 -0
- package/dist/lib/signal/graph/error-boundary.cjs +1 -0
- package/dist/lib/signal/graph/error-boundary.d.ts +16 -0
- package/dist/lib/signal/graph/error-boundary.d.ts.map +1 -0
- package/dist/lib/signal/graph/error-boundary.js +34 -0
- package/dist/lib/signal/graph/error-boundary.mjs +1 -0
- package/dist/lib/signal/graph/index.cjs +1 -0
- package/dist/lib/signal/graph/index.d.ts +21 -0
- package/dist/lib/signal/graph/index.d.ts.map +1 -0
- package/dist/lib/signal/graph/index.js +20 -0
- package/dist/lib/signal/graph/index.mjs +1 -0
- package/dist/lib/signal/graph/resource.cjs +1 -0
- package/dist/lib/signal/graph/resource.d.ts +36 -0
- package/dist/lib/signal/graph/resource.d.ts.map +1 -0
- package/dist/lib/signal/graph/resource.js +156 -0
- package/dist/lib/signal/graph/resource.mjs +1 -0
- package/dist/lib/signal/graph/runtime.cjs +1 -0
- package/dist/lib/signal/graph/runtime.d.ts +56 -0
- package/dist/lib/signal/graph/runtime.d.ts.map +1 -0
- package/dist/lib/signal/graph/runtime.js +277 -0
- package/dist/lib/signal/graph/runtime.mjs +1 -0
- package/dist/lib/signal/graph/signal-next.cjs +1 -0
- package/dist/lib/signal/graph/signal-next.d.ts +37 -0
- package/dist/lib/signal/graph/signal-next.d.ts.map +1 -0
- package/dist/lib/signal/graph/signal-next.js +41 -0
- package/dist/lib/signal/graph/signal-next.mjs +1 -0
- package/dist/lib/signal/graph/ssr-hooks.cjs +1 -0
- package/dist/lib/signal/graph/ssr-hooks.d.ts +28 -0
- package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -0
- package/dist/lib/signal/graph/ssr-hooks.js +45 -0
- package/dist/lib/signal/graph/ssr-hooks.mjs +1 -0
- package/dist/lib/signal/graph/state.cjs +1 -0
- package/dist/lib/signal/graph/state.d.ts +43 -0
- package/dist/lib/signal/graph/state.d.ts.map +1 -0
- package/dist/lib/signal/graph/state.js +37 -0
- package/dist/lib/signal/graph/state.mjs +1 -0
- package/dist/lib/signal/graph/suspense.cjs +1 -0
- package/dist/lib/signal/graph/suspense.d.ts +13 -0
- package/dist/lib/signal/graph/suspense.d.ts.map +1 -0
- package/dist/lib/signal/graph/suspense.js +36 -0
- package/dist/lib/signal/graph/suspense.mjs +1 -0
- package/dist/lib/signal/index-legacy.cjs +1 -0
- package/dist/lib/signal/index-legacy.d.ts +12 -0
- package/dist/lib/signal/index-legacy.d.ts.map +1 -0
- package/dist/lib/signal/index-legacy.js +11 -0
- package/dist/lib/signal/index-legacy.mjs +1 -0
- package/dist/lib/signal/index.cjs +1 -0
- package/dist/lib/signal/index.d.ts +12 -0
- package/dist/lib/signal/index.d.ts.map +1 -0
- package/dist/lib/signal/index.js +11 -0
- package/dist/lib/signal/index.mjs +1 -0
- package/dist/lib/signal/list.cjs +1 -0
- package/dist/lib/signal/list.d.ts +39 -0
- package/dist/lib/signal/list.d.ts.map +1 -0
- package/dist/lib/signal/list.js +172 -0
- package/dist/lib/signal/list.mjs +1 -0
- package/dist/lib/signal/signal.cjs +1 -0
- package/dist/lib/signal/signal.d.ts +295 -0
- package/dist/lib/signal/signal.d.ts.map +1 -0
- package/dist/lib/signal/signal.js +1219 -0
- package/dist/lib/signal/signal.mjs +1 -0
- package/dist/lib/signal/types.cjs +1 -0
- package/dist/lib/signal/types.d.ts +133 -0
- package/dist/lib/signal/types.d.ts.map +1 -0
- package/dist/lib/signal/types.js +38 -0
- package/dist/lib/signal/types.mjs +1 -0
- package/dist/lib/signal/utilities.cjs +1 -0
- package/dist/lib/signal/utilities.d.ts +355 -0
- package/dist/lib/signal/utilities.d.ts.map +1 -0
- package/dist/lib/signal/utilities.js +504 -0
- package/dist/lib/signal/utilities.mjs +1 -0
- package/dist/lib/store/index.cjs +1 -0
- package/dist/lib/store/index.d.ts +14 -0
- package/dist/lib/store/index.d.ts.map +1 -0
- package/dist/lib/store/index.js +11 -0
- package/dist/lib/store/index.mjs +1 -0
- package/dist/lib/store/setter.types.cjs +1 -0
- package/dist/lib/store/setter.types.d.ts +79 -0
- package/dist/lib/store/setter.types.d.ts.map +1 -0
- package/dist/lib/store/setter.types.js +65 -0
- package/dist/lib/store/setter.types.mjs +0 -0
- package/dist/lib/store/store.cjs +1 -0
- package/dist/lib/store/store.d.ts +86 -0
- package/dist/lib/store/store.d.ts.map +1 -0
- package/dist/lib/store/store.js +442 -0
- package/dist/lib/store/store.mjs +1 -0
- package/dist/lib/store/types.cjs +1 -0
- package/dist/lib/store/types.d.ts +57 -0
- package/dist/lib/store/types.d.ts.map +1 -0
- package/dist/lib/store/types.js +1 -0
- package/dist/lib/store/types.mjs +0 -0
- package/dist/lib/store/utils.cjs +1 -0
- package/dist/lib/store/utils.d.ts +13 -0
- package/dist/lib/store/utils.d.ts.map +1 -0
- package/dist/lib/store/utils.js +29 -0
- package/dist/lib/store/utils.mjs +1 -0
- package/dist/lib/subject.cjs +1 -0
- package/dist/lib/subject.d.ts +14 -0
- package/dist/lib/subject.d.ts.map +1 -0
- package/dist/lib/subject.js +169 -0
- package/dist/lib/subject.mjs +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +114 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L1 — the runtime layer the TC39 proposal deliberately OMITS, rebuilt on top of
|
|
3
|
+
* the L0 graph core (./core.ts). TC39 ships only State/Computed/Watcher; everything
|
|
4
|
+
* a framework needs — ownership/disposal, a scheduler, batching, and effects — is
|
|
5
|
+
* left to userland. This module is that userland, expressed once, cleanly:
|
|
6
|
+
*
|
|
7
|
+
* - Owner tree: createRoot / onCleanup / getOwner / runWithOwner (no graph entanglement)
|
|
8
|
+
* - Scheduler: a microtask-batched effect queue + flushSync / batch
|
|
9
|
+
* - effect(): re-running side effect built on a Computed + a Watcher + an owner
|
|
10
|
+
*
|
|
11
|
+
* It is intentionally NOT wired into the package's public exports yet (those names
|
|
12
|
+
* clash with the legacy createEffect/createRoot/onCleanup/batch). It is the staged
|
|
13
|
+
* replacement: once proven, the legacy public API re-points onto this. Effects are
|
|
14
|
+
* built on `Signal.subtle.Watcher` exactly as the proposal intends — the watcher's
|
|
15
|
+
* notify only schedules; the actual re-run (a tracked recompute) happens on flush.
|
|
16
|
+
*/
|
|
17
|
+
import { Computed, Watcher } from './core.js';
|
|
18
|
+
import { G } from './state.js';
|
|
19
|
+
// Owner / scheduler / boundary-hook state all live on the shared globalThis-backed G
|
|
20
|
+
// (see ./state.ts) so duplicate module copies share one graph.
|
|
21
|
+
function makeOwner(parent) {
|
|
22
|
+
return { cleanups: null, owned: null, parent, contexts: null };
|
|
23
|
+
}
|
|
24
|
+
export function createContext(defaultValue) {
|
|
25
|
+
const id = Symbol('context');
|
|
26
|
+
const Provider = (props) => {
|
|
27
|
+
// Stamp the value on a DEDICATED child owner, then read `children` under it — never
|
|
28
|
+
// on the current owner directly. Two sibling <Ctx.Provider> elements used inline (no
|
|
29
|
+
// wrapping component) run under the SAME ambient owner, so stamping there lets the
|
|
30
|
+
// second clobber the first's entry — every descendant then resolves the last value.
|
|
31
|
+
// A child scope isolates each Provider; because createMemo captures the owner at
|
|
32
|
+
// creation, the children memos built while reading `props.children` here capture this
|
|
33
|
+
// scope and resolve the right value even when rendered lazily (Portal/Show/For).
|
|
34
|
+
const parent = G.owner;
|
|
35
|
+
const owner = makeOwner(parent);
|
|
36
|
+
(owner.contexts = new Map()).set(id, props.value);
|
|
37
|
+
if (parent)
|
|
38
|
+
(parent.owned ??= []).push(owner);
|
|
39
|
+
G.owner = owner;
|
|
40
|
+
try {
|
|
41
|
+
return props.children;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
G.owner = parent;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return { id, defaultValue, Provider };
|
|
48
|
+
}
|
|
49
|
+
/** Read the nearest provided value for `context`, or its default. */
|
|
50
|
+
export function useContext(context) {
|
|
51
|
+
let o = G.owner;
|
|
52
|
+
while (o) {
|
|
53
|
+
if (o.contexts && o.contexts.has(context.id))
|
|
54
|
+
return o.contexts.get(context.id);
|
|
55
|
+
o = o.parent;
|
|
56
|
+
}
|
|
57
|
+
return context.defaultValue;
|
|
58
|
+
}
|
|
59
|
+
/** Read `context` starting from a specific owner chain (not the current scope). */
|
|
60
|
+
export function readContextFrom(owner, context) {
|
|
61
|
+
let o = owner;
|
|
62
|
+
while (o) {
|
|
63
|
+
if (o.contexts && o.contexts.has(context.id))
|
|
64
|
+
return o.contexts.get(context.id);
|
|
65
|
+
o = o.parent;
|
|
66
|
+
}
|
|
67
|
+
return context.defaultValue;
|
|
68
|
+
}
|
|
69
|
+
/** Run `fn` in a child scope that provides `value` for `context`. */
|
|
70
|
+
export function provide(context, value, fn) {
|
|
71
|
+
const owner = makeOwner(G.owner);
|
|
72
|
+
(owner.contexts = new Map()).set(context.id, value);
|
|
73
|
+
if (G.owner)
|
|
74
|
+
(G.owner.owned ??= []).push(owner);
|
|
75
|
+
const prev = G.owner;
|
|
76
|
+
G.owner = owner;
|
|
77
|
+
try {
|
|
78
|
+
return fn();
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
G.owner = prev;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// ── Suspend / error hooks (injected by the boundary layers; L1 stays decoupled) ──
|
|
85
|
+
/** Register how a thrown promise (a suspended read) is reported to a boundary. */
|
|
86
|
+
export function setSuspendHandler(fn) {
|
|
87
|
+
G.onSuspend = fn;
|
|
88
|
+
}
|
|
89
|
+
/** Report a suspended read (thrown promise) to the nearest boundary from the current owner. */
|
|
90
|
+
export function reportSuspend(promise) {
|
|
91
|
+
if (G.onSuspend) {
|
|
92
|
+
G.onSuspend(promise, G.owner);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
/** Register how a thrown error is routed to an error boundary. Return true if handled. */
|
|
98
|
+
export function setErrorHandler(fn) {
|
|
99
|
+
G.onError = fn;
|
|
100
|
+
}
|
|
101
|
+
export function getOwner() {
|
|
102
|
+
return G.owner;
|
|
103
|
+
}
|
|
104
|
+
/** Set the current owner directly, returning the previous one. (Framework render glue.) */
|
|
105
|
+
export function setOwner(owner) {
|
|
106
|
+
const prev = G.owner;
|
|
107
|
+
G.owner = owner;
|
|
108
|
+
return prev;
|
|
109
|
+
}
|
|
110
|
+
export function runWithOwner(owner, fn) {
|
|
111
|
+
const prev = G.owner;
|
|
112
|
+
G.owner = owner;
|
|
113
|
+
try {
|
|
114
|
+
return fn();
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
G.owner = prev;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Register a teardown for the current owner scope. */
|
|
121
|
+
export function onCleanup(fn) {
|
|
122
|
+
if (!G.owner)
|
|
123
|
+
return; // no owner → not retained, runs never (matches Solid)
|
|
124
|
+
(G.owner.cleanups ??= []).push(fn);
|
|
125
|
+
}
|
|
126
|
+
function disposeOwner(owner) {
|
|
127
|
+
if (owner.owned) {
|
|
128
|
+
for (let i = owner.owned.length - 1; i >= 0; i--)
|
|
129
|
+
disposeOwner(owner.owned[i]);
|
|
130
|
+
owner.owned = null;
|
|
131
|
+
}
|
|
132
|
+
if (owner.cleanups) {
|
|
133
|
+
for (let i = owner.cleanups.length - 1; i >= 0; i--)
|
|
134
|
+
owner.cleanups[i]();
|
|
135
|
+
owner.cleanups = null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** Create a root reactive scope with explicit disposal (TC39 has no ownership). */
|
|
139
|
+
export function createRoot(fn) {
|
|
140
|
+
const owner = makeOwner(G.owner);
|
|
141
|
+
if (G.owner)
|
|
142
|
+
(G.owner.owned ??= []).push(owner);
|
|
143
|
+
const prev = G.owner;
|
|
144
|
+
G.owner = owner;
|
|
145
|
+
try {
|
|
146
|
+
return fn(() => disposeOwner(owner));
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
G.owner = prev;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// ── Scheduler (TC39 has none) — state on G (see ./state.ts) ───────────────────
|
|
153
|
+
export function setScheduler(fn) {
|
|
154
|
+
G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
|
|
155
|
+
}
|
|
156
|
+
function enqueue(e) {
|
|
157
|
+
if (e.queued)
|
|
158
|
+
return;
|
|
159
|
+
e.queued = true;
|
|
160
|
+
G.queue.push(e);
|
|
161
|
+
if (!G.scheduled && G.batchDepth === 0) {
|
|
162
|
+
G.scheduled = true;
|
|
163
|
+
G.hostSchedule(flushSync);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** Drain all pending effects now (synchronously). */
|
|
167
|
+
export function flushSync() {
|
|
168
|
+
G.scheduled = false;
|
|
169
|
+
// Re-entrancy guard: an effect that writes a signal during its run re-enqueues;
|
|
170
|
+
// the running loop below picks that up, so a nested flushSync must be a no-op
|
|
171
|
+
// (otherwise the same G.queue drains twice).
|
|
172
|
+
if (G.flushing)
|
|
173
|
+
return;
|
|
174
|
+
G.flushing = true;
|
|
175
|
+
let guard = 0;
|
|
176
|
+
try {
|
|
177
|
+
while (G.queue.length) {
|
|
178
|
+
if (++guard > 100000)
|
|
179
|
+
throw new Error('[fluixi] effect flush did not settle (cycle?)');
|
|
180
|
+
const batchOf = G.queue;
|
|
181
|
+
G.queue = [];
|
|
182
|
+
for (const e of batchOf) {
|
|
183
|
+
e.queued = false;
|
|
184
|
+
if (!e.disposed)
|
|
185
|
+
e.run();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
G.flushing = false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Run pending effects after a write completes — but only at the top level (not
|
|
195
|
+
* inside a batch). A single write thus marks the WHOLE graph dirty first, then
|
|
196
|
+
* flushes once (legacy-equivalent synchronous effects, glitch-free). The `G.flushing`
|
|
197
|
+
* guard makes a write inside an effect a no-op here (the running loop drains it).
|
|
198
|
+
*/
|
|
199
|
+
export function afterWrite() {
|
|
200
|
+
if (G.batchDepth === 0)
|
|
201
|
+
flushSync();
|
|
202
|
+
}
|
|
203
|
+
/** Group writes so dependent effects flush once, at the end. */
|
|
204
|
+
export function batch(fn) {
|
|
205
|
+
G.batchDepth++;
|
|
206
|
+
try {
|
|
207
|
+
return fn();
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
if (--G.batchDepth === 0)
|
|
211
|
+
flushSync();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// ── effect() — built on Computed + Watcher + Owner ───────────────────────────
|
|
215
|
+
class EffectNode {
|
|
216
|
+
computed;
|
|
217
|
+
watcher;
|
|
218
|
+
owner;
|
|
219
|
+
queued = false;
|
|
220
|
+
disposed = false;
|
|
221
|
+
constructor(fn) {
|
|
222
|
+
this.owner = makeOwner(G.owner);
|
|
223
|
+
// Tie disposal to the creating scope: when the parent owner tears down it must
|
|
224
|
+
// fully dispose this effect (unwatch + body cleanups), not just run the body
|
|
225
|
+
// cleanups. Register dispose() as a parent cleanup rather than as an owned tree.
|
|
226
|
+
if (G.owner)
|
|
227
|
+
(G.owner.cleanups ??= []).push(() => this.dispose());
|
|
228
|
+
// The Computed runs the user fn inside a tracking scope + this effect's owner,
|
|
229
|
+
// so reads subscribe and onCleanup/nested roots attach here.
|
|
230
|
+
this.computed = new Computed(() => {
|
|
231
|
+
// teardown previous run's cleanups before re-running
|
|
232
|
+
disposeOwner(this.owner);
|
|
233
|
+
runWithOwner(this.owner, () => {
|
|
234
|
+
const r = fn();
|
|
235
|
+
if (typeof r === 'function')
|
|
236
|
+
(this.owner.cleanups ??= []).push(r);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
// The watcher only schedules; the recompute happens on flush.
|
|
240
|
+
this.watcher = new Watcher(() => enqueue(this));
|
|
241
|
+
this.run(); // initial synchronous run (Solid semantics)
|
|
242
|
+
this.watcher.watch(this.computed);
|
|
243
|
+
}
|
|
244
|
+
run() {
|
|
245
|
+
if (this.disposed)
|
|
246
|
+
return;
|
|
247
|
+
this.watcher.getPending(); // clear pending; reading re-arms the watcher
|
|
248
|
+
try {
|
|
249
|
+
this.computed.get(); // recompute if dirty (re-runs the effect body)
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
// A suspended read (createResource while pending) throws its promise. Report
|
|
253
|
+
// it to the nearest Suspense boundary; the effect re-runs via normal
|
|
254
|
+
// reactivity once the resource's state signal changes. Other errors propagate.
|
|
255
|
+
if (e && typeof e.then === 'function' && G.onSuspend) {
|
|
256
|
+
G.onSuspend(e, this.owner);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
// Route a real error to the nearest error boundary; rethrow if none handled it.
|
|
260
|
+
if (G.onError && G.onError(e, this.owner))
|
|
261
|
+
return;
|
|
262
|
+
throw e;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
dispose() {
|
|
266
|
+
if (this.disposed)
|
|
267
|
+
return;
|
|
268
|
+
this.disposed = true;
|
|
269
|
+
this.watcher.unwatch(this.computed);
|
|
270
|
+
disposeOwner(this.owner);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/** A re-running side effect. Runs once now, then again (G.scheduled) when deps change. */
|
|
274
|
+
export function effect(fn) {
|
|
275
|
+
const node = new EffectNode(fn);
|
|
276
|
+
return () => node.dispose();
|
|
277
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m="__fluixi_signal_next_state__",x=n=>{typeof queueMicrotask=="function"?queueMicrotask(n):Promise.resolve().then(n)},t=globalThis[m]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:x,onSuspend:null,onError:null};var y=0,T=1,a=2,p=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(t.untracked)return;let e=t.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}};var l=class extends p{constructor(r,o){super();this._threw=!1;this._initialized=!1;this.state=a;this.sources=null;this._fn=r,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(t.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===T&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===a)break}(this.state===a||!this._initialized)&&this.recompute(),this.state=y}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=t.consumer,o=t.untracked;t.consumer=this,t.untracked=!1;let s,i=!1,f;try{s=this._fn()}catch(u){i=!0,f=u,s=this._value}finally{t.consumer=r,t.untracked=o}let b=!this._initialized||this._threw!==i||(i?f!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=f,this._value=s,b){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(a);_(this)}}markDirty(r){if(this.state>=r)return;let o=this.state===y;if(this.state=r,o){if(this.observers)for(let s of[...this.observers])s.markDirty(T);_(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function _(n){if(n.watchers)for(let e of[...n.watchers])e._notify(n)}var c=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let r of e)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...e){for(let r of e)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let r=this._pending.size===0;this._pending.add(e),r&&this._notifyFn()}};function h(n){return{cleanups:null,owned:null,parent:n,contexts:null}}function D(n){let e=Symbol("context");return{id:e,defaultValue:n,Provider:o=>{let s=t.owner,i=h(s);(i.contexts=new Map).set(e,o.value),s&&(s.owned??=[]).push(i),t.owner=i;try{return o.children}finally{t.owner=s}}}}function N(n){let e=t.owner;for(;e;){if(e.contexts&&e.contexts.has(n.id))return e.contexts.get(n.id);e=e.parent}return n.defaultValue}function P(n,e){let r=n;for(;r;){if(r.contexts&&r.contexts.has(e.id))return r.contexts.get(e.id);r=r.parent}return e.defaultValue}function z(n,e,r){let o=h(t.owner);(o.contexts=new Map).set(n.id,e),t.owner&&(t.owner.owned??=[]).push(o);let s=t.owner;t.owner=o;try{return r()}finally{t.owner=s}}function I(n){t.onSuspend=n}function G(n){return t.onSuspend?(t.onSuspend(n,t.owner),!0):!1}function R(n){t.onError=n}function M(){return t.owner}function W(n){let e=t.owner;return t.owner=n,e}function S(n,e){let r=t.owner;t.owner=n;try{return e()}finally{t.owner=r}}function A(n){t.owner&&(t.owner.cleanups??=[]).push(n)}function d(n){if(n.owned){for(let e=n.owned.length-1;e>=0;e--)d(n.owned[e]);n.owned=null}if(n.cleanups){for(let e=n.cleanups.length-1;e>=0;e--)n.cleanups[e]();n.cleanups=null}}function F(n){let e=h(t.owner);t.owner&&(t.owner.owned??=[]).push(e);let r=t.owner;t.owner=e;try{return n(()=>d(e))}finally{t.owner=r}}function H(n){t.hostSchedule=n??(e=>{Promise.resolve().then(e)})}function k(n){n.queued||(n.queued=!0,t.queue.push(n),!t.scheduled&&t.batchDepth===0&&(t.scheduled=!0,t.hostSchedule(v)))}function v(){if(t.scheduled=!1,t.flushing)return;t.flushing=!0;let n=0;try{for(;t.queue.length;){if(++n>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=t.queue;t.queue=[];for(let r of e)r.queued=!1,r.disposed||r.run()}}finally{t.flushing=!1}}function V(){t.batchDepth===0&&v()}function K(n){t.batchDepth++;try{return n()}finally{--t.batchDepth===0&&v()}}var w=class{constructor(e){this.queued=!1;this.disposed=!1;this.owner=h(t.owner),t.owner&&(t.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new l(()=>{d(this.owner),S(this.owner,()=>{let r=e();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new c(()=>k(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(e){if(e&&typeof e.then=="function"&&t.onSuspend){t.onSuspend(e,this.owner);return}if(t.onError&&t.onError(e,this.owner))return;throw e}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),d(this.owner))}};function Y(n){let e=new w(n);return()=>e.dispose()}export{V as afterWrite,K as batch,D as createContext,F as createRoot,Y as effect,v as flushSync,M as getOwner,A as onCleanup,z as provide,P as readContextFrom,G as reportSuspend,S as runWithOwner,R as setErrorHandler,W as setOwner,H as setScheduler,I as setSuspendHandler,N as useContext};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var oe=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.prototype.hasOwnProperty;var ot=(e,t)=>{for(var n in t)oe(e,n,{get:t[n],enumerable:!0})},st=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of nt(t))!rt.call(e,s)&&s!==n&&oe(e,s,{get:()=>t[s],enumerable:!(r=tt(t,s))||r.enumerable});return e};var it=e=>st(oe({},"__esModule",{value:!0}),e);var gt={};ot(gt,{$PROXY:()=>xt,$SIGNAL:()=>St,Signal:()=>Ze,SuspenseContext:()=>re,__DEV__:()=>X,batch:()=>x,createComputed:()=>Ce,createContext:()=>D,createDebounce:()=>ze,createDeferred:()=>We,createEffect:()=>O,createErrorBoundary:()=>Je,createMemo:()=>w,createRenderEffect:()=>Ae,createResource:()=>He,createRoot:()=>E,createSelector:()=>Ge,createSignal:()=>d,createSuspenseBoundary:()=>Ke,flush:()=>qe,getOwner:()=>F,getServerData:()=>Z,indexArray:()=>yt,isComponent:()=>Ne,isMemo:()=>Ie,isProvider:()=>Be,isResource:()=>Me,isSignal:()=>J,isSuspense:()=>Ue,keyArray:()=>ht,makeArrayFlat:()=>le,mapArray:()=>pt,nextResourceId:()=>ee,on:()=>De,onCleanup:()=>v,provide:()=>I,provideErrorBoundary:()=>Qe,provideSuspense:()=>Ye,readChildren:()=>$e,reportResourceData:()=>te,runWithOwner:()=>M,setOwner:()=>ue,setResourceDataSink:()=>je,setResourceIdSource:()=>Ve,setResourceTracker:()=>Le,setServerDataGetter:()=>Fe,startTransition:()=>ce,trackResourcePromise:()=>Q,untrack:()=>g,useContext:()=>ge,useTransition:()=>Pe});module.exports=it(gt);var ut="__fluixi_signal_next_state__",at=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[ut]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:at,onSuspend:null,onError:null};var ve=0,we=1,B=2,z=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let t=o.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},P=class extends z{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(B);se(this)}}peek(){return this._value}},k=class extends z{constructor(n,r){super();this._threw=!1;this._initialized=!1;this.state=B;this.sources=null;this._fn=n,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===we&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===B)break}(this.state===B||!this._initialized)&&this.recompute(),this.state=ve}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let n=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,i=!1,a;try{s=this._fn()}catch(u){i=!0,a=u,s=this._value}finally{o.consumer=n,o.untracked=r}let l=!this._initialized||this._threw!==i||(i?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=a,this._value=s,l){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(B);se(this)}}markDirty(n){if(this.state>=n)return;let r=this.state===ve;if(this.state=n,r){if(this.observers)for(let s of[...this.observers])s.markDirty(we);se(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function se(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var q=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function L(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function Se(){return o.consumer}function xe(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function H(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function D(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:r=>{let s=o.owner,i=H(s);(i.contexts=new Map).set(t,r.value),s&&(s.owned??=[]).push(i),o.owner=i;try{return r.children}finally{o.owner=s}}}}function ge(e){let t=o.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function K(e,t){let n=e;for(;n;){if(n.contexts&&n.contexts.has(t.id))return n.contexts.get(t.id);n=n.parent}return t.defaultValue}function I(e,t,n){let r=H(o.owner);(r.contexts=new Map).set(e.id,t),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return n()}finally{o.owner=s}}function be(e){o.onSuspend=e}function ke(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function Re(e){o.onError=e}function F(){return o.owner}function ue(e){let t=o.owner;return o.owner=e,t}function M(e,t){let n=o.owner;o.owner=e;try{return t()}finally{o.owner=n}}function v(e){o.owner&&(o.owner.cleanups??=[]).push(e)}function $(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)$(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function E(e){let t=H(o.owner);o.owner&&(o.owner.owned??=[]).push(t);let n=o.owner;o.owner=t;try{return e(()=>$(t))}finally{o.owner=n}}function _e(e){o.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function ct(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(V)))}function V(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=o.queue;o.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{o.flushing=!1}}function Ee(){o.batchDepth===0&&V()}function ae(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&V()}}var ie=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=H(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new k(()=>{$(this.owner),M(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new q(()=>ct(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&o.onSuspend){o.onSuspend(t,this.owner);return}if(o.onError&&o.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),$(this.owner))}};function Y(e){let t=new ie(e);return()=>t.dispose()}function lt(e){return!!e&&typeof e.then=="function"}_e(()=>{});var Oe=Symbol.for("signal"),dt=Symbol.for("memo"),ft=Symbol.for("signal-node");function d(e,t){let n=new P(e,{equals:t?.equals}),r=(()=>n.get()),s=(i=>{let a=typeof i=="function"?i(n.peek()):i;return n.set(a),Ee(),a});return Object.defineProperty(r,Oe,{value:!0,enumerable:!0}),Object.defineProperty(r,ft,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[r,s]}function w(e,t,n){let r=t,s=F(),i=new k(()=>M(s,()=>{try{return r=e(r)}catch(l){if(lt(l))return ke(l),r;throw l}}),{equals:n?.equals}),a=(()=>i.get());return Object.defineProperty(a,Oe,{value:!0,enumerable:!0}),Object.defineProperty(a,dt,{value:!0,enumerable:!0}),a}function O(e,t){let n=t;return Y(()=>{n=e(n)})}function Ce(e,t){let n=t;Y(()=>{n=e(n)})}function Ae(e,t){let n=t;return Y(()=>{n=e(n)})}function x(e){return ae(e)}function g(e){return L(e)}function ce(e){return ae(e),Promise.resolve()}function Pe(){return[()=>!1,ce]}function qe(){return V(),Promise.resolve()}function De(e,t,n){let r=Array.isArray(e),s,i=n?.defer??!1;return a=>{let l=r?e.map(f=>f()):e();if(i){i=!1,s=l;return}let u=L(()=>t(l,s,a));return s=l,u}}function pt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return g(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=new Map;for(let u of r)i.has(u.item)||i.set(u.item,u);let a=[],l=new Set;for(let u=0;u<s.length;u++){let f=s[u],p=i.get(f);if(p&&!l.has(p))p.setIndex(u),a.push(p),l.add(p);else{let c,h,y;E(m=>{y=m;let[C,N]=d(u);h=N,c=t(f,C)});let S={item:f,rendered:c,dispose:y,setIndex:h};a.push(S),l.add(S)}}for(let u of r)l.has(u)||u.dispose();return r=a,a.map(u=>u.rendered)})})}function ht(e,t,n,r){let s=[],i=[];return v(()=>{for(let a of i)a.dispose();s=[],i=[]}),w(()=>{let a=e()||[];return g(()=>{if(a.length===0){for(let c of i)c.dispose();return s=[],i=[],r?.fallback?r.fallback():[]}let l=new Map;for(let c=0;c<s.length;c++)l.set(s[c],i[c]);let u=[],f=[],p=new Set;for(let c=0;c<a.length;c++){let h=t(a[c]),y=l.get(h);if(y&&!p.has(h))y.setIndex(c),u.push(y);else{let S,m,C;E(N=>{C=N;let[R,U]=d(c);m=U;let j=w(A=>{let b=(e()||[])[R()];return b??A},a[c]);S=n(j,R)}),u.push({rendered:S,dispose:C,setIndex:m})}f.push(h),p.add(h)}for(let[c,h]of l)p.has(c)||h.dispose();return s=f,i=u,u.map(c=>c.rendered)})})}function yt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return g(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=r.length,a=s.length;for(let u=i;u<a;u++){let f,p,c,h=s[u];E(y=>{c=y;let[S,m]=d(h);p=m,f=t(S,u)}),r.push({rendered:f,setItem:p,dispose:c})}for(let u=a;u<i;u++)r[u].dispose();a<i&&(r=r.slice(0,a));let l=Math.min(i,a);for(let u=0;u<l;u++)r[u].setItem(s[u]);return r.map(u=>u.rendered)})})}var X=!1,mt=Symbol.for("signal"),Tt=Symbol.for("memo"),vt=Symbol.for("resource");function J(e){return typeof e=="function"&&e[mt]===!0}function Ie(e){return typeof e=="function"&&e[Tt]===!0}function Me(e){return typeof e=="function"&&e[vt]===!0}function Ne(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ue(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Be(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function le(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?le(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var de=null;function Le(e){de=e}function Q(e){de&&de(e)}var fe=null;function Fe(e){fe=e}function Z(e){return fe?fe(e):void 0}var pe=null;function Ve(e){pe=e}function ee(){return pe?pe():void 0}var he=null;function je(e){he=e}function te(e,t){he&&he(e,t)}function Ge(e,t=(n,r)=>n===r){let n=new Map;return O(()=>{let r=e();for(let[s,i]of n){let[a,l]=i,u=t(s,r);a()!==u&&l(u)}}),r=>{let s=n.get(r);if(!s){let[i,a]=d(!1);s=[i,a],n.set(r,s);let l=e();a(t(r,l))}return s[0]()}}function We(e,t){let[n,r]=d(e(),t);return O(()=>{let s=e();t?.timeoutMs?setTimeout(()=>r(()=>s),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),n}function ze(e,t){let n,r=(...s)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,s.length>0){let i=s[s.length-1];typeof i=="object"&&i&&!i.tagName&&i.target&&i.target.tagName&&(i=i.target),i&&typeof i=="object"&&i.tagName&&(i.tagName.toLowerCase()==="input"||i.tagName.toLowerCase()==="textarea")&&i.focus()}e(...s)},t)};return v(()=>{n!==void 0&&clearTimeout(n)}),r}function ne(e){if(typeof e=="function"&&!e.length){let t=e();return J(t)?t:ne(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=ne(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function $e(e){let t=w(e);return w(()=>ne(t()))}function wt(e){return!!e&&typeof e.then=="function"}var ye=Symbol();function He(e,t,n={}){let r,s;typeof t=="function"?(r=typeof e=="function"?e:()=>e,s=t):(r=()=>!0,s=e,t&&typeof t=="object"&&(n=t));let i=ee(),a=i!==void 0?Z(i):void 0,l=a!==void 0,[u,f]=d(a!==void 0?a.value:n.initialValue,{equals:!1}),[p,c]=d(void 0,{equals:!1}),[h,y]=d(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[S,m]=d(void 0,{equals:!1}),[C,N]=d(void 0,{equals:!1}),R=ye,U=!1;O(()=>{let T=r();if(C(),T===!1||T===null||T===void 0){R=ye,x(()=>{y("unresolved"),m(void 0),c(void 0)});return}let b=U;if(U=!1,R!==ye&&T===R&&!b)return;if(R=T,l){l=!1;return}let G=!1;v(()=>G=!0);let me=g(h),et=g(u),Te=me==="ready"||me==="refreshing";x(()=>{y(Te?"refreshing":"pending"),c(void 0)});try{let _=s(T,{value:et,refetching:Te});wt(_)?(m(_),Q(_),_.then(W=>{G||(i!==void 0&&te(i,W),x(()=>{f(()=>W),y("ready"),m(void 0)}))},W=>{G||x(()=>{c(W),y("errored"),m(void 0)})})):x(()=>{f(()=>_),y("ready"),m(void 0)})}catch(_){if(G)return;x(()=>{c(_),y("errored"),m(void 0)})}});let j=()=>{let T=h();return T==="pending"||T==="refreshing"},A=(()=>{let T=p();if(T)throw T;if(j()){let b=S();if(b)throw b}return u()});return Object.defineProperties(A,{state:{get:h},loading:{get:j},error:{get:p},latest:{get:u}}),Object.defineProperty(A,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(A,Symbol.for("signal"),{value:!0,enumerable:!0}),[A,{mutate:f,refetch:()=>{U=!0,N(void 0)}}]}var re=D();be((e,t)=>{let n=K(t,re);n&&(n.increment(),e.finally(()=>n.decrement()))});function Ke(){let[e,t]=d(0),n=0;return{increment:()=>t(n+=1),decrement:()=>t(n-=1),inFallback:()=>e()>0}}function Ye(e,t){return I(re,e,t)}var Xe=D();Re((e,t)=>{let n=K(t,Xe);return n?(n.setError(e),!0):!1});function Je(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:r=>t(()=>r)}}function Qe(e,t){return I(Xe,e,t)}var Ze={State:P,Computed:k,subtle:{Watcher:q,untrack:L,currentComputed:Se,hasSinks:xe}};var St=Symbol.for("signal"),xt=Symbol.for("fluixi-proxy");
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@fluixi/reactive/signal-next` — the complete reactive API running on the TC39
|
|
3
|
+
* Signals core (L0 graph + L1 runtime), as a drop-in for `@fluixi/reactive/signal`.
|
|
4
|
+
*
|
|
5
|
+
* This is the OPT-IN entry for the migration. It is purely additive: the legacy
|
|
6
|
+
* `@fluixi/reactive/signal` (signal.ts) remains the default and the fallback, fully
|
|
7
|
+
* intact. Adopt this entry to run on the new core; when the native `globalThis.Signal`
|
|
8
|
+
* ships, L0 becomes a thin polyfill swap underneath this same surface.
|
|
9
|
+
*
|
|
10
|
+
* Coverage: signals, memos, effects, computed, render effects, roots, ownership,
|
|
11
|
+
* batch, untrack, on, transitions (minimal), context, resources (+ SSR seeding),
|
|
12
|
+
* Suspense, and error boundaries — all on the TC39 graph.
|
|
13
|
+
*
|
|
14
|
+
* As a complete drop-in for `@fluixi/reactive/signal`, it first re-exports the FULL
|
|
15
|
+
* legacy surface (operators, list helpers, schedulers, etc.), then OVERRIDES the core
|
|
16
|
+
* reactive primitives below with the TC39 implementations — explicit named re-exports
|
|
17
|
+
* take precedence over this star, so consumers get the new core for those. (Legacy
|
|
18
|
+
* operators that still hold their own module state run on the legacy graph until ported.)
|
|
19
|
+
*
|
|
20
|
+
* The legacy surface is pulled from the SOURCE modules directly (not `../index.js`, which
|
|
21
|
+
* now re-exports THIS file — importing it here would be a cycle).
|
|
22
|
+
*/
|
|
23
|
+
export type { Accessor, Setter, SignalOptions, SignalTuple, MemoOptions, EqualityFn, EffectFn, EffectOptions, ComputationFn, Computation, Cleanup, DerivedFn, AsyncFn, Resource, ResourceFetcher, ResourceSource, ResourceOptions, ResourceState, RootOwner, ReactiveNode, Trigger, EnhancedTrigger, EnhancedSignal, AsyncSignal, LazySignal, SignalWithHistory, SuspenseContextType, SuspenseListContextType, SuspenseListRegisteredState, } from '../signal.js';
|
|
24
|
+
export * from '../list.js';
|
|
25
|
+
export { __DEV__, isSignal, isMemo, isResource, isComponent, isSuspense, isProvider, makeArrayFlat, } from './detect.js';
|
|
26
|
+
export { setResourceTracker, trackResourcePromise, setServerDataGetter, getServerData, setResourceIdSource, nextResourceId, setResourceDataSink, reportResourceData, } from './ssr-hooks.js';
|
|
27
|
+
export { createSelector, createDeferred, createDebounce } from './derived.js';
|
|
28
|
+
export { readChildren } from './children.js';
|
|
29
|
+
export { createSignal, createMemo, createEffect, createComputed, createRenderEffect, createRoot, onCleanup, getOwner, setOwner, runWithOwner, batch, untrack, on, flush, startTransition, useTransition, } from './compat.js';
|
|
30
|
+
export { createContext, useContext, provide, type Context, type Owner } from './runtime.js';
|
|
31
|
+
export { createResource, type ResourceReturn, type ResourceActions } from './resource.js';
|
|
32
|
+
export { createSuspenseBoundary, provideSuspense, SuspenseContext, type SuspenseBoundary, } from './suspense.js';
|
|
33
|
+
export { createErrorBoundary, provideErrorBoundary, type ErrorBoundary, } from './error-boundary.js';
|
|
34
|
+
export { Signal } from './index.js';
|
|
35
|
+
export declare const $SIGNAL: unique symbol;
|
|
36
|
+
export declare const $PROXY: unique symbol;
|
|
37
|
+
//# sourceMappingURL=signal-next.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-next.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/signal-next.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,YAAY,EACV,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EACrE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAChF,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EACzE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAC9E,UAAU,EAAE,iBAAiB,EAC7B,mBAAmB,EAAE,uBAAuB,EAAE,2BAA2B,GAC1E,MAAM,cAAc,CAAC;AAKtB,cAAc,YAAY,CAAC;AAI3B,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,aAAa,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,OAAO,EACP,EAAE,EACF,KAAK,EACL,eAAe,EACf,aAAa,GAKd,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAG5F,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAG1F,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,aAAa,GACnB,MAAM,qBAAqB,CAAC;AAM7B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAOpC,eAAO,MAAM,OAAO,eAAuB,CAAC;AAC5C,eAAO,MAAM,MAAM,eAA6B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Signal operators (`@fluixi/reactive/operators`) and the cached-resource helper
|
|
2
|
+
// (`@fluixi/reactive/cached-resource`) live on their own subpaths — cached-resource
|
|
3
|
+
// still runs on the legacy graph, and keeping both out of the default entry lets the
|
|
4
|
+
// legacy `signal.js` fully tree-shake. `list.ts` stays: dom <For>/<Index> use it.
|
|
5
|
+
export * from '../list.js';
|
|
6
|
+
// Detection guards + helpers — sourced from the TC39-owned module (not signal.js),
|
|
7
|
+
// so they survive once signal.ts is retired. Explicit re-export wins over the star.
|
|
8
|
+
export { __DEV__, isSignal, isMemo, isResource, isComponent, isSuspense, isProvider, makeArrayFlat, } from './detect.js';
|
|
9
|
+
// SSR resource injectables — sourced from the TC39-owned module, not signal.js.
|
|
10
|
+
export { setResourceTracker, trackResourcePromise, setServerDataGetter, getServerData, setResourceIdSource, nextResourceId, setResourceDataSink, reportResourceData, } from './ssr-hooks.js';
|
|
11
|
+
// Derived utilities on the TC39 graph.
|
|
12
|
+
export { createSelector, createDeferred, createDebounce } from './derived.js';
|
|
13
|
+
// Reactive children resolver.
|
|
14
|
+
export { readChildren } from './children.js';
|
|
15
|
+
// Core primitives + scheduling (L2 compat over L0/L1)
|
|
16
|
+
export { createSignal, createMemo, createEffect, createComputed, createRenderEffect, createRoot, onCleanup, getOwner, setOwner, runWithOwner, batch, untrack, on, flush, startTransition, useTransition,
|
|
17
|
+
// Note: the value re-exports above override the legacy ones from `export *`, but the
|
|
18
|
+
// TYPE re-exports are intentionally NOT pulled from compat — the legacy `Accessor`/
|
|
19
|
+
// `Signal`/`SignalOptions` types (a superset, incl. `toObservable`) win, so consumers
|
|
20
|
+
// like the store keep type-checking. (Runtime is identical; only the surface type differs.)
|
|
21
|
+
} from './compat.js';
|
|
22
|
+
// Context (owner-tree)
|
|
23
|
+
export { createContext, useContext, provide } from './runtime.js';
|
|
24
|
+
// Resources (+ __FX_DATA__ SSR seeding, reused from legacy hooks)
|
|
25
|
+
export { createResource } from './resource.js';
|
|
26
|
+
// Suspense
|
|
27
|
+
export { createSuspenseBoundary, provideSuspense, SuspenseContext, } from './suspense.js';
|
|
28
|
+
// Error boundaries
|
|
29
|
+
export { createErrorBoundary, provideErrorBoundary, } from './error-boundary.js';
|
|
30
|
+
// The raw TC39 primitive surface (Signal.State / Computed / subtle.Watcher)
|
|
31
|
+
// `Signal` is the TC39 namespace VALUE (Signal.State/Computed/subtle…). The legacy `[get,set]`
|
|
32
|
+
// tuple type is exported as `SignalTuple` (via `export *` above) — a value and a type of the
|
|
33
|
+
// same name can't be re-exported together, so consumers use `SignalTuple<T>` for the tuple.
|
|
34
|
+
export { Signal } from './index.js';
|
|
35
|
+
// Marker symbols consumers use to detect signals/proxies (e.g. the store, which builds
|
|
36
|
+
// only on the public primitives). $SIGNAL uses the global registry — identical to the
|
|
37
|
+
// legacy `Symbol.for('signal')` — so detection is interoperable. Defined locally (not
|
|
38
|
+
// re-exported from legacy) so signal-next has no import dependency on signal.ts here,
|
|
39
|
+
// which would create an async-resolution cycle when consumers alias signal → signal-next.
|
|
40
|
+
export const $SIGNAL = Symbol.for('signal');
|
|
41
|
+
export const $PROXY = Symbol.for('fluixi-proxy');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var Ce="__fluixi_signal_next_state__",Ae=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[Ce]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Ae,onSuspend:null,onError:null};var he=0,ye=1,M=2,W=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let t=o.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},C=class extends W{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(M);J(this)}}peek(){return this._value}},g=class extends W{constructor(n,r){super();this._threw=!1;this._initialized=!1;this.state=M;this.sources=null;this._fn=n,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===ye&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===M)break}(this.state===M||!this._initialized)&&this.recompute(),this.state=he}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let n=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,i=!1,a;try{s=this._fn()}catch(u){i=!0,a=u,s=this._value}finally{o.consumer=n,o.untracked=r}let l=!this._initialized||this._threw!==i||(i?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=a,this._value=s,l){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(M);J(this)}}markDirty(n){if(this.state>=n)return;let r=this.state===he;if(this.state=n,r){if(this.observers)for(let s of[...this.observers])s.markDirty(ye);J(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function J(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var A=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function N(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function me(){return o.consumer}function Te(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function $(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function U(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:r=>{let s=o.owner,i=$(s);(i.contexts=new Map).set(t,r.value),s&&(s.owned??=[]).push(i),o.owner=i;try{return r.children}finally{o.owner=s}}}}function Pe(e){let t=o.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function H(e,t){let n=e;for(;n;){if(n.contexts&&n.contexts.has(t.id))return n.contexts.get(t.id);n=n.parent}return t.defaultValue}function B(e,t,n){let r=$(o.owner);(r.contexts=new Map).set(e.id,t),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return n()}finally{o.owner=s}}function ve(e){o.onSuspend=e}function we(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function Se(e){o.onError=e}function K(){return o.owner}function xe(e){let t=o.owner;return o.owner=e,t}function L(e,t){let n=o.owner;o.owner=e;try{return t()}finally{o.owner=n}}function v(e){o.owner&&(o.owner.cleanups??=[]).push(e)}function z(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)z(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function P(e){let t=$(o.owner);o.owner&&(o.owner.owned??=[]).push(t);let n=o.owner;o.owner=t;try{return e(()=>z(t))}finally{o.owner=n}}function ge(e){o.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function qe(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(F)))}function F(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=o.queue;o.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{o.flushing=!1}}function be(){o.batchDepth===0&&F()}function Z(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&F()}}var Q=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=$(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new g(()=>{z(this.owner),L(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new A(()=>qe(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&o.onSuspend){o.onSuspend(t,this.owner);return}if(o.onError&&o.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),z(this.owner))}};function Y(e){let t=new Q(e);return()=>t.dispose()}function De(e){return!!e&&typeof e.then=="function"}ge(()=>{});var ke=Symbol.for("signal"),Ie=Symbol.for("memo"),Me=Symbol.for("signal-node");function d(e,t){let n=new C(e,{equals:t?.equals}),r=(()=>n.get()),s=(i=>{let a=typeof i=="function"?i(n.peek()):i;return n.set(a),be(),a});return Object.defineProperty(r,ke,{value:!0,enumerable:!0}),Object.defineProperty(r,Me,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[r,s]}function w(e,t,n){let r=t,s=K(),i=new g(()=>L(s,()=>{try{return r=e(r)}catch(l){if(De(l))return we(l),r;throw l}}),{equals:n?.equals}),a=(()=>i.get());return Object.defineProperty(a,ke,{value:!0,enumerable:!0}),Object.defineProperty(a,Ie,{value:!0,enumerable:!0}),a}function q(e,t){let n=t;return Y(()=>{n=e(n)})}function Ne(e,t){let n=t;Y(()=>{n=e(n)})}function Ue(e,t){let n=t;return Y(()=>{n=e(n)})}function b(e){return Z(e)}function k(e){return N(e)}function Re(e){return Z(e),Promise.resolve()}function Be(){return[()=>!1,Re]}function Le(){return F(),Promise.resolve()}function Fe(e,t,n){let r=Array.isArray(e),s,i=n?.defer??!1;return a=>{let l=r?e.map(f=>f()):e();if(i){i=!1,s=l;return}let u=N(()=>t(l,s,a));return s=l,u}}function xt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return k(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=new Map;for(let u of r)i.has(u.item)||i.set(u.item,u);let a=[],l=new Set;for(let u=0;u<s.length;u++){let f=s[u],p=i.get(f);if(p&&!l.has(p))p.setIndex(u),a.push(p),l.add(p);else{let c,h,y;P(m=>{y=m;let[E,D]=d(u);h=D,c=t(f,E)});let S={item:f,rendered:c,dispose:y,setIndex:h};a.push(S),l.add(S)}}for(let u of r)l.has(u)||u.dispose();return r=a,a.map(u=>u.rendered)})})}function gt(e,t,n,r){let s=[],i=[];return v(()=>{for(let a of i)a.dispose();s=[],i=[]}),w(()=>{let a=e()||[];return k(()=>{if(a.length===0){for(let c of i)c.dispose();return s=[],i=[],r?.fallback?r.fallback():[]}let l=new Map;for(let c=0;c<s.length;c++)l.set(s[c],i[c]);let u=[],f=[],p=new Set;for(let c=0;c<a.length;c++){let h=t(a[c]),y=l.get(h);if(y&&!p.has(h))y.setIndex(c),u.push(y);else{let S,m,E;P(D=>{E=D;let[R,I]=d(c);m=I;let V=w(O=>{let x=(e()||[])[R()];return x??O},a[c]);S=n(V,R)}),u.push({rendered:S,dispose:E,setIndex:m})}f.push(h),p.add(h)}for(let[c,h]of l)p.has(c)||h.dispose();return s=f,i=u,u.map(c=>c.rendered)})})}function bt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return k(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=r.length,a=s.length;for(let u=i;u<a;u++){let f,p,c,h=s[u];P(y=>{c=y;let[S,m]=d(h);p=m,f=t(S,u)}),r.push({rendered:f,setItem:p,dispose:c})}for(let u=a;u<i;u++)r[u].dispose();a<i&&(r=r.slice(0,a));let l=Math.min(i,a);for(let u=0;u<l;u++)r[u].setItem(s[u]);return r.map(u=>u.rendered)})})}var ee=!1,Ve=Symbol.for("signal"),je=Symbol.for("memo"),Ge=Symbol.for("resource");function te(e){return typeof e=="function"&&e[Ve]===!0}function We(e){return typeof e=="function"&&e[je]===!0}function ze(e){return typeof e=="function"&&e[Ge]===!0}function $e(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function He(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Ke(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function _e(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?_e(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var ne=null;function Ye(e){ne=e}function ie(e){ne&&ne(e)}var re=null;function Xe(e){re=e}function ue(e){return re?re(e):void 0}var oe=null;function Je(e){oe=e}function ae(){return oe?oe():void 0}var se=null;function Qe(e){se=e}function ce(e,t){se&&se(e,t)}function Ze(e,t=(n,r)=>n===r){let n=new Map;return q(()=>{let r=e();for(let[s,i]of n){let[a,l]=i,u=t(s,r);a()!==u&&l(u)}}),r=>{let s=n.get(r);if(!s){let[i,a]=d(!1);s=[i,a],n.set(r,s);let l=e();a(t(r,l))}return s[0]()}}function et(e,t){let[n,r]=d(e(),t);return q(()=>{let s=e();t?.timeoutMs?setTimeout(()=>r(()=>s),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),n}function tt(e,t){let n,r=(...s)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,s.length>0){let i=s[s.length-1];typeof i=="object"&&i&&!i.tagName&&i.target&&i.target.tagName&&(i=i.target),i&&typeof i=="object"&&i.tagName&&(i.tagName.toLowerCase()==="input"||i.tagName.toLowerCase()==="textarea")&&i.focus()}e(...s)},t)};return v(()=>{n!==void 0&&clearTimeout(n)}),r}function X(e){if(typeof e=="function"&&!e.length){let t=e();return te(t)?t:X(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=X(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function nt(e){let t=w(e);return w(()=>X(t()))}function rt(e){return!!e&&typeof e.then=="function"}var le=Symbol();function ot(e,t,n={}){let r,s;typeof t=="function"?(r=typeof e=="function"?e:()=>e,s=t):(r=()=>!0,s=e,t&&typeof t=="object"&&(n=t));let i=ae(),a=i!==void 0?ue(i):void 0,l=a!==void 0,[u,f]=d(a!==void 0?a.value:n.initialValue,{equals:!1}),[p,c]=d(void 0,{equals:!1}),[h,y]=d(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[S,m]=d(void 0,{equals:!1}),[E,D]=d(void 0,{equals:!1}),R=le,I=!1;q(()=>{let T=r();if(E(),T===!1||T===null||T===void 0){R=le,b(()=>{y("unresolved"),m(void 0),c(void 0)});return}let x=I;if(I=!1,R!==le&&T===R&&!x)return;if(R=T,l){l=!1;return}let j=!1;v(()=>j=!0);let fe=k(h),Oe=k(u),pe=fe==="ready"||fe==="refreshing";b(()=>{y(pe?"refreshing":"pending"),c(void 0)});try{let _=s(T,{value:Oe,refetching:pe});rt(_)?(m(_),ie(_),_.then(G=>{j||(i!==void 0&&ce(i,G),b(()=>{f(()=>G),y("ready"),m(void 0)}))},G=>{j||b(()=>{c(G),y("errored"),m(void 0)})})):b(()=>{f(()=>_),y("ready"),m(void 0)})}catch(_){if(j)return;b(()=>{c(_),y("errored"),m(void 0)})}});let V=()=>{let T=h();return T==="pending"||T==="refreshing"},O=(()=>{let T=p();if(T)throw T;if(V()){let x=S();if(x)throw x}return u()});return Object.defineProperties(O,{state:{get:h},loading:{get:V},error:{get:p},latest:{get:u}}),Object.defineProperty(O,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(O,Symbol.for("signal"),{value:!0,enumerable:!0}),[O,{mutate:f,refetch:()=>{I=!0,D(void 0)}}]}var de=U();ve((e,t)=>{let n=H(t,de);n&&(n.increment(),e.finally(()=>n.decrement()))});function st(){let[e,t]=d(0),n=0;return{increment:()=>t(n+=1),decrement:()=>t(n-=1),inFallback:()=>e()>0}}function it(e,t){return B(de,e,t)}var Ee=U();Se((e,t)=>{let n=H(t,Ee);return n?(n.setError(e),!0):!1});function ut(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:r=>t(()=>r)}}function at(e,t){return B(Ee,e,t)}var ct={State:C,Computed:g,subtle:{Watcher:A,untrack:N,currentComputed:me,hasSinks:Te}};var Gt=Symbol.for("signal"),Wt=Symbol.for("fluixi-proxy");export{Wt as $PROXY,Gt as $SIGNAL,ct as Signal,de as SuspenseContext,ee as __DEV__,b as batch,Ne as createComputed,U as createContext,tt as createDebounce,et as createDeferred,q as createEffect,ut as createErrorBoundary,w as createMemo,Ue as createRenderEffect,ot as createResource,P as createRoot,Ze as createSelector,d as createSignal,st as createSuspenseBoundary,Le as flush,K as getOwner,ue as getServerData,bt as indexArray,$e as isComponent,We as isMemo,Ke as isProvider,ze as isResource,te as isSignal,He as isSuspense,gt as keyArray,_e as makeArrayFlat,xt as mapArray,ae as nextResourceId,Fe as on,v as onCleanup,B as provide,at as provideErrorBoundary,it as provideSuspense,nt as readChildren,ce as reportResourceData,L as runWithOwner,xe as setOwner,Qe as setResourceDataSink,Je as setResourceIdSource,Ye as setResourceTracker,Xe as setServerDataGetter,Re as startTransition,ie as trackResourcePromise,k as untrack,Pe as useContext,Be as useTransition};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var f=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},p=(e,n,t,d)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of c(n))!v.call(e,r)&&r!==t&&i(e,r,{get:()=>n[r],enumerable:!(d=s(n,r))||d.enumerable});return e};var g=e=>p(i({},"__esModule",{value:!0}),e);var _={};f(_,{getServerData:()=>R,nextResourceId:()=>k,reportResourceData:()=>P,setResourceDataSink:()=>m,setResourceIdSource:()=>S,setResourceTracker:()=>x,setServerDataGetter:()=>D,trackResourcePromise:()=>y});module.exports=g(_);var u=null;function x(e){u=e}function y(e){u&&u(e)}var o=null;function D(e){o=e}function R(e){return o?o(e):void 0}var l=null;function S(e){l=e}function k(){return l?l():void 0}var a=null;function m(e){a=e}function P(e,n){a&&a(e,n)}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSR resource injectables — graph-agnostic module state. The server (@fluixi/server
|
|
3
|
+
* via @fluixi/dom) injects these so async SSR can await in-flight resource fetches and
|
|
4
|
+
* seed resources from server-serialized data on the client. All no-ops when unset →
|
|
5
|
+
* zero client/runtime impact. Used by both the TC39 resource core and the legacy graph,
|
|
6
|
+
* so they live in a TC39-owned module (not signal.ts, which is being retired).
|
|
7
|
+
*/
|
|
8
|
+
/** Register a sink that receives every resource fetch promise (server: collect & await). */
|
|
9
|
+
export declare function setResourceTracker(fn: ((p: Promise<any>) => void) | null): void;
|
|
10
|
+
/** @internal — resources report their fetch promise here. */
|
|
11
|
+
export declare function trackResourcePromise(p: Promise<any>): void;
|
|
12
|
+
/** Inject server-serialized resource data (client hydration: seed without refetch). */
|
|
13
|
+
export declare function setServerDataGetter(fn: ((id: string) => {
|
|
14
|
+
value: any;
|
|
15
|
+
} | undefined) | null): void;
|
|
16
|
+
/** @internal — resources look up seeded data by their SSR id. */
|
|
17
|
+
export declare function getServerData(id: string): {
|
|
18
|
+
value: any;
|
|
19
|
+
} | undefined;
|
|
20
|
+
/** Inject a stable per-resource id source (server render order / hydration order). */
|
|
21
|
+
export declare function setResourceIdSource(fn: (() => string) | null): void;
|
|
22
|
+
/** @internal — a resource asks for its SSR id at creation; undefined on a plain client. */
|
|
23
|
+
export declare function nextResourceId(): string | undefined;
|
|
24
|
+
/** Inject a sink for resolved resource values (server: collect for serialization). */
|
|
25
|
+
export declare function setResourceDataSink(fn: ((id: string, value: any) => void) | null): void;
|
|
26
|
+
/** @internal — a resource reports its resolved value here. */
|
|
27
|
+
export declare function reportResourceData(id: string, value: any): void;
|
|
28
|
+
//# sourceMappingURL=ssr-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr-hooks.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/ssr-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,4FAA4F;AAC5F,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAE/E;AACD,6DAA6D;AAC7D,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAE1D;AAGD,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK;IAAE,KAAK,EAAE,GAAG,CAAA;CAAE,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,IAAI,CAEjG;AACD,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,GAAG,CAAA;CAAE,GAAG,SAAS,CAEpE;AAGD,sFAAsF;AACtF,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI,CAEnE;AACD,2FAA2F;AAC3F,wBAAgB,cAAc,IAAI,MAAM,GAAG,SAAS,CAEnD;AAGD,sFAAsF;AACtF,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAEvF;AACD,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAE/D"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSR resource injectables — graph-agnostic module state. The server (@fluixi/server
|
|
3
|
+
* via @fluixi/dom) injects these so async SSR can await in-flight resource fetches and
|
|
4
|
+
* seed resources from server-serialized data on the client. All no-ops when unset →
|
|
5
|
+
* zero client/runtime impact. Used by both the TC39 resource core and the legacy graph,
|
|
6
|
+
* so they live in a TC39-owned module (not signal.ts, which is being retired).
|
|
7
|
+
*/
|
|
8
|
+
let _resourceTracker = null;
|
|
9
|
+
/** Register a sink that receives every resource fetch promise (server: collect & await). */
|
|
10
|
+
export function setResourceTracker(fn) {
|
|
11
|
+
_resourceTracker = fn;
|
|
12
|
+
}
|
|
13
|
+
/** @internal — resources report their fetch promise here. */
|
|
14
|
+
export function trackResourcePromise(p) {
|
|
15
|
+
if (_resourceTracker)
|
|
16
|
+
_resourceTracker(p);
|
|
17
|
+
}
|
|
18
|
+
let _serverDataGetter = null;
|
|
19
|
+
/** Inject server-serialized resource data (client hydration: seed without refetch). */
|
|
20
|
+
export function setServerDataGetter(fn) {
|
|
21
|
+
_serverDataGetter = fn;
|
|
22
|
+
}
|
|
23
|
+
/** @internal — resources look up seeded data by their SSR id. */
|
|
24
|
+
export function getServerData(id) {
|
|
25
|
+
return _serverDataGetter ? _serverDataGetter(id) : undefined;
|
|
26
|
+
}
|
|
27
|
+
let _resourceIdSource = null;
|
|
28
|
+
/** Inject a stable per-resource id source (server render order / hydration order). */
|
|
29
|
+
export function setResourceIdSource(fn) {
|
|
30
|
+
_resourceIdSource = fn;
|
|
31
|
+
}
|
|
32
|
+
/** @internal — a resource asks for its SSR id at creation; undefined on a plain client. */
|
|
33
|
+
export function nextResourceId() {
|
|
34
|
+
return _resourceIdSource ? _resourceIdSource() : undefined;
|
|
35
|
+
}
|
|
36
|
+
let _resourceDataSink = null;
|
|
37
|
+
/** Inject a sink for resolved resource values (server: collect for serialization). */
|
|
38
|
+
export function setResourceDataSink(fn) {
|
|
39
|
+
_resourceDataSink = fn;
|
|
40
|
+
}
|
|
41
|
+
/** @internal — a resource reports its resolved value here. */
|
|
42
|
+
export function reportResourceData(id, value) {
|
|
43
|
+
if (_resourceDataSink)
|
|
44
|
+
_resourceDataSink(id, value);
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n=null;function o(e){n=e}function l(e){n&&n(e)}var r=null;function a(e){r=e}function d(e){return r?r(e):void 0}var t=null;function s(e){t=e}function c(){return t?t():void 0}var i=null;function v(e){i=e}function f(e,u){i&&i(e,u)}export{d as getServerData,c as nextResourceId,f as reportResourceData,v as setResourceDataSink,s as setResourceIdSource,o as setResourceTracker,a as setServerDataGetter,l as trackResourcePromise};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var t=Object.prototype.hasOwnProperty;var i=(e,o)=>{for(var u in o)l(e,u,{get:o[u],enumerable:!0})},d=(e,o,u,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of s(o))!t.call(e,n)&&n!==u&&l(e,n,{get:()=>o[n],enumerable:!(a=r(o,n))||a.enumerable});return e};var c=e=>d(l({},"__esModule",{value:!0}),e);var b={};i(b,{G:()=>p});module.exports=c(b);var h="__fluixi_signal_next_state__",f=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},p=globalThis[h]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:f,onSuspend:null,onError:null};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reactive graph's mutable state, kept as a SINGLE object cached on globalThis.
|
|
3
|
+
*
|
|
4
|
+
* Why: tracking/scheduling reads module-global state ("who's the current consumer?",
|
|
5
|
+
* "what owner are we under?", "the effect queue"). If a production bundle emits more
|
|
6
|
+
* than one copy of this module (a common cross-package hazard — see @fluixi/dom's
|
|
7
|
+
* integration bridge), plain `let`s would be DUPLICATED: an effect would set copy A's
|
|
8
|
+
* consumer while a signal read checks copy B's → no subscription → reactivity silently
|
|
9
|
+
* lost (works in dev, breaks in prod). Caching the state on globalThis means every copy
|
|
10
|
+
* of this module reads/writes the SAME object, so the graph stays unified no matter how
|
|
11
|
+
* many times the module is bundled — no integration bridge required.
|
|
12
|
+
*
|
|
13
|
+
* This is strictly more robust than SolidJS, which keeps this state in module `let`s and
|
|
14
|
+
* relies on dedup + a "multiple instances" warning. Node-ref fields are loosely typed
|
|
15
|
+
* (`any`) to avoid import cycles with core.ts/runtime.ts; the public API stays fully typed.
|
|
16
|
+
*/
|
|
17
|
+
export interface GraphState {
|
|
18
|
+
/** The computation currently evaluating — reads inside it subscribe to it. */
|
|
19
|
+
consumer: any;
|
|
20
|
+
/** When true, reads don't subscribe (untrack / peek). */
|
|
21
|
+
untracked: boolean;
|
|
22
|
+
/** The current owner scope (ownership/disposal/context). */
|
|
23
|
+
owner: any;
|
|
24
|
+
/** Pending effects awaiting flush. */
|
|
25
|
+
queue: Array<{
|
|
26
|
+
queued: boolean;
|
|
27
|
+
disposed: boolean;
|
|
28
|
+
run(): void;
|
|
29
|
+
}>;
|
|
30
|
+
/** A flush has been scheduled (microtask) but not yet run. */
|
|
31
|
+
scheduled: boolean;
|
|
32
|
+
/** A flush is in progress (re-entrancy guard). */
|
|
33
|
+
flushing: boolean;
|
|
34
|
+
/** Depth of active batch() calls; >0 defers flushing. */
|
|
35
|
+
batchDepth: number;
|
|
36
|
+
/** Host scheduler for the deferred flush (overridable: SSR/tests/compat). */
|
|
37
|
+
hostSchedule: (run: () => void) => void;
|
|
38
|
+
/** Boundary hooks (injected by the Suspense / error-boundary layers). */
|
|
39
|
+
onSuspend: ((promise: Promise<unknown>, owner: any) => void) | null;
|
|
40
|
+
onError: ((error: unknown, owner: any) => boolean) | null;
|
|
41
|
+
}
|
|
42
|
+
export declare const G: GraphState;
|
|
43
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,WAAW,UAAU;IACzB,8EAA8E;IAE9E,QAAQ,EAAE,GAAG,CAAC;IACd,yDAAyD;IACzD,SAAS,EAAE,OAAO,CAAC;IACnB,4DAA4D;IAE5D,KAAK,EAAE,GAAG,CAAC;IACX,sCAAsC;IACtC,KAAK,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAC;QAAC,GAAG,IAAI,IAAI,CAAA;KAAE,CAAC,CAAC;IAClE,8DAA8D;IAC9D,SAAS,EAAE,OAAO,CAAC;IACnB,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC;IAClB,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IACxC,yEAAyE;IAEzE,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAEpE,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,IAAI,CAAC;CAC3D;AASD,eAAO,MAAM,CAAC,EAAE,UAaS,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reactive graph's mutable state, kept as a SINGLE object cached on globalThis.
|
|
3
|
+
*
|
|
4
|
+
* Why: tracking/scheduling reads module-global state ("who's the current consumer?",
|
|
5
|
+
* "what owner are we under?", "the effect queue"). If a production bundle emits more
|
|
6
|
+
* than one copy of this module (a common cross-package hazard — see @fluixi/dom's
|
|
7
|
+
* integration bridge), plain `let`s would be DUPLICATED: an effect would set copy A's
|
|
8
|
+
* consumer while a signal read checks copy B's → no subscription → reactivity silently
|
|
9
|
+
* lost (works in dev, breaks in prod). Caching the state on globalThis means every copy
|
|
10
|
+
* of this module reads/writes the SAME object, so the graph stays unified no matter how
|
|
11
|
+
* many times the module is bundled — no integration bridge required.
|
|
12
|
+
*
|
|
13
|
+
* This is strictly more robust than SolidJS, which keeps this state in module `let`s and
|
|
14
|
+
* relies on dedup + a "multiple instances" warning. Node-ref fields are loosely typed
|
|
15
|
+
* (`any`) to avoid import cycles with core.ts/runtime.ts; the public API stays fully typed.
|
|
16
|
+
*/
|
|
17
|
+
const KEY = '__fluixi_signal_next_state__';
|
|
18
|
+
const defaultSchedule = (run) => {
|
|
19
|
+
if (typeof queueMicrotask === 'function')
|
|
20
|
+
queueMicrotask(run);
|
|
21
|
+
else
|
|
22
|
+
void Promise.resolve().then(run);
|
|
23
|
+
};
|
|
24
|
+
export const G =
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
(globalThis[KEY] ??= {
|
|
27
|
+
consumer: null,
|
|
28
|
+
untracked: false,
|
|
29
|
+
owner: null,
|
|
30
|
+
queue: [],
|
|
31
|
+
scheduled: false,
|
|
32
|
+
flushing: false,
|
|
33
|
+
batchDepth: 0,
|
|
34
|
+
hostSchedule: defaultSchedule,
|
|
35
|
+
onSuspend: null,
|
|
36
|
+
onError: null,
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o="__fluixi_signal_next_state__",n=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},u=globalThis[o]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:n,onSuspend:null,onError:null};export{u as G};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var n in e)a(t,n,{get:e[n],enumerable:!0})},k=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of S(e))!_.call(t,o)&&o!==n&&a(t,o,{get:()=>e[o],enumerable:!(s=x(e,o))||s.enumerable});return t};var O=t=>k(a({},"__esModule",{value:!0}),t);var M={};g(M,{SuspenseContext:()=>c,createSuspenseBoundary:()=>R,provideSuspense:()=>N});module.exports=O(M);var q="__fluixi_signal_next_state__",C=t=>{typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)},r=globalThis[q]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:C,onSuspend:null,onError:null};var P=2,l=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let e=r.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},u=class extends l{constructor(e,n){super(),this._value=e,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(P);D(this)}}peek(){return this._value}};function D(t){if(t.watchers)for(let e of[...t.watchers])e._notify(t)}function f(t){return{cleanups:null,owned:null,parent:t,contexts:null}}function p(t){let e=Symbol("context");return{id:e,defaultValue:t,Provider:s=>{let o=r.owner,i=f(o);(i.contexts=new Map).set(e,s.value),o&&(o.owned??=[]).push(i),r.owner=i;try{return s.children}finally{r.owner=o}}}}function h(t,e){let n=t;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.parent}return e.defaultValue}function w(t,e,n){let s=f(r.owner);(s.contexts=new Map).set(t.id,e),r.owner&&(r.owner.owned??=[]).push(s);let o=r.owner;r.owner=s;try{return n()}finally{r.owner=o}}function v(t){r.onSuspend=t}function T(t){r.hostSchedule=t??(e=>{Promise.resolve().then(e)})}function y(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let t=0;try{for(;r.queue.length;){if(++t>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=r.queue;r.queue=[];for(let n of e)n.queued=!1,n.disposed||n.run()}}finally{r.flushing=!1}}function m(){r.batchDepth===0&&y()}T(()=>{});var A=Symbol.for("signal");var E=Symbol.for("signal-node");function b(t,e){let n=new u(t,{equals:e?.equals}),s=(()=>n.get()),o=(i=>{let d=typeof i=="function"?i(n.peek()):i;return n.set(d),m(),d});return Object.defineProperty(s,A,{value:!0,enumerable:!0}),Object.defineProperty(s,E,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[s,o]}var c=p();v((t,e)=>{let n=h(e,c);n&&(n.increment(),t.finally(()=>n.decrement()))});function R(){let[t,e]=b(0),n=0;return{increment:()=>e(n+=1),decrement:()=>e(n-=1),inFallback:()=>t()>0}}function N(t,e){return w(c,t,e)}
|