@pravosleva/reactive-engine 2.7.1 → 3.0.0-alpha.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/dist/core/core.d.ts +89 -203
- package/dist/core/core.d.ts.map +1 -1
- package/dist/core/core.global.d.ts +64 -8
- package/dist/core/core.global.d.ts.map +1 -1
- package/dist/core/core.logger.d.ts +2 -0
- package/dist/core/core.logger.d.ts.map +1 -1
- package/dist/core/core.method.reactive.d.ts +2 -4
- package/dist/core/core.method.reactive.d.ts.map +1 -1
- package/dist/core/core.method.resource.d.ts +3 -11
- package/dist/core/core.method.resource.d.ts.map +1 -1
- package/dist/core/types.d.ts +1 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core.global.mjs +31 -4
- package/dist/core.global.mjs.map +1 -1
- package/dist/core.logger.mjs +49 -2
- package/dist/core.logger.mjs.map +1 -1
- package/dist/core.method.reactive.mjs +73 -30
- package/dist/core.method.reactive.mjs.map +1 -1
- package/dist/core.method.resource.mjs +122 -138
- package/dist/core.method.resource.mjs.map +1 -1
- package/dist/core.mjs +379 -150
- package/dist/core.mjs.map +1 -1
- package/dist/index.mjs +12 -12
- package/dist/index2.mjs +5 -5
- package/dist/react/hooks/useReactiveSubscription.mjs +13 -13
- package/dist/react/hooks/useReactiveSubscription.mjs.map +1 -1
- package/dist/react/hooks/useReactiveValue.d.ts +0 -4
- package/dist/react/hooks/useReactiveValue.d.ts.map +1 -1
- package/dist/react/hooks/useReactiveValue.mjs +24 -9
- package/dist/react/hooks/useReactiveValue.mjs.map +1 -1
- package/dist/reactive-engine.umd.js +2 -2
- package/dist/reactive-engine.umd.js.map +1 -1
- package/package.json +4 -2
- package/dist/core.method.computed.mjs +0 -167
- package/dist/core.method.computed.mjs.map +0 -1
- package/dist/core.method.effect.mjs +0 -120
- package/dist/core.method.effect.mjs.map +0 -1
- package/dist/core.method.signal.mjs +0 -106
- package/dist/core.method.signal.mjs.map +0 -1
- package/dist/core.method.untrack.mjs +0 -14
- package/dist/core.method.untrack.mjs.map +0 -1
- package/dist/utils/getExtractedValues.mjs +0 -24
- package/dist/utils/getExtractedValues.mjs.map +0 -1
package/dist/core.mjs
CHANGED
|
@@ -1,90 +1,261 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { createReactive as r } from "./core.method.reactive.mjs";
|
|
5
|
-
import { createEffect as i } from "./core.method.effect.mjs";
|
|
6
|
-
import { ReactiveDebounceLogger as a } from "./core.logger.mjs";
|
|
7
|
-
import { createResource as o } from "./core.method.resource.mjs";
|
|
1
|
+
import { ReactiveDebounceLogger as e, queueLog as t } from "./core.logger.mjs";
|
|
2
|
+
import { createReactive as n } from "./core.method.reactive.mjs";
|
|
3
|
+
import { createResource as r } from "./core.method.resource.mjs";
|
|
8
4
|
//#region src/core/core.ts
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
5
|
+
var i = class {
|
|
6
|
+
source = null;
|
|
7
|
+
target = null;
|
|
8
|
+
nextSubscriber = null;
|
|
9
|
+
prevSubscriber = null;
|
|
10
|
+
nextDependency = null;
|
|
11
|
+
prevDependency = null;
|
|
12
|
+
version = 0;
|
|
13
|
+
clear() {
|
|
14
|
+
this.source = null, this.target = null, this.nextSubscriber = null, this.prevSubscriber = null, this.nextDependency = null, this.prevDependency = null, this.version = 0;
|
|
15
|
+
}
|
|
16
|
+
}, a = class {
|
|
17
|
+
static pool = [];
|
|
18
|
+
static size = 0;
|
|
19
|
+
static maxPoolSize = 1e5;
|
|
20
|
+
static acquire(e, t) {
|
|
21
|
+
if (this.size > 0) {
|
|
22
|
+
this.size--;
|
|
23
|
+
let n = this.pool[this.size];
|
|
24
|
+
return this.pool[this.size] = null, n.source = e, n.target = t, n;
|
|
25
|
+
}
|
|
26
|
+
let n = new i();
|
|
27
|
+
return n.source = e, n.target = t, n;
|
|
28
|
+
}
|
|
29
|
+
static release(e) {
|
|
30
|
+
this.size < this.maxPoolSize && (e.clear(), this.pool[this.size] = e, this.size++);
|
|
31
|
+
}
|
|
32
|
+
}, o = class {
|
|
33
|
+
id;
|
|
34
|
+
type;
|
|
35
|
+
version = 0;
|
|
36
|
+
state = 0;
|
|
37
|
+
depth = 0;
|
|
38
|
+
subscribersHead = null;
|
|
39
|
+
subscribersTail = null;
|
|
40
|
+
dependenciesHead = null;
|
|
41
|
+
dependenciesTail = null;
|
|
42
|
+
_value;
|
|
43
|
+
_prevValue;
|
|
44
|
+
fn = null;
|
|
45
|
+
cleanups = /* @__PURE__ */ new Set();
|
|
46
|
+
isDisposed = !1;
|
|
47
|
+
ownedEffects = /* @__PURE__ */ new Set();
|
|
48
|
+
wrapper = null;
|
|
49
|
+
engine = null;
|
|
50
|
+
constructor(e, t, n) {
|
|
51
|
+
this.type = e, this.id = t, this._value = n, this._prevValue = n;
|
|
52
|
+
}
|
|
53
|
+
get subscribers() {
|
|
54
|
+
let e = /* @__PURE__ */ new Set(), t = this.subscribersHead;
|
|
55
|
+
for (; t !== null;) t.target && e.add(t.target), t = t.nextSubscriber;
|
|
56
|
+
return e;
|
|
57
|
+
}
|
|
58
|
+
get dependencies() {
|
|
59
|
+
let e = /* @__PURE__ */ new Set(), t = this.dependenciesHead;
|
|
60
|
+
for (; t !== null;) t.source && e.add(t.source), t = t.nextDependency;
|
|
61
|
+
return e;
|
|
62
|
+
}
|
|
63
|
+
}, s = class {
|
|
64
|
+
buckets = [];
|
|
65
|
+
maxDepth = -1;
|
|
66
|
+
schedule(e) {
|
|
67
|
+
let t = e.depth;
|
|
68
|
+
this.buckets[t] || (this.buckets[t] = []), this.buckets[t].includes(e) || (this.buckets[t].push(e), t > this.maxDepth && (this.maxDepth = t));
|
|
69
|
+
}
|
|
70
|
+
clearAll() {
|
|
71
|
+
for (let e = 0; e <= this.maxDepth; e++) {
|
|
72
|
+
let t = this.buckets[e];
|
|
73
|
+
if (t) {
|
|
74
|
+
for (let e of t) e.state = 0;
|
|
75
|
+
this.buckets[e] = [];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
this.maxDepth = -1;
|
|
79
|
+
}
|
|
80
|
+
flush(e) {
|
|
81
|
+
let t = e.activeConsumer;
|
|
82
|
+
try {
|
|
83
|
+
let t = 0;
|
|
84
|
+
for (; t <= this.maxDepth;) {
|
|
85
|
+
let n = this.buckets[t];
|
|
86
|
+
if (!n || n.length === 0) {
|
|
87
|
+
t++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
this.buckets[t] = [], n.sort((e, t) => t.depth - e.depth);
|
|
91
|
+
for (let t of n) if (!(t.isDisposed || t.state === 0) && (t.state === 1 && (e.checkNeedsUpdate(t) ? t.state = 2 : t.state = 0), t.state === 2)) try {
|
|
92
|
+
e.runEffectNode(t);
|
|
93
|
+
} catch (e) {
|
|
94
|
+
throw this.clearAll(), e;
|
|
95
|
+
}
|
|
96
|
+
let r = !1;
|
|
97
|
+
for (let e = 0; e <= this.maxDepth; e++) if (this.buckets[e] && this.buckets[e].length > 0) {
|
|
98
|
+
t = e, r = !0;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
r || t++;
|
|
102
|
+
}
|
|
103
|
+
} finally {
|
|
104
|
+
e.activeConsumer = t, this.maxDepth = -1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, c = class {
|
|
60
108
|
activeConsumer = null;
|
|
61
109
|
batchDepth = 0;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
maxPendingDepth = 0;
|
|
110
|
+
batchedSignals = [];
|
|
111
|
+
batchInitialValues = /* @__PURE__ */ new Map();
|
|
65
112
|
computedCache = /* @__PURE__ */ new WeakMap();
|
|
66
|
-
|
|
67
|
-
diCache = /* @__PURE__ */ new Map();
|
|
113
|
+
logger;
|
|
68
114
|
proxyCache = /* @__PURE__ */ new WeakMap();
|
|
69
115
|
proxyTargets = /* @__PURE__ */ new WeakSet();
|
|
70
116
|
reactiveSignals = /* @__PURE__ */ new WeakMap();
|
|
117
|
+
scheduler = new s();
|
|
118
|
+
currentOwner = null;
|
|
119
|
+
effectIdCounter = 0;
|
|
120
|
+
diRegistry = /* @__PURE__ */ new Map();
|
|
121
|
+
diCache = /* @__PURE__ */ new Map();
|
|
71
122
|
cycleDetectionStack = /* @__PURE__ */ new Set();
|
|
72
|
-
batchedSignals = /* @__PURE__ */ new Set();
|
|
73
|
-
activeOwner = null;
|
|
74
|
-
activeCleanupNode = null;
|
|
75
|
-
pendingCleanups = /* @__PURE__ */ new Set();
|
|
76
|
-
queueCleanup(e) {
|
|
77
|
-
this.pendingCleanups.add(e);
|
|
78
|
-
}
|
|
79
123
|
constructor(e) {
|
|
80
124
|
this.logger = e?.logger || { isEnabled: !1 };
|
|
81
125
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
126
|
+
log(n) {
|
|
127
|
+
!this.logger || !this.logger.isEnabled || e.processLog(this.logger, t, n);
|
|
128
|
+
}
|
|
129
|
+
signal(e, t) {
|
|
130
|
+
let n = typeof t == "string" ? t : t?.name || "signal", r = typeof t == "object" ? t?.validate : void 0, i = typeof t == "object" ? t?.isInternalCoreSignal : !1, a = new o("signal", n, e);
|
|
131
|
+
a.engine = this;
|
|
132
|
+
let s = this;
|
|
133
|
+
this.log({
|
|
134
|
+
type: "signal",
|
|
135
|
+
label: n,
|
|
136
|
+
details: { to: e },
|
|
137
|
+
isInternalCoreSignal: i
|
|
138
|
+
});
|
|
139
|
+
let c = {
|
|
140
|
+
_node: a,
|
|
141
|
+
_engine: this,
|
|
142
|
+
get value() {
|
|
143
|
+
return s.activeConsumer && s.trackNode(a, s.activeConsumer), a._value;
|
|
144
|
+
},
|
|
145
|
+
set value(e) {
|
|
146
|
+
if (r) {
|
|
147
|
+
let t = r(e);
|
|
148
|
+
if (t === !1 || typeof t == "string") {
|
|
149
|
+
console.error(`[Validation Error] Invalid value supplied to signal "${n}": ${t}`);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
let t = typeof e == "object" && !!e;
|
|
154
|
+
if (Object.is(a._value, e) && !t) return;
|
|
155
|
+
let o = a._value;
|
|
156
|
+
a._prevValue = o, s.batchDepth > 0 && !s.batchInitialValues.has(a) && s.batchInitialValues.set(a, {
|
|
157
|
+
value: o,
|
|
158
|
+
version: a.version
|
|
159
|
+
}), a._value = e, a.version++, s.log({
|
|
160
|
+
type: "signal",
|
|
161
|
+
label: n,
|
|
162
|
+
details: {
|
|
163
|
+
from: o,
|
|
164
|
+
to: e
|
|
165
|
+
},
|
|
166
|
+
isInternalCoreSignal: i
|
|
167
|
+
}), s.notifySubscribers(a, 2), s.batchDepth > 0 ? s.batchedSignals.includes(a) || s.batchedSignals.push(a) : s.flushEffects();
|
|
168
|
+
},
|
|
169
|
+
get valueWithoutTracking() {
|
|
170
|
+
return a._value;
|
|
171
|
+
},
|
|
172
|
+
subscribe(e) {
|
|
173
|
+
return s.effect(() => {
|
|
174
|
+
e(c.value);
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
destroy() {
|
|
178
|
+
s.disposeNode(a);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return a.wrapper = c, c;
|
|
182
|
+
}
|
|
183
|
+
notifySubscribers(e, t) {
|
|
184
|
+
let n = e.subscribersHead;
|
|
185
|
+
for (; n !== null;) {
|
|
186
|
+
let e = n.target;
|
|
187
|
+
if (e === this.activeConsumer) {
|
|
188
|
+
n = n.nextSubscriber;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
e.state < t && (e.state = t, e.type === "effect" ? this.scheduler.schedule(e) : this.notifySubscribers(e, 1)), n = n.nextSubscriber;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
computed(e, t) {
|
|
195
|
+
let n = new o("computed", t || "computed");
|
|
196
|
+
n.engine = this, n.fn = e, n.state = 2;
|
|
197
|
+
let r = this, i = {
|
|
198
|
+
_node: n,
|
|
199
|
+
_engine: this,
|
|
200
|
+
get value() {
|
|
201
|
+
return n.state === 1 && (r.checkNeedsUpdate(n) ? n.state = 2 : n.state = 0), n.state === 2 && (n._value, r.evaluateComputed(n)), r.activeConsumer && r.trackNode(n, r.activeConsumer), n._value;
|
|
202
|
+
},
|
|
203
|
+
get valueWithoutTracking() {
|
|
204
|
+
return n._value;
|
|
205
|
+
},
|
|
206
|
+
subscribe(e) {
|
|
207
|
+
return r.effect(() => {
|
|
208
|
+
e(i.value);
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
destroy() {
|
|
212
|
+
r.disposeNode(n);
|
|
213
|
+
},
|
|
214
|
+
_isDirty() {
|
|
215
|
+
return n.state === 2;
|
|
216
|
+
},
|
|
217
|
+
get dependencies() {
|
|
218
|
+
let e = /* @__PURE__ */ new Set(), t = n.dependenciesHead;
|
|
219
|
+
for (; t !== null;) t.source && t.source.wrapper && e.add(t.source.wrapper), t = t.nextDependency;
|
|
220
|
+
return e;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
return n.wrapper = i, this.batchDepth === 0 && this.computedCache.set(e, i), i;
|
|
224
|
+
}
|
|
225
|
+
effect(e, t) {
|
|
226
|
+
let n = t || "effect", r = new o("effect", n);
|
|
227
|
+
r.state = 2, r.depth = this.currentOwner ? this.currentOwner.depth + 1 : 0, r.wrapper = {
|
|
228
|
+
id: ++this.effectIdCounter,
|
|
229
|
+
run: () => {
|
|
230
|
+
this.runEffectNode(r);
|
|
231
|
+
},
|
|
232
|
+
markDirty: () => {
|
|
233
|
+
r.state = 2, this.scheduler.schedule(r);
|
|
234
|
+
},
|
|
235
|
+
cleanups: r.cleanups,
|
|
236
|
+
label: n,
|
|
237
|
+
get isDirty() {
|
|
238
|
+
return r.state === 2;
|
|
239
|
+
},
|
|
240
|
+
get isDisposed() {
|
|
241
|
+
return r.isDisposed;
|
|
242
|
+
},
|
|
243
|
+
_node: r
|
|
244
|
+
}, r.fn = () => {
|
|
245
|
+
this.log({
|
|
246
|
+
type: "effect",
|
|
247
|
+
label: n
|
|
248
|
+
});
|
|
249
|
+
let t = e();
|
|
250
|
+
typeof t == "function" && r.cleanups.add(t);
|
|
251
|
+
}, this.currentOwner && this.currentOwner.ownedEffects.add(r), this.runEffectNode(r);
|
|
252
|
+
let i = () => {
|
|
253
|
+
this.disposeNode(r);
|
|
254
|
+
};
|
|
255
|
+
return i._node = r, i;
|
|
85
256
|
}
|
|
86
|
-
|
|
87
|
-
|
|
257
|
+
resource(e, t, n) {
|
|
258
|
+
return r(this, e, t, n);
|
|
88
259
|
}
|
|
89
260
|
batch(e) {
|
|
90
261
|
this.batchDepth++;
|
|
@@ -92,79 +263,148 @@ var f = class {
|
|
|
92
263
|
return e();
|
|
93
264
|
} finally {
|
|
94
265
|
if (this.batchDepth--, this.batchDepth === 0) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
266
|
+
for (let e of this.batchedSignals) {
|
|
267
|
+
let t = this.batchInitialValues.get(e), n = e._value !== null && typeof e._value == "object";
|
|
268
|
+
t && !n && Object.is(e._value, t.value) && (e.version = t.version, this.resetCleanState(e));
|
|
98
269
|
}
|
|
99
|
-
this.flushEffects();
|
|
270
|
+
this.batchedSignals = [], this.batchInitialValues.clear(), this.flushEffects();
|
|
100
271
|
}
|
|
101
272
|
}
|
|
102
273
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
274
|
+
resetCleanState(e) {
|
|
275
|
+
let t = e.subscribersHead;
|
|
276
|
+
for (; t !== null;) {
|
|
277
|
+
let e = t.target;
|
|
278
|
+
e.state > 0 && !this.checkNeedsUpdate(e) && (e.state = 0, this.resetCleanState(e)), t = t.nextSubscriber;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
untrack(e) {
|
|
282
|
+
let t = this.activeConsumer;
|
|
283
|
+
this.activeConsumer = null;
|
|
106
284
|
try {
|
|
107
|
-
|
|
108
|
-
let t = this.pendingEffects[e];
|
|
109
|
-
if (!t || t.size === 0) continue;
|
|
110
|
-
let n = Array.from(t);
|
|
111
|
-
t.clear();
|
|
112
|
-
for (let t of n) if (!t.isDisposed && t.isDirty) {
|
|
113
|
-
if (t.dependencies && t.dependencies.size > 0) {
|
|
114
|
-
let e = !1;
|
|
115
|
-
for (let n of t.dependencies) {
|
|
116
|
-
let r = n._node || n;
|
|
117
|
-
r.type === "computed" && r.state > 0 && r.update && r.update(), t.depVersions && t.depVersions.get(n) !== r.version && (e = !0);
|
|
118
|
-
}
|
|
119
|
-
if (!e && t.dependencies.size > 0) {
|
|
120
|
-
t.isDirty = !1;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
try {
|
|
125
|
-
t.run();
|
|
126
|
-
} catch (t) {
|
|
127
|
-
for (let t = e; t <= this.maxPendingDepth; t++) {
|
|
128
|
-
let e = this.pendingEffects[t];
|
|
129
|
-
if (e) {
|
|
130
|
-
for (let t of e) t.isDirty = !1;
|
|
131
|
-
e.clear();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
throw this.maxPendingDepth = 0, t;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (e > 0) {
|
|
138
|
-
let t = !1;
|
|
139
|
-
for (let n = 0; n < e; n++) if (this.pendingEffects[n] && this.pendingEffects[n].size > 0) {
|
|
140
|
-
t = !0;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
t && (e = -1);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
this.maxPendingDepth = 0;
|
|
285
|
+
return e();
|
|
147
286
|
} finally {
|
|
148
|
-
this.activeConsumer =
|
|
287
|
+
this.activeConsumer = t;
|
|
149
288
|
}
|
|
150
289
|
}
|
|
151
|
-
|
|
152
|
-
|
|
290
|
+
flushEffects() {
|
|
291
|
+
this.batchDepth === 0 && this.scheduler.flush(this);
|
|
153
292
|
}
|
|
154
|
-
|
|
155
|
-
|
|
293
|
+
trackNode(e, t) {
|
|
294
|
+
let n = t.dependenciesHead;
|
|
295
|
+
for (; n !== null;) {
|
|
296
|
+
if (n.source === e) {
|
|
297
|
+
n.version = e.version;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
n = n.nextDependency;
|
|
301
|
+
}
|
|
302
|
+
let r = a.acquire(e, t);
|
|
303
|
+
r.version = e.version, t.depth <= e.depth && (t.depth = e.depth + 1), e.subscribersTail === null ? (e.subscribersHead = r, e.subscribersTail = r) : (e.subscribersTail.nextSubscriber = r, r.prevSubscriber = e.subscribersTail, e.subscribersTail = r), t.dependenciesTail === null ? (t.dependenciesHead = r, t.dependenciesTail = r) : (t.dependenciesTail.nextDependency = r, r.prevDependency = t.dependenciesTail, t.dependenciesTail = r);
|
|
156
304
|
}
|
|
157
|
-
|
|
158
|
-
|
|
305
|
+
unlinkDependencies(e, t = !1) {
|
|
306
|
+
let n = e.dependenciesHead;
|
|
307
|
+
for (e.dependenciesHead = null, e.dependenciesTail = null; n !== null;) {
|
|
308
|
+
let r = n.nextDependency, i = n.source;
|
|
309
|
+
n.prevSubscriber === null ? i.subscribersHead = n.nextSubscriber : n.prevSubscriber.nextSubscriber = n.nextSubscriber, n.nextSubscriber === null ? i.subscribersTail = n.prevSubscriber : n.nextSubscriber.prevSubscriber = n.prevSubscriber, a.release(n), t && e.isDisposed && e.type === "computed" && i.type === "computed" && i.subscribersHead === null && this.disposeNode(i), n = r;
|
|
310
|
+
}
|
|
159
311
|
}
|
|
160
|
-
|
|
161
|
-
|
|
312
|
+
checkNeedsUpdate(e) {
|
|
313
|
+
let t = e.dependenciesHead;
|
|
314
|
+
for (; t !== null;) {
|
|
315
|
+
let e = t.source;
|
|
316
|
+
if (e.state === 1 && (this.checkNeedsUpdate(e) ? e.state = 2 : e.state = 0), e.state === 2 && this.evaluateComputed(e), t.version !== e.version) return t.version = e.version, !0;
|
|
317
|
+
t = t.nextDependency;
|
|
318
|
+
}
|
|
319
|
+
return !1;
|
|
162
320
|
}
|
|
163
|
-
|
|
164
|
-
|
|
321
|
+
evaluateComputed(e) {
|
|
322
|
+
if (e.ownedEffects.size > 0) {
|
|
323
|
+
let t = Array.from(e.ownedEffects);
|
|
324
|
+
e.ownedEffects.clear();
|
|
325
|
+
for (let e of t) this.disposeNode(e);
|
|
326
|
+
}
|
|
327
|
+
this.unlinkDependencies(e, !1);
|
|
328
|
+
let t = this.activeConsumer, n = this.currentOwner;
|
|
329
|
+
this.activeConsumer = e, this.currentOwner = e;
|
|
330
|
+
let r = e._value;
|
|
331
|
+
try {
|
|
332
|
+
let t = e.fn();
|
|
333
|
+
Object.is(e._value, t) || (e._value = t, e.version++), e.state = 0, this.log({
|
|
334
|
+
type: "computed",
|
|
335
|
+
label: e.id,
|
|
336
|
+
details: {
|
|
337
|
+
from: r,
|
|
338
|
+
to: e._value
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
} finally {
|
|
342
|
+
this.activeConsumer = t, this.currentOwner = n;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
executeCleanups(e) {
|
|
346
|
+
if (e.cleanups.size === 0) return;
|
|
347
|
+
let t = Array.from(e.cleanups);
|
|
348
|
+
e.cleanups.clear();
|
|
349
|
+
let n = null;
|
|
350
|
+
for (let e of t) try {
|
|
351
|
+
this.untrack(() => e());
|
|
352
|
+
} catch (e) {
|
|
353
|
+
n === null && (n = e);
|
|
354
|
+
}
|
|
355
|
+
if (n !== null) throw n;
|
|
356
|
+
}
|
|
357
|
+
runEffectNode(e) {
|
|
358
|
+
if (e.isDisposed) return;
|
|
359
|
+
if (e.ownedEffects.size > 0) {
|
|
360
|
+
let t = Array.from(e.ownedEffects);
|
|
361
|
+
e.ownedEffects.clear();
|
|
362
|
+
for (let e of t) this.disposeNode(e);
|
|
363
|
+
}
|
|
364
|
+
try {
|
|
365
|
+
this.executeCleanups(e);
|
|
366
|
+
} catch (t) {
|
|
367
|
+
throw e.state = 0, t;
|
|
368
|
+
}
|
|
369
|
+
this.unlinkDependencies(e, !1);
|
|
370
|
+
let t = this.activeConsumer, n = this.currentOwner;
|
|
371
|
+
this.activeConsumer = e, this.currentOwner = e;
|
|
372
|
+
try {
|
|
373
|
+
e.fn(), e.state = 0;
|
|
374
|
+
} finally {
|
|
375
|
+
this.activeConsumer = t, this.currentOwner = n, e.isDisposed && this.unlinkDependencies(e, !0);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
disposeNode(e) {
|
|
379
|
+
if (e.isDisposed) return;
|
|
380
|
+
if (e.isDisposed = !0, e.state = 0, e.ownedEffects.size > 0) {
|
|
381
|
+
let t = Array.from(e.ownedEffects);
|
|
382
|
+
e.ownedEffects.clear();
|
|
383
|
+
for (let e of t) this.disposeNode(e);
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
this.executeCleanups(e);
|
|
387
|
+
} catch {}
|
|
388
|
+
this.unlinkDependencies(e, !0);
|
|
389
|
+
let t = e.subscribersHead;
|
|
390
|
+
for (e.subscribersHead = null, e.subscribersTail = null; t !== null;) {
|
|
391
|
+
let e = t.nextSubscriber, n = t.target;
|
|
392
|
+
n && (t.prevDependency === null ? n.dependenciesHead = t.nextDependency : t.prevDependency.nextDependency = t.nextDependency, t.nextDependency === null ? n.dependenciesTail = t.prevDependency : t.nextDependency.prevDependency = t.prevDependency), a.release(t), t = e;
|
|
393
|
+
}
|
|
165
394
|
}
|
|
166
395
|
reactive(e, t) {
|
|
167
|
-
return
|
|
396
|
+
return n(this, e, t);
|
|
397
|
+
}
|
|
398
|
+
delay(e, t) {
|
|
399
|
+
return new Promise((n, r) => {
|
|
400
|
+
if (t.aborted) return r(new DOMException("Aborted", "AbortError"));
|
|
401
|
+
let i = setTimeout(() => {
|
|
402
|
+
t.removeEventListener("abort", a), n();
|
|
403
|
+
}, e), a = () => {
|
|
404
|
+
clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
|
|
405
|
+
};
|
|
406
|
+
t.addEventListener("abort", a, { once: !0 });
|
|
407
|
+
});
|
|
168
408
|
}
|
|
169
409
|
provide(e, t) {
|
|
170
410
|
this.diRegistry.set(e, t), this.diCache.delete(e);
|
|
@@ -200,22 +440,11 @@ var f = class {
|
|
|
200
440
|
this.cycleDetectionStack.delete(e);
|
|
201
441
|
}
|
|
202
442
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
t.removeEventListener("abort", a), n();
|
|
208
|
-
}, e), a = () => {
|
|
209
|
-
clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
|
|
210
|
-
};
|
|
211
|
-
t.addEventListener("abort", a, { once: !0 });
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
resource(e, t, n) {
|
|
215
|
-
return o(this, e, t, n);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
443
|
+
}, l = new c();
|
|
444
|
+
function u() {
|
|
445
|
+
l = new c();
|
|
446
|
+
}
|
|
218
447
|
//#endregion
|
|
219
|
-
export {
|
|
448
|
+
export { s as EffectScheduler, a as LinkPool, i as NodeLink, c as ReactiveEngine, c as ReactiveEngineAutomatic, c as ReactiveEngineCore, o as ReactiveNode, l as currentEngineInstance, u as resetGlobalReactiveEngine };
|
|
220
449
|
|
|
221
450
|
//# sourceMappingURL=core.mjs.map
|