@vielzeug/ripple 2.3.0 → 26.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -32
- package/dist/_async.cjs +1 -1
- package/dist/_async.cjs.map +1 -1
- package/dist/_async.d.ts.map +1 -1
- package/dist/_async.js +1 -73
- package/dist/_async.js.map +1 -1
- package/dist/_default.cjs +1 -1
- package/dist/_default.cjs.map +1 -1
- package/dist/_default.d.ts +18 -5
- package/dist/_default.d.ts.map +1 -1
- package/dist/_default.js +1 -28
- package/dist/_default.js.map +1 -1
- package/dist/_subscribable.cjs +2 -0
- package/dist/_subscribable.cjs.map +1 -0
- package/dist/_subscribable.d.ts +17 -0
- package/dist/_subscribable.d.ts.map +1 -0
- package/dist/_subscribable.js +2 -0
- package/dist/_subscribable.js.map +1 -0
- package/dist/_watch.cjs +1 -1
- package/dist/_watch.cjs.map +1 -1
- package/dist/_watch.d.ts +1 -1
- package/dist/_watch.d.ts.map +1 -1
- package/dist/_watch.js +1 -17
- package/dist/_watch.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -9
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -8
- package/dist/index.js.map +1 -1
- package/dist/ripple.cjs +1 -1
- package/dist/ripple.cjs.map +1 -1
- package/dist/ripple.iife.js +1 -1
- package/dist/ripple.iife.js.map +1 -1
- package/dist/ripple.js +1 -1
- package/dist/ripple.js.map +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.ts +31 -12
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1 -357
- package/dist/runtime.js.map +1 -1
- package/dist/types.d.ts +34 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -8
package/dist/runtime.js
CHANGED
|
@@ -1,358 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/runtime.ts
|
|
3
|
-
var i = Symbol.for("@vielzeug/ripple/reactive"), a = 100, o = Symbol("ripple.unset"), s = class {
|
|
4
|
-
[i] = !0;
|
|
5
|
-
dependents = /* @__PURE__ */ new Set();
|
|
6
|
-
name;
|
|
7
|
-
runtime;
|
|
8
|
-
constructor(e, t) {
|
|
9
|
-
this.runtime = e, this.name = t;
|
|
10
|
-
}
|
|
11
|
-
subscribe(e) {
|
|
12
|
-
this.runtime.assertActive(), this.peek();
|
|
13
|
-
let t = {
|
|
14
|
-
dependencies: /* @__PURE__ */ new Set(),
|
|
15
|
-
onDependencyChanged: () => this.runtime.enqueueListener(e)
|
|
16
|
-
};
|
|
17
|
-
return this.dependents.add(t), () => this.dependents.delete(t);
|
|
18
|
-
}
|
|
19
|
-
notify() {
|
|
20
|
-
for (let e of [...this.dependents]) e.onDependencyChanged();
|
|
21
|
-
}
|
|
22
|
-
}, c = class extends s {
|
|
23
|
-
current;
|
|
24
|
-
equals;
|
|
25
|
-
constructor(e, t, n) {
|
|
26
|
-
super(e, n?.name), this.current = t, this.equals = n?.equals ?? Object.is;
|
|
27
|
-
}
|
|
28
|
-
get value() {
|
|
29
|
-
return this.runtime.track(this), this.current;
|
|
30
|
-
}
|
|
31
|
-
set value(e) {
|
|
32
|
-
if (this.runtime.assertActive(), this.equals(this.current, e)) return;
|
|
33
|
-
let t = this.current;
|
|
34
|
-
this.current = e, this.runtime.emit({
|
|
35
|
-
kind: "write",
|
|
36
|
-
name: this.name,
|
|
37
|
-
next: e,
|
|
38
|
-
previous: t
|
|
39
|
-
}), this.runtime.propagate(() => this.notify());
|
|
40
|
-
}
|
|
41
|
-
peek() {
|
|
42
|
-
return this.current;
|
|
43
|
-
}
|
|
44
|
-
update(e) {
|
|
45
|
-
this.value = e(this.current);
|
|
46
|
-
}
|
|
47
|
-
}, l = class extends s {
|
|
48
|
-
dependencies = /* @__PURE__ */ new Set();
|
|
49
|
-
computing = !1;
|
|
50
|
-
disposed = !1;
|
|
51
|
-
dirty = !0;
|
|
52
|
-
current = o;
|
|
53
|
-
derive;
|
|
54
|
-
equals;
|
|
55
|
-
constructor(e, t, n) {
|
|
56
|
-
super(e, n?.name), this.derive = t, this.equals = n?.equals ?? Object.is;
|
|
57
|
-
}
|
|
58
|
-
get value() {
|
|
59
|
-
return this.runtime.track(this), this.refresh(), this.current;
|
|
60
|
-
}
|
|
61
|
-
peek() {
|
|
62
|
-
return this.refresh(), this.current;
|
|
63
|
-
}
|
|
64
|
-
onDependencyChanged() {
|
|
65
|
-
this.disposed || (this.dirty ||= !0, this.dependents.size > 0 && this.refresh() && this.notify());
|
|
66
|
-
}
|
|
67
|
-
dispose() {
|
|
68
|
-
this.disposed || (this.disposed = !0, this.runtime.clearDependencies(this), this.dependents.clear());
|
|
69
|
-
}
|
|
70
|
-
refresh() {
|
|
71
|
-
if (!this.dirty || this.disposed) return !1;
|
|
72
|
-
if (this.computing) {
|
|
73
|
-
let t = this.name === void 0 ? "" : ` "${this.name}"`;
|
|
74
|
-
throw new e(`computed cycle detected${t}`);
|
|
75
|
-
}
|
|
76
|
-
this.computing = !0, this.runtime.emit({
|
|
77
|
-
kind: "compute",
|
|
78
|
-
name: this.name
|
|
79
|
-
});
|
|
80
|
-
try {
|
|
81
|
-
let e = this.runtime.collect(this, this.derive), t = this.current === o || !this.equals(this.current, e);
|
|
82
|
-
return this.current = e, this.dirty = !1, t;
|
|
83
|
-
} finally {
|
|
84
|
-
this.computing = !1;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}, u = class {
|
|
88
|
-
disposalController = new AbortController();
|
|
89
|
-
owned = /* @__PURE__ */ new Set();
|
|
90
|
-
name;
|
|
91
|
-
isDisposed = !1;
|
|
92
|
-
runtime;
|
|
93
|
-
constructor(e, t) {
|
|
94
|
-
this.runtime = e, this.name = t;
|
|
95
|
-
}
|
|
96
|
-
get disposed() {
|
|
97
|
-
return this.isDisposed;
|
|
98
|
-
}
|
|
99
|
-
get disposalSignal() {
|
|
100
|
-
return this.disposalController.signal;
|
|
101
|
-
}
|
|
102
|
-
run(e) {
|
|
103
|
-
if (this.isDisposed) throw new n("Cannot run a disposed scope.");
|
|
104
|
-
return this.runtime.withScope(this, e);
|
|
105
|
-
}
|
|
106
|
-
dispose() {
|
|
107
|
-
if (!this.isDisposed) {
|
|
108
|
-
this.isDisposed = !0;
|
|
109
|
-
for (let e of [...this.owned].reverse()) e.dispose();
|
|
110
|
-
this.owned.clear(), this.disposalController.abort(), this.runtime.emit({
|
|
111
|
-
kind: "dispose",
|
|
112
|
-
name: this.name,
|
|
113
|
-
node: "scope"
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
[Symbol.dispose]() {
|
|
118
|
-
this.dispose();
|
|
119
|
-
}
|
|
120
|
-
}, d = class {
|
|
121
|
-
dependencies = /* @__PURE__ */ new Set();
|
|
122
|
-
disposalController = new AbortController();
|
|
123
|
-
cleanup;
|
|
124
|
-
isDisposed = !1;
|
|
125
|
-
owner;
|
|
126
|
-
scheduled = !1;
|
|
127
|
-
callback;
|
|
128
|
-
options;
|
|
129
|
-
runtime;
|
|
130
|
-
constructor(e, t, n) {
|
|
131
|
-
this.runtime = e, this.callback = t, this.options = n;
|
|
132
|
-
}
|
|
133
|
-
get disposed() {
|
|
134
|
-
return this.isDisposed;
|
|
135
|
-
}
|
|
136
|
-
get disposalSignal() {
|
|
137
|
-
return this.disposalController.signal;
|
|
138
|
-
}
|
|
139
|
-
onDependencyChanged() {
|
|
140
|
-
if (!this.isDisposed) {
|
|
141
|
-
if (this.options?.scheduler === "microtask") {
|
|
142
|
-
if (this.scheduled) return;
|
|
143
|
-
this.scheduled = !0, queueMicrotask(() => {
|
|
144
|
-
this.scheduled = !1, this.isDisposed || this.runtime.enqueue(this);
|
|
145
|
-
});
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
this.runtime.enqueue(this);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
run() {
|
|
152
|
-
if (this.isDisposed) return;
|
|
153
|
-
this.owner?.dispose(), this.owner = void 0, this.runCleanup(), this.runtime.emit({
|
|
154
|
-
kind: "effect",
|
|
155
|
-
name: this.options?.name
|
|
156
|
-
});
|
|
157
|
-
let e = new u(this.runtime);
|
|
158
|
-
try {
|
|
159
|
-
let t = this.runtime.withEffectScope(e, () => this.runtime.collectEffect(this, this.callback));
|
|
160
|
-
this.owner = e, this.cleanup = typeof t == "function" ? t : void 0;
|
|
161
|
-
} catch (t) {
|
|
162
|
-
e.dispose(), this.runtime.report(t, {
|
|
163
|
-
kind: "effect",
|
|
164
|
-
name: this.options?.name
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
dispose() {
|
|
169
|
-
this.isDisposed || (this.isDisposed = !0, this.owner?.dispose(), this.owner = void 0, this.runtime.clearDependencies(this), this.runCleanup(), this.disposalController.abort(), this.runtime.emit({
|
|
170
|
-
kind: "dispose",
|
|
171
|
-
name: this.options?.name,
|
|
172
|
-
node: "effect"
|
|
173
|
-
}));
|
|
174
|
-
}
|
|
175
|
-
[Symbol.dispose]() {
|
|
176
|
-
this.dispose();
|
|
177
|
-
}
|
|
178
|
-
runCleanup() {
|
|
179
|
-
let e = this.cleanup;
|
|
180
|
-
if (this.cleanup = void 0, e !== void 0) try {
|
|
181
|
-
e();
|
|
182
|
-
} catch (e) {
|
|
183
|
-
this.runtime.report(e, {
|
|
184
|
-
kind: "cleanup",
|
|
185
|
-
name: this.options?.name
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}, f = class {
|
|
190
|
-
activeEffectScope;
|
|
191
|
-
activeObserver;
|
|
192
|
-
activeScope;
|
|
193
|
-
isDisposed = !1;
|
|
194
|
-
flushDepth = 0;
|
|
195
|
-
flushing = !1;
|
|
196
|
-
pending = /* @__PURE__ */ new Set();
|
|
197
|
-
listeners = /* @__PURE__ */ new Set();
|
|
198
|
-
rootScope;
|
|
199
|
-
observer;
|
|
200
|
-
onError;
|
|
201
|
-
constructor(e) {
|
|
202
|
-
this.observer = e?.observer, this.onError = e?.onError ?? ((e) => {
|
|
203
|
-
queueMicrotask(() => {
|
|
204
|
-
throw e;
|
|
205
|
-
});
|
|
206
|
-
}), this.rootScope = new u(this, "runtime"), this.activeScope = this.rootScope;
|
|
207
|
-
}
|
|
208
|
-
get disposed() {
|
|
209
|
-
return this.isDisposed;
|
|
210
|
-
}
|
|
211
|
-
get disposalSignal() {
|
|
212
|
-
return this.rootScope.disposalSignal;
|
|
213
|
-
}
|
|
214
|
-
signal = (e, t) => (this.assertActive(), new c(this, e, t));
|
|
215
|
-
computed = (e, t) => {
|
|
216
|
-
this.assertActive();
|
|
217
|
-
let n = new l(this, e, t);
|
|
218
|
-
return (this.activeEffectScope ?? this.activeScope).owned.add(n), n;
|
|
219
|
-
};
|
|
220
|
-
effect = (e, t) => {
|
|
221
|
-
this.assertActive();
|
|
222
|
-
let n = new d(this, e, t);
|
|
223
|
-
return (this.activeEffectScope ?? this.activeScope).owned.add(n), n.run(), n;
|
|
224
|
-
};
|
|
225
|
-
createScope = (e) => {
|
|
226
|
-
this.assertActive();
|
|
227
|
-
let t = new u(this, e);
|
|
228
|
-
return this.activeScope.owned.add(t), t;
|
|
229
|
-
};
|
|
230
|
-
batch = (e) => (this.assertActive(), this.propagate(e));
|
|
231
|
-
untrack = (e) => (this.assertActive(), this.withObserver(void 0, e));
|
|
232
|
-
dispose() {
|
|
233
|
-
this.isDisposed || (this.isDisposed = !0, this.rootScope.dispose());
|
|
234
|
-
}
|
|
235
|
-
assertActive() {
|
|
236
|
-
if (this.isDisposed) throw new t("Cannot use a disposed Ripple runtime.");
|
|
237
|
-
}
|
|
238
|
-
track(e) {
|
|
239
|
-
let t = this.activeObserver;
|
|
240
|
-
t?.collecting !== void 0 && t.collecting.add(e);
|
|
241
|
-
}
|
|
242
|
-
clearDependencies(e) {
|
|
243
|
-
for (let t of e.dependencies) t.dependents.delete(e);
|
|
244
|
-
e.dependencies.clear();
|
|
245
|
-
}
|
|
246
|
-
collect(e, t) {
|
|
247
|
-
return this.collectWith(e, t, e.dependencies.size === 0);
|
|
248
|
-
}
|
|
249
|
-
collectEffect(e, t) {
|
|
250
|
-
return this.collectWith(e, t, !0);
|
|
251
|
-
}
|
|
252
|
-
withEffectScope(e, t) {
|
|
253
|
-
let n = this.activeEffectScope;
|
|
254
|
-
this.activeEffectScope = e;
|
|
255
|
-
try {
|
|
256
|
-
return t();
|
|
257
|
-
} finally {
|
|
258
|
-
this.activeEffectScope = n;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
withObserver(e, t) {
|
|
262
|
-
let n = this.activeObserver;
|
|
263
|
-
this.activeObserver = e;
|
|
264
|
-
try {
|
|
265
|
-
return t();
|
|
266
|
-
} finally {
|
|
267
|
-
this.activeObserver = n;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
withScope(e, t) {
|
|
271
|
-
let n = this.activeEffectScope, r = this.activeScope;
|
|
272
|
-
this.activeEffectScope = void 0, this.activeScope = e;
|
|
273
|
-
try {
|
|
274
|
-
return t();
|
|
275
|
-
} finally {
|
|
276
|
-
this.activeEffectScope = n, this.activeScope = r;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
enqueue(e) {
|
|
280
|
-
this.pending.add(e), this.flushDepth === 0 && this.flush();
|
|
281
|
-
}
|
|
282
|
-
enqueueListener(e) {
|
|
283
|
-
this.listeners.add(e), this.flushDepth === 0 && this.flush();
|
|
284
|
-
}
|
|
285
|
-
propagate(e) {
|
|
286
|
-
this.flushDepth++;
|
|
287
|
-
try {
|
|
288
|
-
return e();
|
|
289
|
-
} finally {
|
|
290
|
-
this.flushDepth--, this.flushDepth === 0 && this.flush();
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
emit(e) {
|
|
294
|
-
try {
|
|
295
|
-
this.observer?.(e);
|
|
296
|
-
} catch (t) {
|
|
297
|
-
this.report(t, {
|
|
298
|
-
kind: "observer",
|
|
299
|
-
name: e.name
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
report(e, t) {
|
|
304
|
-
try {
|
|
305
|
-
this.onError(e, t);
|
|
306
|
-
} catch (e) {
|
|
307
|
-
queueMicrotask(() => {
|
|
308
|
-
throw e;
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
collectWith(e, t, n) {
|
|
313
|
-
let r = this.activeObserver, i = /* @__PURE__ */ new Set();
|
|
314
|
-
e.collecting = i, this.activeObserver = e;
|
|
315
|
-
try {
|
|
316
|
-
let n = t();
|
|
317
|
-
return this.commitDependencies(e, i), n;
|
|
318
|
-
} catch (t) {
|
|
319
|
-
throw n && this.commitDependencies(e, i), t;
|
|
320
|
-
} finally {
|
|
321
|
-
e.collecting = void 0, this.activeObserver = r;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
commitDependencies(e, t) {
|
|
325
|
-
for (let n of e.dependencies) t.has(n) || n.dependents.delete(e);
|
|
326
|
-
for (let n of t) e.dependencies.has(n) || n.dependents.add(e);
|
|
327
|
-
e.dependencies.clear();
|
|
328
|
-
for (let n of t) e.dependencies.add(n);
|
|
329
|
-
}
|
|
330
|
-
flush() {
|
|
331
|
-
if (this.flushing) return;
|
|
332
|
-
this.flushing = !0;
|
|
333
|
-
let e = 0;
|
|
334
|
-
try {
|
|
335
|
-
for (; this.pending.size > 0 || this.listeners.size > 0;) {
|
|
336
|
-
if (++e > a) throw new r(`infinite reactive flush (>${a} iterations)`);
|
|
337
|
-
let t = [...this.pending], n = [...this.listeners];
|
|
338
|
-
this.pending.clear(), this.listeners.clear();
|
|
339
|
-
for (let e of t) e.run();
|
|
340
|
-
for (let e of n) try {
|
|
341
|
-
e();
|
|
342
|
-
} catch (e) {
|
|
343
|
-
this.report(e, { kind: "listener" });
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
} finally {
|
|
347
|
-
this.flushing = !1;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}, p = (e) => {
|
|
351
|
-
if (typeof e != "object" || !e || !(i in e)) return !1;
|
|
352
|
-
let t = e;
|
|
353
|
-
return typeof t.peek == "function" && typeof t.subscribe == "function";
|
|
354
|
-
};
|
|
355
|
-
//#endregion
|
|
356
|
-
export { i as REACTIVE, f as ReactiveRuntime, p as isReactive };
|
|
357
|
-
|
|
1
|
+
import{RippleComputedCycleError as e,RippleDisposedRuntimeError as t,RippleDisposedScopeError as n,RippleInfiniteLoopError as r}from"./errors.js";var i=Symbol.for(`@vielzeug/ripple/reactive`),a=100,o=Symbol(`ripple.unset`),ReactiveNode=class{[i]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.runtime.assertActive(),this.peek();let t={listener:e,onDependencyChanged:()=>this.runtime.enqueueListener(t)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},SignalNode=class extends ReactiveNode{current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){if(this.runtime.assertActive(),this.equals(this.current,e))return;let t=this.current;this.current=e,this.runtime.emit({name:this.name,next:e,previous:t,type:`write`}),this.runtime.propagate(()=>this.notify())}peek(){return this.current}update(e){this.value=e(this.current)}},ComputedNode=class extends ReactiveNode{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=o;derive;equals;owner;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.refresh(),this.current}peek(){return this.refresh(),this.current}onDependencyChanged(){if(!this.disposed&&(this.dirty||=!0,this.dependents.size>0))try{this.refresh()&&this.notify()}catch(e){this.runtime.report(e,{kind:`computed`,name:this.name})}}setOwner(e){this.owner=e}dispose(){this.disposed||(this.disposed=!0,this.owner?.release(this),this.owner=void 0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing){let t=this.name===void 0?``:` "${this.name}"`;throw new e(`computed cycle detected${t}`)}this.computing=!0,this.runtime.emit({name:this.name,type:`compute`});try{let e=this.runtime.collect(this,this.derive),t=this.current===o||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},ScopeNode=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;owner;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}own(e){e.setOwner(this),this.owned.add(e)}release(e){this.owned.delete(e)}setOwner(e){this.owner=e}run(e){if(this.isDisposed)throw new n(`Cannot run a disposed scope.`);return this.runtime.withScope(this,e)}dispose(){if(!this.isDisposed){this.isDisposed=!0,this.owner?.release(this),this.owner=void 0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort(),this.runtime.emit({name:this.name,node:`scope`,type:`dispose`})}}[Symbol.dispose](){this.dispose()}},EffectNode=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;ownershipScope;runScope;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}setOwner(e){this.ownershipScope=e}onDependencyChanged(){this.isDisposed||this.runtime.enqueue(this)}run(){if(this.isDisposed)return;this.runScope?.dispose(),this.runScope=void 0,this.runCleanup(),this.runtime.emit({name:this.options?.name,type:`effect`});let e=new ScopeNode(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.runScope=e,this.cleanup=typeof t==`function`?t:void 0,this.isDisposed&&(this.runScope.dispose(),this.runScope=void 0,this.runCleanup())}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.ownershipScope?.release(this),this.ownershipScope=void 0,this.runScope?.dispose(),this.runScope=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort(),this.runtime.emit({name:this.options?.name,node:`effect`,type:`dispose`}))}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},ReactiveRuntime=class{activeEffectScope;activeObserver;activeScope;isDisposed=!1;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;tappers=new Set;errorPolicy;constructor(e){this.errorPolicy=e?.errorPolicy??`throw`,this.rootScope=new ScopeNode(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}get disposalSignal(){return this.rootScope.disposalSignal}signal=(e,t)=>(this.assertActive(),new SignalNode(this,e,t));computed=(e,t)=>{this.assertActive();let n=new ComputedNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n};effect=(e,t)=>{this.assertActive();let n=new EffectNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n.run(),n};createScope=e=>{this.assertActive();let t=new ScopeNode(this,e);return this.activeScope.own(t),t};batch=e=>(this.assertActive(),this.propagate(e));untrack=e=>(this.assertActive(),this.withObserver(void 0,e));tap=(e,t)=>{if(this.isDisposed)return()=>{};let n=t?.signal;if(n?.aborted)return this.tappers.delete(e),()=>{};if(this.tappers.add(e),n){let onAbort=()=>this.tappers.delete(e);return n.addEventListener(`abort`,onAbort,{once:!0}),()=>{this.tappers.delete(e),n.removeEventListener(`abort`,onAbort)}}return()=>this.tappers.delete(e)};dispose(){this.isDisposed||(this.isDisposed=!0,this.rootScope.dispose(),this.emit({node:`graph`,type:`dispose`}),this.tappers.clear())}assertActive(){if(this.isDisposed)throw new t(`Cannot use a disposed Ripple runtime.`)}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,e.dependencies.size===0)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}emit(e){if(this.tappers.size!==0)for(let t of this.tappers)try{t(e)}catch{}}report(e,t){this.emit({context:t,error:e,type:`error`}),this.errorPolicy===`throw`&&queueMicrotask(()=>{throw e})}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let e=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++e>a)throw new r(`infinite reactive flush (>${a} iterations)`);let t=[...this.pending],n=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of t)e.run();for(let e of n)try{e.listener()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},isReactive=e=>{if(typeof e!=`object`||!e||e[i]!==!0)return!1;let t=e;return`value`in t&&typeof t.peek==`function`&&typeof t.subscribe==`function`};export{i as REACTIVE,ReactiveRuntime,isReactive};
|
|
358
2
|
//# sourceMappingURL=runtime.js.map
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import {\n RippleComputedCycleError,\n RippleDisposedRuntimeError,\n RippleDisposedScopeError,\n RippleInfiniteLoopError,\n} from './errors';\nimport type {\n Cleanup,\n ComputedOptions,\n EffectHandle,\n EffectOptions,\n ReactiveErrorContext,\n ReactiveObserver,\n Readable,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Unsubscribe,\n} from './types';\n\nexport const REACTIVE = Symbol.for('@vielzeug/ripple/reactive');\nconst MAX_FLUSH_ITERATIONS = 100;\nconst UNSET = Symbol('ripple.unset');\n\ntype Dependency = ReactiveNode<unknown>;\n\ntype ObserverNode = {\n collecting?: Set<Dependency>;\n readonly dependencies: Set<Dependency>;\n onDependencyChanged(): void;\n};\n\ntype Owned = {\n dispose(): void;\n};\n\nabstract class ReactiveNode<T> {\n readonly [REACTIVE] = true;\n readonly dependents = new Set<ObserverNode>();\n readonly name: string | undefined;\n protected readonly runtime: ReactiveRuntime;\n\n protected constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n abstract peek(): T;\n abstract get value(): T;\n\n subscribe(listener: () => void): Unsubscribe {\n this.runtime.assertActive();\n this.peek();\n\n const observer: ObserverNode = {\n dependencies: new Set(),\n onDependencyChanged: () => this.runtime.enqueueListener(listener),\n };\n\n this.dependents.add(observer);\n\n return () => this.dependents.delete(observer);\n }\n\n protected notify(): void {\n for (const dependent of [...this.dependents]) dependent.onDependencyChanged();\n }\n}\n\nclass SignalNode<T> extends ReactiveNode<T> implements Signal<T> {\n private current: T;\n private readonly equals: (previous: T, next: T) => boolean;\n\n constructor(runtime: ReactiveRuntime, initial: T, options?: SignalOptions<T>) {\n super(runtime, options?.name);\n this.current = initial;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n this.runtime.track(this);\n\n return this.current;\n }\n\n set value(next: T) {\n this.runtime.assertActive();\n\n if (this.equals(this.current, next)) return;\n\n const previous = this.current;\n\n this.current = next;\n this.runtime.emit({ kind: 'write', name: this.name, next, previous });\n this.runtime.propagate(() => this.notify());\n }\n\n peek(): T {\n return this.current;\n }\n\n update(updater: (prev: T) => T): void {\n this.value = updater(this.current);\n }\n}\n\nclass ComputedNode<T> extends ReactiveNode<T> implements ObserverNode, Owned {\n readonly dependencies = new Set<Dependency>();\n private computing = false;\n private disposed = false;\n private dirty = true;\n private current: T | typeof UNSET = UNSET;\n private readonly derive: () => T;\n private readonly equals: (previous: T, next: T) => boolean;\n\n constructor(runtime: ReactiveRuntime, derive: () => T, options?: ComputedOptions<T>) {\n super(runtime, options?.name);\n this.derive = derive;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n // Track before refresh: if refresh throws, the consumer still depends on\n // this computed and must be notified when a dependency change might let it\n // succeed. Without this, a first-run failure permanently severs the\n // consumer from the computed.\n this.runtime.track(this);\n this.refresh();\n\n return this.current as T;\n }\n\n peek(): T {\n this.refresh();\n\n return this.current as T;\n }\n\n onDependencyChanged(): void {\n if (this.disposed) return;\n\n if (!this.dirty) this.dirty = true;\n\n if (this.dependents.size > 0 && this.refresh()) this.notify();\n }\n\n dispose(): void {\n if (this.disposed) return;\n\n this.disposed = true;\n this.runtime.clearDependencies(this);\n this.dependents.clear();\n }\n\n private refresh(): boolean {\n if (!this.dirty || this.disposed) return false;\n\n if (this.computing) {\n const label = this.name === undefined ? '' : ` \"${this.name}\"`;\n\n throw new RippleComputedCycleError(`computed cycle detected${label}`);\n }\n\n this.computing = true;\n this.runtime.emit({ kind: 'compute', name: this.name });\n\n try {\n const next = this.runtime.collect(this, this.derive);\n const changed = this.current === UNSET || !this.equals(this.current as T, next);\n\n this.current = next;\n this.dirty = false;\n\n return changed;\n } finally {\n this.computing = false;\n }\n }\n}\n\nclass ScopeNode implements Scope {\n readonly disposalController = new AbortController();\n readonly owned = new Set<Owned>();\n readonly name: string | undefined;\n private isDisposed = false;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n run<T>(fn: () => T): T {\n if (this.isDisposed) throw new RippleDisposedScopeError('Cannot run a disposed scope.');\n\n return this.runtime.withScope(this, fn);\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n for (const owned of [...this.owned].reverse()) owned.dispose();\n this.owned.clear();\n this.disposalController.abort();\n this.runtime.emit({ kind: 'dispose', name: this.name, node: 'scope' });\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n}\n\nclass EffectNode implements ObserverNode, EffectHandle {\n readonly dependencies = new Set<Dependency>();\n readonly disposalController = new AbortController();\n private cleanup: Cleanup | undefined;\n private isDisposed = false;\n private owner: ScopeNode | undefined;\n private scheduled = false;\n private readonly callback: () => Cleanup | undefined;\n private readonly options: EffectOptions | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, callback: () => Cleanup | undefined, options?: EffectOptions) {\n this.runtime = runtime;\n this.callback = callback;\n this.options = options;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n onDependencyChanged(): void {\n if (this.isDisposed) return;\n\n if (this.options?.scheduler === 'microtask') {\n if (this.scheduled) return;\n\n this.scheduled = true;\n queueMicrotask(() => {\n this.scheduled = false;\n\n if (!this.isDisposed) this.runtime.enqueue(this);\n });\n\n return;\n }\n\n this.runtime.enqueue(this);\n }\n\n run(): void {\n if (this.isDisposed) return;\n\n this.owner?.dispose();\n this.owner = undefined;\n this.runCleanup();\n this.runtime.emit({ kind: 'effect', name: this.options?.name });\n\n const owner = new ScopeNode(this.runtime);\n\n try {\n const cleanup = this.runtime.withEffectScope(owner, () => this.runtime.collectEffect(this, this.callback));\n\n this.owner = owner;\n this.cleanup = typeof cleanup === 'function' ? cleanup : undefined;\n } catch (error) {\n owner.dispose();\n this.runtime.report(error, { kind: 'effect', name: this.options?.name });\n }\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.owner?.dispose();\n this.owner = undefined;\n this.runtime.clearDependencies(this);\n this.runCleanup();\n this.disposalController.abort();\n this.runtime.emit({ kind: 'dispose', name: this.options?.name, node: 'effect' });\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n private runCleanup(): void {\n const cleanup = this.cleanup;\n\n this.cleanup = undefined;\n\n if (cleanup === undefined) return;\n\n try {\n cleanup();\n } catch (error) {\n this.runtime.report(error, { kind: 'cleanup', name: this.options?.name });\n }\n }\n}\n\n/**\n * A runtime owns reactive graph state and lifetime. Separate instances isolate\n * applications and SSR requests without process-wide mutable hooks.\n */\nexport class ReactiveRuntime {\n private activeEffectScope: ScopeNode | undefined;\n private activeObserver: ObserverNode | undefined;\n private activeScope: ScopeNode;\n private isDisposed = false;\n private flushDepth = 0;\n private flushing = false;\n private readonly pending = new Set<EffectNode>();\n private readonly listeners = new Set<() => void>();\n private readonly rootScope: ScopeNode;\n private readonly observer: ReactiveObserver | undefined;\n private readonly onError: (error: unknown, context: ReactiveErrorContext) => void;\n\n constructor(options?: RippleOptions) {\n this.observer = options?.observer;\n this.onError =\n options?.onError ??\n ((error) => {\n queueMicrotask(() => {\n throw error;\n });\n });\n this.rootScope = new ScopeNode(this, 'runtime');\n this.activeScope = this.rootScope;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.rootScope.disposalSignal;\n }\n\n readonly signal = <T>(initial: T, options?: SignalOptions<T>): Signal<T> => {\n this.assertActive();\n\n return new SignalNode(this, initial, options);\n };\n\n readonly computed = <T>(derive: () => T, options?: ComputedOptions<T>): Readable<T> => {\n this.assertActive();\n\n const node = new ComputedNode(this, derive, options);\n\n (this.activeEffectScope ?? this.activeScope).owned.add(node);\n\n return node;\n };\n\n readonly effect = (callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle => {\n this.assertActive();\n\n const node = new EffectNode(this, callback, options);\n\n (this.activeEffectScope ?? this.activeScope).owned.add(node);\n node.run();\n\n return node;\n };\n\n readonly createScope = (name?: string): Scope => {\n this.assertActive();\n\n const scope = new ScopeNode(this, name);\n\n // Scopes model explicit, caller-owned lifetimes. Unlike effects/computeds created during an\n // effect run, they deliberately attach to the enclosing scope rather than the per-run owner:\n // keyed DOM directives retain item scopes across reconciliation runs and dispose them only\n // when the item itself leaves the collection.\n this.activeScope.owned.add(scope);\n\n return scope;\n };\n\n readonly batch = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.propagate(fn);\n };\n\n readonly untrack = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.withObserver(undefined, fn);\n };\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.rootScope.dispose();\n }\n\n /** Internal node guard: disposed runtimes allow inert reads but reject graph work and mutation. */\n assertActive(): void {\n if (this.isDisposed) throw new RippleDisposedRuntimeError('Cannot use a disposed Ripple runtime.');\n }\n\n track(node: Dependency): void {\n const observer = this.activeObserver;\n\n if (observer?.collecting === undefined) return;\n\n observer.collecting.add(node);\n }\n\n clearDependencies(observer: ObserverNode): void {\n for (const dependency of observer.dependencies) dependency.dependents.delete(observer);\n observer.dependencies.clear();\n }\n\n collect<T>(observer: ObserverNode, fn: () => T): T {\n // On first run (no prior dependencies), commit partial dependencies even if\n // derive throws — otherwise the computed would have zero dependencies and never\n // be notified when its source changes, permanently stuck until a manual read.\n // On subsequent runs, keep previous dependencies (tested behavior).\n return this.collectWith(observer, fn, observer.dependencies.size === 0);\n }\n\n collectEffect<T>(observer: ObserverNode, fn: () => T): T {\n return this.collectWith(observer, fn, true);\n }\n\n withEffectScope<T>(scope: ScopeNode, fn: () => T): T {\n const previous = this.activeEffectScope;\n\n this.activeEffectScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previous;\n }\n }\n\n withObserver<T>(observer: ObserverNode | undefined, fn: () => T): T {\n const previous = this.activeObserver;\n\n this.activeObserver = observer;\n\n try {\n return fn();\n } finally {\n this.activeObserver = previous;\n }\n }\n\n withScope<T>(scope: ScopeNode, fn: () => T): T {\n const previousEffectScope = this.activeEffectScope;\n const previousScope = this.activeScope;\n\n this.activeEffectScope = undefined;\n this.activeScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previousEffectScope;\n this.activeScope = previousScope;\n }\n }\n\n enqueue(effect: EffectNode): void {\n this.pending.add(effect);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n enqueueListener(listener: () => void): void {\n this.listeners.add(listener);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n propagate<T>(fn: () => T): T {\n this.flushDepth++;\n\n try {\n return fn();\n } finally {\n this.flushDepth--;\n\n if (this.flushDepth === 0) this.flush();\n }\n }\n\n emit(event: Parameters<ReactiveObserver>[0]): void {\n try {\n this.observer?.(event);\n } catch (error) {\n this.report(error, { kind: 'observer', name: event.name });\n }\n }\n\n report(error: unknown, context: ReactiveErrorContext): void {\n try {\n this.onError(error, context);\n } catch (reporterError) {\n queueMicrotask(() => {\n throw reporterError;\n });\n }\n }\n\n private collectWith<T>(observer: ObserverNode, fn: () => T, commitOnError: boolean): T {\n const previousObserver = this.activeObserver;\n const dependencies = new Set<Dependency>();\n\n observer.collecting = dependencies;\n this.activeObserver = observer;\n\n try {\n const result = fn();\n\n this.commitDependencies(observer, dependencies);\n\n return result;\n } catch (error) {\n if (commitOnError) this.commitDependencies(observer, dependencies);\n\n throw error;\n } finally {\n observer.collecting = undefined;\n this.activeObserver = previousObserver;\n }\n }\n\n private commitDependencies(observer: ObserverNode, next: Set<Dependency>): void {\n for (const dependency of observer.dependencies) {\n if (!next.has(dependency)) dependency.dependents.delete(observer);\n }\n\n for (const dependency of next) {\n if (!observer.dependencies.has(dependency)) dependency.dependents.add(observer);\n }\n\n observer.dependencies.clear();\n for (const dependency of next) observer.dependencies.add(dependency);\n }\n\n private flush(): void {\n if (this.flushing) return;\n\n this.flushing = true;\n\n let iterations = 0;\n\n try {\n while (this.pending.size > 0 || this.listeners.size > 0) {\n if (++iterations > MAX_FLUSH_ITERATIONS) {\n throw new RippleInfiniteLoopError(`infinite reactive flush (>${MAX_FLUSH_ITERATIONS} iterations)`);\n }\n\n const effects = [...this.pending];\n const listeners = [...this.listeners];\n\n this.pending.clear();\n this.listeners.clear();\n\n for (const effect of effects) effect.run();\n\n for (const listener of listeners) {\n try {\n listener();\n } catch (error) {\n this.report(error, { kind: 'listener' });\n }\n }\n }\n } finally {\n this.flushing = false;\n }\n }\n}\n\nexport const isReactive = <T>(value: T | Readable<T>): value is Readable<T> => {\n if (typeof value !== 'object' || value === null || !(REACTIVE in value)) return false;\n\n const candidate = value as { peek?: unknown; subscribe?: unknown };\n\n return typeof candidate.peek === 'function' && typeof candidate.subscribe === 'function';\n};\n"],"mappings":";;AAqBA,IAAa,IAAW,OAAO,IAAI,2BAA2B,GACxD,IAAuB,KACvB,IAAQ,OAAO,cAAc,GAcpB,IAAf,MAA+B;CAC7B,CAAU,KAAY;CACtB,6BAAsB,IAAI,IAAkB;CAC5C;CACA;CAEA,YAAsB,GAA0B,GAAe;EAE7D,AADA,KAAK,UAAU,GACf,KAAK,OAAO;CACd;CAKA,UAAU,GAAmC;EAE3C,AADA,KAAK,QAAQ,aAAa,GAC1B,KAAK,KAAK;EAEV,IAAM,IAAyB;GAC7B,8BAAc,IAAI,IAAI;GACtB,2BAA2B,KAAK,QAAQ,gBAAgB,CAAQ;EAClE;EAIA,OAFA,KAAK,WAAW,IAAI,CAAQ,SAEf,KAAK,WAAW,OAAO,CAAQ;CAC9C;CAEA,SAAyB;EACvB,KAAK,IAAM,KAAa,CAAC,GAAG,KAAK,UAAU,GAAG,EAAU,oBAAoB;CAC9E;AACF,GAEM,IAAN,cAA4B,EAAqC;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AQ;EAGlE,KAAK,IAAM,KAAc,GACvB,AAAK,EAAS,aAAa,IAAI,CAAU,KAAG,EAAW,WAAW,IAAI,CAAQ;EAGhF,EAAS,aAAa,MAAM;EAC5B,KAAK,IAAM,KAAc,GAAM,EAAS,aAAa,IAAI,CAAU;CACrE;CAEA,QAAsB;EACpB,IAAI,KAAK,UAAU;EAEnB,KAAK,WAAW;EAEhB,IAAI,IAAa;EAEjB,IAAI;GACF,OAAO,KAAK,QAAQ,OAAO,KAAK,KAAK,UAAU,OAAO,IAAG;IACvD,IAAI,EAAE,IAAa,GACjB,MAAM,IAAI,EAAwB,6BAA6B,EAAqB,aAAa;IAGnG,IAAM,IAAU,CAAC,GAAG,KAAK,OAAO,GAC1B,IAAY,CAAC,GAAG,KAAK,SAAS;IAGpC,AADA,KAAK,QAAQ,MAAM,GACnB,KAAK,UAAU,MAAM;IAErB,KAAK,IAAM,KAAU,GAAS,EAAO,IAAI;IAEzC,KAAK,IAAM,KAAY,GACrB,IAAI;KACF,EAAS;IACX,SAAS,GAAO;KACd,KAAK,OAAO,GAAO,EAAE,MAAM,WAAW,CAAC;IACzC;GAEJ;EACF,UAAU;GACR,KAAK,WAAW;EAClB;CACF;AACF,GAEa,KAAiB,MAAiD;CAC7E,IAAI,OAAO,KAAU,aAAY,KAAkB,EAAE,KAAY,IAAQ,OAAO;CAEhF,IAAM,IAAY;CAElB,OAAO,OAAO,EAAU,QAAS,cAAc,OAAO,EAAU,aAAc;AAChF"}
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import {\n RippleComputedCycleError,\n RippleDisposedRuntimeError,\n RippleDisposedScopeError,\n RippleInfiniteLoopError,\n} from './errors';\nimport type {\n Cleanup,\n ComputedOptions,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleErrorContext,\n RippleErrorPolicy,\n RippleEvent,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Unsubscribe,\n} from './types';\n\nexport const REACTIVE = Symbol.for('@vielzeug/ripple/reactive');\nconst MAX_FLUSH_ITERATIONS = 100;\nconst UNSET = Symbol('ripple.unset');\n\ntype Dependency = ReactiveNode<unknown>;\n\n/** Anything that wants to hear that a dependency changed — the only member a producer may call. */\ntype Dependent = {\n onDependencyChanged(): void;\n};\n\n/** A subscribe() listener sink: enqueued as a unit so two subscriptions sharing one\n * callback each fire per flush, while one subscription never fires twice. */\ntype ListenerSink = Dependent & {\n readonly listener: () => void;\n};\n\n/** A dependency-collecting observer (computed or effect). Plain listener sinks need less. */\ntype ObserverNode = Dependent & {\n collecting?: Set<Dependency>;\n readonly dependencies: Set<Dependency>;\n};\n\ntype Owned = {\n dispose(): void;\n setOwner(owner: ScopeNode | undefined): void;\n};\n\nabstract class ReactiveNode<T> {\n readonly [REACTIVE] = true;\n readonly dependents = new Set<Dependent>();\n readonly name: string | undefined;\n protected readonly runtime: ReactiveRuntime;\n\n protected constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n abstract peek(): T;\n abstract get value(): T;\n\n subscribe(listener: () => void): Unsubscribe {\n this.runtime.assertActive();\n this.peek();\n\n // A listener sink never collects dependencies, so it is a bare dependent —\n // no dependency bookkeeping is allocated per subscription.\n const sink: ListenerSink = {\n listener,\n onDependencyChanged: () => this.runtime.enqueueListener(sink),\n };\n\n this.dependents.add(sink);\n\n return () => this.dependents.delete(sink);\n }\n\n protected notify(): void {\n for (const dependent of [...this.dependents]) dependent.onDependencyChanged();\n }\n}\n\nclass SignalNode<T> extends ReactiveNode<T> implements Signal<T> {\n private current: T;\n private readonly equals: (previous: T, next: T) => boolean;\n\n constructor(runtime: ReactiveRuntime, initial: T, options?: SignalOptions<T>) {\n super(runtime, options?.name);\n this.current = initial;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n this.runtime.track(this);\n\n return this.current;\n }\n\n set value(next: T) {\n this.runtime.assertActive();\n\n if (this.equals(this.current, next)) return;\n\n const previous = this.current;\n\n this.current = next;\n this.runtime.emit({ name: this.name, next, previous, type: 'write' });\n this.runtime.propagate(() => this.notify());\n }\n\n peek(): T {\n return this.current;\n }\n\n update(updater: (prev: T) => T): void {\n this.value = updater(this.current);\n }\n}\n\nclass ComputedNode<T> extends ReactiveNode<T> implements ObserverNode, Owned {\n readonly dependencies = new Set<Dependency>();\n private computing = false;\n private disposed = false;\n private dirty = true;\n private current: T | typeof UNSET = UNSET;\n private readonly derive: () => T;\n private readonly equals: (previous: T, next: T) => boolean;\n private owner: ScopeNode | undefined;\n\n constructor(runtime: ReactiveRuntime, derive: () => T, options?: ComputedOptions<T>) {\n super(runtime, options?.name);\n this.derive = derive;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n // Track before refresh: if refresh throws, the consumer still depends on\n // this computed and must be notified when a dependency change might let it\n // succeed. Without this, a first-run failure permanently severs the\n // consumer from the computed.\n this.runtime.track(this);\n this.refresh();\n\n return this.current as T;\n }\n\n peek(): T {\n this.refresh();\n\n return this.current as T;\n }\n\n onDependencyChanged(): void {\n if (this.disposed) return;\n\n if (!this.dirty) this.dirty = true;\n\n if (this.dependents.size > 0) {\n try {\n if (this.refresh()) this.notify();\n } catch (error) {\n this.runtime.report(error, { kind: 'computed', name: this.name });\n }\n }\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n dispose(): void {\n if (this.disposed) return;\n\n this.disposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n this.runtime.clearDependencies(this);\n this.dependents.clear();\n }\n\n private refresh(): boolean {\n if (!this.dirty || this.disposed) return false;\n\n if (this.computing) {\n const label = this.name === undefined ? '' : ` \"${this.name}\"`;\n\n throw new RippleComputedCycleError(`computed cycle detected${label}`);\n }\n\n this.computing = true;\n this.runtime.emit({ name: this.name, type: 'compute' });\n\n try {\n const next = this.runtime.collect(this, this.derive);\n const changed = this.current === UNSET || !this.equals(this.current as T, next);\n\n this.current = next;\n this.dirty = false;\n\n return changed;\n } finally {\n this.computing = false;\n }\n }\n}\n\nclass ScopeNode implements Scope, Owned {\n readonly disposalController = new AbortController();\n readonly owned = new Set<Owned>();\n readonly name: string | undefined;\n private isDisposed = false;\n private owner: ScopeNode | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n own(value: Owned): void {\n value.setOwner(this);\n this.owned.add(value);\n }\n\n release(value: Owned): void {\n this.owned.delete(value);\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n run<T>(fn: () => T): T {\n if (this.isDisposed) throw new RippleDisposedScopeError('Cannot run a disposed scope.');\n\n return this.runtime.withScope(this, fn);\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n for (const owned of [...this.owned].reverse()) owned.dispose();\n this.owned.clear();\n this.disposalController.abort();\n this.runtime.emit({ name: this.name, node: 'scope', type: 'dispose' });\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n}\n\nclass EffectNode implements ObserverNode, EffectHandle {\n readonly dependencies = new Set<Dependency>();\n readonly disposalController = new AbortController();\n private cleanup: Cleanup | undefined;\n private isDisposed = false;\n private ownershipScope: ScopeNode | undefined;\n private runScope: ScopeNode | undefined;\n private readonly callback: () => Cleanup | undefined;\n private readonly options: EffectOptions | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, callback: () => Cleanup | undefined, options?: EffectOptions) {\n this.runtime = runtime;\n this.callback = callback;\n this.options = options;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.ownershipScope = owner;\n }\n\n onDependencyChanged(): void {\n if (this.isDisposed) return;\n\n this.runtime.enqueue(this);\n }\n\n run(): void {\n if (this.isDisposed) return;\n\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runCleanup();\n this.runtime.emit({ name: this.options?.name, type: 'effect' });\n\n const owner = new ScopeNode(this.runtime);\n\n try {\n const cleanup = this.runtime.withEffectScope(owner, () => this.runtime.collectEffect(this, this.callback));\n\n this.runScope = owner;\n this.cleanup = typeof cleanup === 'function' ? cleanup : undefined;\n if (this.isDisposed) {\n this.runScope.dispose();\n this.runScope = undefined;\n this.runCleanup();\n }\n } catch (error) {\n owner.dispose();\n this.runtime.report(error, { kind: 'effect', name: this.options?.name });\n }\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.ownershipScope?.release(this);\n this.ownershipScope = undefined;\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runtime.clearDependencies(this);\n this.runCleanup();\n this.disposalController.abort();\n this.runtime.emit({ name: this.options?.name, node: 'effect', type: 'dispose' });\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n private runCleanup(): void {\n const cleanup = this.cleanup;\n\n this.cleanup = undefined;\n\n if (cleanup === undefined) return;\n\n try {\n cleanup();\n } catch (error) {\n this.runtime.report(error, { kind: 'cleanup', name: this.options?.name });\n }\n }\n}\n\n/**\n * A runtime owns reactive graph state and lifetime. Separate instances isolate\n * applications and SSR requests without process-wide mutable hooks.\n */\nexport class ReactiveRuntime {\n private activeEffectScope: ScopeNode | undefined;\n private activeObserver: ObserverNode | undefined;\n private activeScope: ScopeNode;\n private isDisposed = false;\n private flushDepth = 0;\n private flushing = false;\n private readonly pending = new Set<EffectNode>();\n private readonly listeners = new Set<ListenerSink>();\n private readonly rootScope: ScopeNode;\n private readonly tappers = new Set<(event: RippleEvent) => void>();\n private readonly errorPolicy: RippleErrorPolicy;\n\n constructor(options?: RippleOptions) {\n this.errorPolicy = options?.errorPolicy ?? 'throw';\n this.rootScope = new ScopeNode(this, 'runtime');\n this.activeScope = this.rootScope;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.rootScope.disposalSignal;\n }\n\n readonly signal = <T>(initial: T, options?: SignalOptions<T>): Signal<T> => {\n this.assertActive();\n\n return new SignalNode(this, initial, options);\n };\n\n readonly computed = <T>(derive: () => T, options?: ComputedOptions<T>): Readable<T> => {\n this.assertActive();\n\n const node = new ComputedNode(this, derive, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n\n return node;\n };\n\n readonly effect = (callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle => {\n this.assertActive();\n\n const node = new EffectNode(this, callback, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n node.run();\n\n return node;\n };\n\n readonly createScope = (name?: string): Scope => {\n this.assertActive();\n\n const scope = new ScopeNode(this, name);\n\n // Scopes model explicit, caller-owned lifetimes. Unlike effects/computeds created during an\n // effect run, they deliberately attach to the enclosing scope rather than the per-run owner:\n // keyed DOM directives retain item scopes across reconciliation runs and dispose them only\n // when the item itself leaves the collection.\n this.activeScope.own(scope);\n\n return scope;\n };\n\n readonly batch = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.propagate(fn);\n };\n\n readonly untrack = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.withObserver(undefined, fn);\n };\n\n /** Runtime observability — see `Ripple.tap()`. */\n readonly tap = (handler: (event: RippleEvent) => void, options?: { signal?: AbortSignal }): Unsubscribe => {\n if (this.isDisposed) return () => {};\n\n const signal = options?.signal;\n\n if (signal?.aborted) {\n this.tappers.delete(handler);\n return () => {};\n }\n\n this.tappers.add(handler);\n\n if (signal) {\n const onAbort = () => this.tappers.delete(handler);\n\n signal.addEventListener('abort', onAbort, { once: true });\n\n return () => {\n this.tappers.delete(handler);\n signal.removeEventListener('abort', onAbort);\n };\n }\n\n return () => this.tappers.delete(handler);\n };\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.rootScope.dispose();\n this.emit({ node: 'graph', type: 'dispose' });\n this.tappers.clear();\n }\n\n /** Internal node guard: disposed runtimes allow inert reads but reject graph work and mutation. */\n assertActive(): void {\n if (this.isDisposed) throw new RippleDisposedRuntimeError('Cannot use a disposed Ripple runtime.');\n }\n\n track(node: Dependency): void {\n const observer = this.activeObserver;\n\n if (observer?.collecting === undefined) return;\n\n observer.collecting.add(node);\n }\n\n clearDependencies(observer: ObserverNode): void {\n for (const dependency of observer.dependencies) dependency.dependents.delete(observer);\n observer.dependencies.clear();\n }\n\n collect<T>(observer: ObserverNode, fn: () => T): T {\n // On first run (no prior dependencies), commit partial dependencies even if\n // derive throws — otherwise the computed would have zero dependencies and never\n // be notified when its source changes, permanently stuck until a manual read.\n // On subsequent runs, keep previous dependencies (tested behavior).\n return this.collectWith(observer, fn, observer.dependencies.size === 0);\n }\n\n collectEffect<T>(observer: ObserverNode, fn: () => T): T {\n return this.collectWith(observer, fn, true);\n }\n\n withEffectScope<T>(scope: ScopeNode, fn: () => T): T {\n const previous = this.activeEffectScope;\n\n this.activeEffectScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previous;\n }\n }\n\n withObserver<T>(observer: ObserverNode | undefined, fn: () => T): T {\n const previous = this.activeObserver;\n\n this.activeObserver = observer;\n\n try {\n return fn();\n } finally {\n this.activeObserver = previous;\n }\n }\n\n withScope<T>(scope: ScopeNode, fn: () => T): T {\n const previousEffectScope = this.activeEffectScope;\n const previousScope = this.activeScope;\n\n this.activeEffectScope = undefined;\n this.activeScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previousEffectScope;\n this.activeScope = previousScope;\n }\n }\n\n enqueue(effect: EffectNode): void {\n this.pending.add(effect);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n enqueueListener(sink: ListenerSink): void {\n this.listeners.add(sink);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n propagate<T>(fn: () => T): T {\n this.flushDepth++;\n\n try {\n return fn();\n } finally {\n this.flushDepth--;\n\n if (this.flushDepth === 0) this.flush();\n }\n }\n\n emit(event: RippleEvent): void {\n if (this.tappers.size === 0) return;\n\n for (const tapper of this.tappers) {\n try {\n tapper(event);\n } catch {\n // Observability must not affect runtime behavior.\n }\n }\n }\n\n report(error: unknown, context: RippleErrorContext): void {\n this.emit({ context, error, type: 'error' });\n\n if (this.errorPolicy === 'throw') {\n queueMicrotask(() => {\n throw error;\n });\n }\n }\n\n private collectWith<T>(observer: ObserverNode, fn: () => T, commitOnError: boolean): T {\n const previousObserver = this.activeObserver;\n const dependencies = new Set<Dependency>();\n\n observer.collecting = dependencies;\n this.activeObserver = observer;\n\n try {\n const result = fn();\n\n this.commitDependencies(observer, dependencies);\n\n return result;\n } catch (error) {\n if (commitOnError) this.commitDependencies(observer, dependencies);\n\n throw error;\n } finally {\n observer.collecting = undefined;\n this.activeObserver = previousObserver;\n }\n }\n\n private commitDependencies(observer: ObserverNode, next: Set<Dependency>): void {\n for (const dependency of observer.dependencies) {\n if (!next.has(dependency)) dependency.dependents.delete(observer);\n }\n\n for (const dependency of next) {\n if (!observer.dependencies.has(dependency)) dependency.dependents.add(observer);\n }\n\n observer.dependencies.clear();\n for (const dependency of next) observer.dependencies.add(dependency);\n }\n\n private flush(): void {\n if (this.flushing) return;\n\n this.flushing = true;\n\n let iterations = 0;\n\n try {\n while (this.pending.size > 0 || this.listeners.size > 0) {\n if (++iterations > MAX_FLUSH_ITERATIONS) {\n throw new RippleInfiniteLoopError(`infinite reactive flush (>${MAX_FLUSH_ITERATIONS} iterations)`);\n }\n\n const effects = [...this.pending];\n const listeners = [...this.listeners];\n\n this.pending.clear();\n this.listeners.clear();\n\n for (const effect of effects) effect.run();\n\n for (const sink of listeners) {\n try {\n sink.listener();\n } catch (error) {\n this.report(error, { kind: 'listener' });\n }\n }\n }\n } finally {\n this.flushing = false;\n }\n }\n}\n\nexport const isReactive = <T>(value: T | Readable<T>): value is Readable<T> => {\n if (typeof value !== 'object' || value === null || (value as { [REACTIVE]?: unknown })[REACTIVE] !== true)\n return false;\n\n const candidate = value as { peek?: unknown; subscribe?: unknown; value?: unknown };\n\n return 'value' in candidate && typeof candidate.peek === 'function' && typeof candidate.subscribe === 'function';\n};\n"],"mappings":"kJAsBA,IAAa,EAAW,OAAO,IAAI,2BAA2B,EACxD,EAAuB,IACvB,EAAQ,OAAO,cAAc,EA0BpB,aAAf,KAA+B,CAC7B,CAAU,GAAY,GACtB,WAAsB,IAAI,IAC1B,KACA,QAEA,YAAsB,EAA0B,EAAe,CAC7D,KAAK,QAAU,EACf,KAAK,KAAO,CACd,CAKA,UAAU,EAAmC,CAC3C,KAAK,QAAQ,aAAa,EAC1B,KAAK,KAAK,EAIV,IAAM,EAAqB,CACzB,WACA,wBAA2B,KAAK,QAAQ,gBAAgB,CAAI,CAC9D,EAIA,OAFA,KAAK,WAAW,IAAI,CAAI,MAEX,KAAK,WAAW,OAAO,CAAI,CAC1C,CAEA,QAAyB,CACvB,IAAK,IAAM,IAAa,CAAC,GAAG,KAAK,UAAU,EAAG,EAAU,oBAAoB,CAC9E,CACF,EAEM,WAAN,cAA4B,YAAqC,CAC/D,QACA,OAEA,YAAY,EAA0B,EAAY,EAA4B,CAC5E,MAAM,EAAS,GAAS,IAAI,EAC5B,KAAK,QAAU,EACf,KAAK,OAAS,GAAS,QAAU,OAAO,EAC1C,CAEA,IAAI,OAAW,CAGb,OAFA,KAAK,QAAQ,MAAM,IAAI,EAEhB,KAAK,OACd,CAEA,IAAI,MAAM,EAAS,CAGjB,GAFA,KAAK,QAAQ,aAAa,EAEtB,KAAK,OAAO,KAAK,QAAS,CAAI,EAAG,OAErC,IAAM,EAAW,KAAK,QAEtB,KAAK,QAAU,EACf,KAAK,QAAQ,KAAK,CAAE,KAAM,KAAK,KAAM,OAAM,WAAU,KAAM,OAAQ,CAAC,EACpE,KAAK,QAAQ,cAAgB,KAAK,OAAO,CAAC,CAC5C,CAEA,MAAU,CACR,OAAO,KAAK,OACd,CAEA,OAAO,EAA+B,CACpC,KAAK,MAAQ,EAAQ,KA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eAAiB,CACxB,CACF,CAEA,mBAA2B,EAAwB,EAA6B,CAC9E,IAAK,IAAM,KAAc,EAAS,aAC3B,EAAK,IAAI,CAAU,GAAG,EAAW,WAAW,OAAO,CAAQ,EAGlE,IAAK,IAAM,KAAc,EAClB,EAAS,aAAa,IAAI,CAAU,GAAG,EAAW,WAAW,IAAI,CAAQ,EAGhF,EAAS,aAAa,MAAM,EAC5B,IAAK,IAAM,KAAc,EAAM,EAAS,aAAa,IAAI,CAAU,CACrE,CAEA,OAAsB,CACpB,GAAI,KAAK,SAAU,OAEnB,KAAK,SAAW,GAEhB,IAAI,EAAa,EAEjB,GAAI,CACF,KAAO,KAAK,QAAQ,KAAO,GAAK,KAAK,UAAU,KAAO,GAAG,CACvD,GAAI,EAAE,EAAa,EACjB,MAAM,IAAI,EAAwB,6BAA6B,EAAqB,aAAa,EAGnG,IAAM,EAAU,CAAC,GAAG,KAAK,OAAO,EAC1B,EAAY,CAAC,GAAG,KAAK,SAAS,EAEpC,KAAK,QAAQ,MAAM,EACnB,KAAK,UAAU,MAAM,EAErB,IAAK,IAAM,KAAU,EAAS,EAAO,IAAI,EAEzC,IAAK,IAAM,KAAQ,EACjB,GAAI,CACF,EAAK,SAAS,CAChB,OAAS,EAAO,CACd,KAAK,OAAO,EAAO,CAAE,KAAM,UAAW,CAAC,CACzC,CAEJ,CACF,QAAU,CACR,KAAK,SAAW,EAClB,CACF,CACF,EAEa,WAAiB,GAAiD,CAC7E,GAAI,OAAO,GAAU,WAAY,GAAmB,EAAmC,KAAc,GACnG,MAAO,GAET,IAAM,EAAY,EAElB,MAAO,UAAW,GAAa,OAAO,EAAU,MAAS,YAAc,OAAO,EAAU,WAAc,UACxG"}
|
package/dist/types.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export type ComputedOptions<T> = {
|
|
|
11
11
|
};
|
|
12
12
|
export type EffectOptions = {
|
|
13
13
|
name?: string;
|
|
14
|
-
scheduler?: 'microtask' | 'sync';
|
|
15
14
|
};
|
|
16
15
|
export interface Readable<T> {
|
|
17
16
|
readonly name?: string;
|
|
@@ -33,29 +32,50 @@ export type EffectHandle = Disposable;
|
|
|
33
32
|
export interface Scope extends Disposable {
|
|
34
33
|
run<T>(fn: () => T): T;
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Structural contract for external state sources that expose a snapshot and a
|
|
37
|
+
* subscription pair — the same shape React's `useSyncExternalStore` consumes.
|
|
38
|
+
* Packages can implement this without importing Ripple; `fromSubscribable()`
|
|
39
|
+
* bridges them into a reactive graph.
|
|
40
|
+
*/
|
|
41
|
+
export interface Subscribable<T> {
|
|
42
|
+
getSnapshot(): T;
|
|
43
|
+
subscribe(listener: () => void): Unsubscribe;
|
|
44
|
+
}
|
|
45
|
+
export type RippleErrorContext = {
|
|
46
|
+
readonly kind: 'cleanup' | 'computed' | 'effect' | 'listener';
|
|
47
|
+
readonly name?: string;
|
|
48
|
+
};
|
|
49
|
+
export type RippleEvent = {
|
|
50
|
+
readonly type: 'compute';
|
|
38
51
|
readonly name?: string;
|
|
39
52
|
} | {
|
|
40
|
-
readonly
|
|
53
|
+
readonly type: 'effect';
|
|
41
54
|
readonly name?: string;
|
|
42
55
|
} | {
|
|
43
|
-
readonly
|
|
56
|
+
readonly type: 'write';
|
|
44
57
|
readonly name?: string;
|
|
45
58
|
readonly next: unknown;
|
|
46
59
|
readonly previous: unknown;
|
|
47
60
|
} | {
|
|
48
|
-
readonly
|
|
49
|
-
readonly name?: string;
|
|
50
|
-
readonly node: 'effect' | 'scope';
|
|
51
|
-
};
|
|
52
|
-
export type ReactiveObserver = (event: ReactiveEvent) => void;
|
|
53
|
-
export type ReactiveErrorContext = {
|
|
54
|
-
readonly kind: 'cleanup' | 'effect' | 'listener' | 'observer';
|
|
61
|
+
readonly type: 'dispose';
|
|
55
62
|
readonly name?: string;
|
|
63
|
+
readonly node: 'effect' | 'graph' | 'scope';
|
|
64
|
+
} | {
|
|
65
|
+
readonly type: 'error';
|
|
66
|
+
readonly error: unknown;
|
|
67
|
+
readonly context: RippleErrorContext;
|
|
56
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Deterministic error policy for runtime callback, cleanup, and listener
|
|
71
|
+
* failures. Error events are always emitted through `tap()` regardless of
|
|
72
|
+
* policy — this controls only whether failures also rethrow.
|
|
73
|
+
*
|
|
74
|
+
* - `'throw'` (default): rethrows the error asynchronously via `queueMicrotask`.
|
|
75
|
+
* - `'swallow'`: silences rethrow; observe failures only through `tap()`.
|
|
76
|
+
*/
|
|
77
|
+
export type RippleErrorPolicy = 'throw' | 'swallow';
|
|
57
78
|
export type RippleOptions = {
|
|
58
|
-
|
|
59
|
-
onError?: (error: unknown, context: ReactiveErrorContext) => void;
|
|
79
|
+
errorPolicy?: RippleErrorPolicy;
|
|
60
80
|
};
|
|
61
81
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;AACjC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;AAC5D,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC/B,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,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QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE9F;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,CAAC;AAEpD,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/ripple",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "26.10.0",
|
|
4
|
+
"description": "Reactive runtime primitives: signals, derived values, effects, scopes, watchers, and async resources",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/helmuthdu/vielzeug",
|
|
@@ -30,19 +30,20 @@
|
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "vite build && pnpm run build:bundle && pnpm run build:types",
|
|
33
|
+
"build": "vite build && pnpm --silent run build:bundle && pnpm --silent run build:types && pnpm --silent run verify:exports",
|
|
34
34
|
"build:bundle": "vite build --config vite.bundle.config.ts",
|
|
35
35
|
"build:types": "tsc -p tsconfig.declarations.json",
|
|
36
36
|
"fix": "biome check --write src",
|
|
37
37
|
"lint": "biome ci src",
|
|
38
|
-
"prepublishOnly": "pnpm run build",
|
|
38
|
+
"prepublishOnly": "pnpm --silent run build",
|
|
39
39
|
"preview": "vite preview",
|
|
40
|
-
"test": "vitest"
|
|
40
|
+
"test": "vitest",
|
|
41
|
+
"verify:exports": "node verify-exports.mjs"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@types/node": "^26.2
|
|
44
|
+
"@types/node": "^26.6.2",
|
|
44
45
|
"typescript": "^6.0.3",
|
|
45
|
-
"vite": "^8.
|
|
46
|
-
"vitest": "^
|
|
46
|
+
"vite": "^8.3.0",
|
|
47
|
+
"vitest": "^5.0.1"
|
|
47
48
|
}
|
|
48
49
|
}
|