@cajoa/core 0.15.0 → 0.17.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/index.cjs +245 -85
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +244 -85
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
createMemo: () => createMemo,
|
|
37
37
|
createResource: () => createResource,
|
|
38
38
|
createRoot: () => createRoot,
|
|
39
|
+
createSelector: () => createSelector,
|
|
39
40
|
createSignal: () => createSignal,
|
|
40
41
|
createStore: () => createStore,
|
|
41
42
|
getRenderer: () => getRenderer,
|
|
@@ -79,16 +80,19 @@ function logError(message, error) {
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
// src/reactivity/signal.ts
|
|
83
|
+
var CLEAN = 0;
|
|
84
|
+
var CHECK = 1;
|
|
85
|
+
var DIRTY = 2;
|
|
82
86
|
var currentOwner = null;
|
|
83
|
-
var
|
|
87
|
+
var listener = null;
|
|
84
88
|
function clean(owner) {
|
|
85
89
|
const fns = owner.cleanups;
|
|
86
90
|
owner.cleanups = [];
|
|
87
91
|
for (const fn of fns) fn();
|
|
88
92
|
}
|
|
89
93
|
function cleanComputation(c) {
|
|
90
|
-
for (const
|
|
91
|
-
c.
|
|
94
|
+
for (const source of c.sources) source.observers.delete(c);
|
|
95
|
+
c.sources.clear();
|
|
92
96
|
clean(c);
|
|
93
97
|
}
|
|
94
98
|
function addCleanup(fn) {
|
|
@@ -104,11 +108,104 @@ function handleError(error, owner) {
|
|
|
104
108
|
throw error;
|
|
105
109
|
}
|
|
106
110
|
var batchDepth = 0;
|
|
107
|
-
var
|
|
111
|
+
var flushing = false;
|
|
112
|
+
var queued = /* @__PURE__ */ new Set();
|
|
113
|
+
var isComputation = (source) => "fn" in source;
|
|
114
|
+
function track(source) {
|
|
115
|
+
if (listener) {
|
|
116
|
+
source.observers.add(listener);
|
|
117
|
+
listener.sources.add(source);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function mark(node, state) {
|
|
121
|
+
if (node.disposed || node.state >= state) return;
|
|
122
|
+
const wasClean = node.state === CLEAN;
|
|
123
|
+
node.state = state;
|
|
124
|
+
if (!wasClean) return;
|
|
125
|
+
if (node.isEffect) {
|
|
126
|
+
queued.add(node);
|
|
127
|
+
} else {
|
|
128
|
+
for (const observer of node.observers) mark(observer, CHECK);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function notify(source) {
|
|
132
|
+
for (const observer of source.observers) mark(observer, DIRTY);
|
|
133
|
+
if (batchDepth === 0 && !flushing) flush();
|
|
134
|
+
}
|
|
135
|
+
function run(node) {
|
|
136
|
+
cleanComputation(node);
|
|
137
|
+
const prevOwner = currentOwner;
|
|
138
|
+
const prevListener = listener;
|
|
139
|
+
currentOwner = node;
|
|
140
|
+
listener = node;
|
|
141
|
+
node.state = CLEAN;
|
|
142
|
+
try {
|
|
143
|
+
const result = node.fn();
|
|
144
|
+
if (!node.isEffect) {
|
|
145
|
+
const changed = node.hasValue && !Object.is(node.value, result);
|
|
146
|
+
node.value = result;
|
|
147
|
+
node.hasValue = true;
|
|
148
|
+
if (changed) {
|
|
149
|
+
for (const observer of node.observers) {
|
|
150
|
+
if (observer.state === CHECK) observer.state = DIRTY;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
handleError(error, node);
|
|
156
|
+
} finally {
|
|
157
|
+
currentOwner = prevOwner;
|
|
158
|
+
listener = prevListener;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function update(node) {
|
|
162
|
+
if (node.disposed) {
|
|
163
|
+
node.state = CLEAN;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (node.state === CHECK) {
|
|
167
|
+
for (const source of [...node.sources]) {
|
|
168
|
+
if (isComputation(source)) {
|
|
169
|
+
update(source);
|
|
170
|
+
if (node.state === DIRTY) break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (node.state === DIRTY) run(node);
|
|
175
|
+
else node.state = CLEAN;
|
|
176
|
+
}
|
|
108
177
|
function flush() {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
178
|
+
flushing = true;
|
|
179
|
+
let failure = null;
|
|
180
|
+
let steps = 0;
|
|
181
|
+
try {
|
|
182
|
+
while (queued.size > 0) {
|
|
183
|
+
if (++steps > 1e5) {
|
|
184
|
+
queued.clear();
|
|
185
|
+
failure ??= {
|
|
186
|
+
error: new Error(
|
|
187
|
+
"Cajoa: updates never settled. An effect probably keeps changing a signal that it also reads."
|
|
188
|
+
)
|
|
189
|
+
};
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
const effect = queued.values().next().value;
|
|
193
|
+
queued.delete(effect);
|
|
194
|
+
try {
|
|
195
|
+
update(effect);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
failure ??= { error };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
} finally {
|
|
201
|
+
flushing = false;
|
|
202
|
+
}
|
|
203
|
+
if (failure) throw failure.error;
|
|
204
|
+
}
|
|
205
|
+
function dispose(node) {
|
|
206
|
+
node.disposed = true;
|
|
207
|
+
queued.delete(node);
|
|
208
|
+
cleanComputation(node);
|
|
112
209
|
}
|
|
113
210
|
function batch(fn) {
|
|
114
211
|
batchDepth++;
|
|
@@ -116,58 +213,84 @@ function batch(fn) {
|
|
|
116
213
|
return fn();
|
|
117
214
|
} finally {
|
|
118
215
|
batchDepth--;
|
|
119
|
-
if (batchDepth === 0) flush();
|
|
216
|
+
if (batchDepth === 0 && !flushing) flush();
|
|
120
217
|
}
|
|
121
218
|
}
|
|
122
219
|
function createSignal(value) {
|
|
123
|
-
const
|
|
220
|
+
const source = { observers: /* @__PURE__ */ new Set() };
|
|
124
221
|
const get = () => {
|
|
125
|
-
|
|
126
|
-
subs.add(currentEffect);
|
|
127
|
-
currentEffect.deps.add(subs);
|
|
128
|
-
}
|
|
222
|
+
track(source);
|
|
129
223
|
return value;
|
|
130
224
|
};
|
|
131
225
|
const set = (next) => {
|
|
132
226
|
const v = typeof next === "function" ? next(value) : next;
|
|
133
227
|
if (Object.is(v, value)) return;
|
|
134
228
|
value = v;
|
|
135
|
-
|
|
136
|
-
if (batchDepth > 0)
|
|
137
|
-
pending.add(effect);
|
|
138
|
-
else effect.run();
|
|
139
|
-
}
|
|
229
|
+
notify(source);
|
|
140
230
|
};
|
|
141
231
|
return [get, set];
|
|
142
232
|
}
|
|
143
|
-
function
|
|
144
|
-
|
|
233
|
+
function createComputation(fn, isEffect) {
|
|
234
|
+
return {
|
|
235
|
+
fn,
|
|
236
|
+
isEffect,
|
|
145
237
|
cleanups: [],
|
|
146
238
|
parent: currentOwner,
|
|
147
|
-
|
|
239
|
+
sources: /* @__PURE__ */ new Set(),
|
|
240
|
+
observers: /* @__PURE__ */ new Set(),
|
|
241
|
+
state: DIRTY,
|
|
148
242
|
disposed: false,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
243
|
+
hasValue: false,
|
|
244
|
+
value: void 0
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function createEffect(fn) {
|
|
248
|
+
const node = createComputation(fn, true);
|
|
249
|
+
addCleanup(() => dispose(node));
|
|
250
|
+
run(node);
|
|
251
|
+
}
|
|
252
|
+
function createMemo(fn) {
|
|
253
|
+
const node = createComputation(fn, false);
|
|
254
|
+
addCleanup(() => dispose(node));
|
|
255
|
+
run(node);
|
|
256
|
+
return () => {
|
|
257
|
+
if (node.state !== CLEAN) update(node);
|
|
258
|
+
track(node);
|
|
259
|
+
return node.value;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function createSelector(source) {
|
|
263
|
+
const cells = /* @__PURE__ */ new Map();
|
|
264
|
+
let previous = untrack(source);
|
|
265
|
+
createEffect(() => {
|
|
266
|
+
const next = source();
|
|
267
|
+
if (Object.is(next, previous)) return;
|
|
268
|
+
const old = previous;
|
|
269
|
+
previous = next;
|
|
270
|
+
batch(() => {
|
|
271
|
+
for (const key of [old, next]) {
|
|
272
|
+
const cell = cells.get(key);
|
|
273
|
+
if (cell) notify(cell);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
return (key) => {
|
|
278
|
+
const current2 = untrack(source);
|
|
279
|
+
if (listener) {
|
|
280
|
+
let cell = cells.get(key);
|
|
281
|
+
if (!cell) {
|
|
282
|
+
cell = { observers: /* @__PURE__ */ new Set() };
|
|
283
|
+
cells.set(key, cell);
|
|
163
284
|
}
|
|
285
|
+
track(cell);
|
|
286
|
+
const mine = cell;
|
|
287
|
+
listener.cleanups.push(() => {
|
|
288
|
+
if (mine.observers.size === 0 && cells.get(key) === mine)
|
|
289
|
+
cells.delete(key);
|
|
290
|
+
});
|
|
164
291
|
}
|
|
292
|
+
return Object.is(current2, key);
|
|
165
293
|
};
|
|
166
|
-
addCleanup(() => {
|
|
167
|
-
effect.disposed = true;
|
|
168
|
-
cleanComputation(effect);
|
|
169
|
-
});
|
|
170
|
-
effect.run();
|
|
171
294
|
}
|
|
172
295
|
function onCleanup(fn) {
|
|
173
296
|
if (!currentOwner) {
|
|
@@ -180,40 +303,40 @@ function onCleanup(fn) {
|
|
|
180
303
|
function createRoot(fn) {
|
|
181
304
|
const root = { cleanups: [], parent: currentOwner };
|
|
182
305
|
const prevOwner = currentOwner;
|
|
183
|
-
const
|
|
306
|
+
const prevListener = listener;
|
|
184
307
|
currentOwner = root;
|
|
185
|
-
|
|
308
|
+
listener = null;
|
|
186
309
|
try {
|
|
187
310
|
return fn(() => clean(root));
|
|
188
311
|
} finally {
|
|
189
312
|
currentOwner = prevOwner;
|
|
190
|
-
|
|
313
|
+
listener = prevListener;
|
|
191
314
|
}
|
|
192
315
|
}
|
|
193
316
|
function onMount(fn) {
|
|
194
317
|
const owner = currentOwner;
|
|
195
318
|
Promise.resolve().then(() => {
|
|
196
319
|
const prevOwner = currentOwner;
|
|
197
|
-
const
|
|
320
|
+
const prevListener = listener;
|
|
198
321
|
currentOwner = owner;
|
|
199
|
-
|
|
322
|
+
listener = null;
|
|
200
323
|
try {
|
|
201
324
|
fn();
|
|
202
325
|
} catch (error) {
|
|
203
326
|
handleError(error, owner);
|
|
204
327
|
} finally {
|
|
205
328
|
currentOwner = prevOwner;
|
|
206
|
-
|
|
329
|
+
listener = prevListener;
|
|
207
330
|
}
|
|
208
331
|
});
|
|
209
332
|
}
|
|
210
333
|
function untrack(fn) {
|
|
211
|
-
const prev =
|
|
212
|
-
|
|
334
|
+
const prev = listener;
|
|
335
|
+
listener = null;
|
|
213
336
|
try {
|
|
214
337
|
return fn();
|
|
215
338
|
} finally {
|
|
216
|
-
|
|
339
|
+
listener = prev;
|
|
217
340
|
}
|
|
218
341
|
}
|
|
219
342
|
function catchError(fn, handler) {
|
|
@@ -271,13 +394,6 @@ function useContext(ctx) {
|
|
|
271
394
|
return ctx.defaultValue;
|
|
272
395
|
}
|
|
273
396
|
|
|
274
|
-
// src/reactivity/memo.ts
|
|
275
|
-
function createMemo(fn) {
|
|
276
|
-
const [value, setValue] = createSignal(void 0);
|
|
277
|
-
createEffect(() => setValue(() => fn()));
|
|
278
|
-
return value;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
397
|
// src/reactivity/suspense.ts
|
|
282
398
|
var SuspenseContext = createContext(null);
|
|
283
399
|
function trackPending() {
|
|
@@ -297,12 +413,12 @@ function createResource(a, b) {
|
|
|
297
413
|
const [failure, setFailure] = createSignal(null);
|
|
298
414
|
const [loading, setLoading] = createSignal(false);
|
|
299
415
|
const [version, setVersion] = createSignal(0);
|
|
300
|
-
let
|
|
301
|
-
const
|
|
416
|
+
let run2 = 0;
|
|
417
|
+
const track2 = trackPending();
|
|
302
418
|
let release;
|
|
303
419
|
let settled = false;
|
|
304
420
|
const finish = (id, outcome) => {
|
|
305
|
-
if (id !==
|
|
421
|
+
if (id !== run2) return;
|
|
306
422
|
settled = true;
|
|
307
423
|
batch(() => {
|
|
308
424
|
setLoading(false);
|
|
@@ -319,10 +435,10 @@ function createResource(a, b) {
|
|
|
319
435
|
createEffect(() => {
|
|
320
436
|
const s = source();
|
|
321
437
|
version();
|
|
322
|
-
|
|
323
|
-
const id =
|
|
438
|
+
run2++;
|
|
439
|
+
const id = run2;
|
|
324
440
|
onCleanup(() => {
|
|
325
|
-
|
|
441
|
+
run2++;
|
|
326
442
|
release?.();
|
|
327
443
|
release = void 0;
|
|
328
444
|
});
|
|
@@ -334,7 +450,7 @@ function createResource(a, b) {
|
|
|
334
450
|
});
|
|
335
451
|
return;
|
|
336
452
|
}
|
|
337
|
-
if (!settled &&
|
|
453
|
+
if (!settled && track2 && !release) release = track2();
|
|
338
454
|
setLoading(true);
|
|
339
455
|
setFailure(null);
|
|
340
456
|
let result;
|
|
@@ -619,6 +735,65 @@ function getRenderer() {
|
|
|
619
735
|
return current;
|
|
620
736
|
}
|
|
621
737
|
|
|
738
|
+
// src/runtime/reconcile.ts
|
|
739
|
+
function longestIncreasingSubsequence(values) {
|
|
740
|
+
const predecessor = new Array(values.length);
|
|
741
|
+
const tails = [];
|
|
742
|
+
for (let i = 0; i < values.length; i++) {
|
|
743
|
+
const v = values[i];
|
|
744
|
+
if (v < 0) continue;
|
|
745
|
+
let lo;
|
|
746
|
+
if (tails.length === 0 || values[tails[tails.length - 1]] < v) {
|
|
747
|
+
lo = tails.length;
|
|
748
|
+
} else {
|
|
749
|
+
lo = 0;
|
|
750
|
+
let hi = tails.length - 1;
|
|
751
|
+
while (lo < hi) {
|
|
752
|
+
const mid = lo + hi >> 1;
|
|
753
|
+
if (values[tails[mid]] < v) lo = mid + 1;
|
|
754
|
+
else hi = mid;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
predecessor[i] = lo > 0 ? tails[lo - 1] : -1;
|
|
758
|
+
tails[lo] = i;
|
|
759
|
+
}
|
|
760
|
+
const result = new Array(tails.length);
|
|
761
|
+
let k = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
762
|
+
for (let j = tails.length - 1; j >= 0; j--) {
|
|
763
|
+
result[j] = k;
|
|
764
|
+
k = predecessor[k];
|
|
765
|
+
}
|
|
766
|
+
return result;
|
|
767
|
+
}
|
|
768
|
+
function reconcile(start, end, next) {
|
|
769
|
+
const r = getRenderer();
|
|
770
|
+
const keep = new Set(next);
|
|
771
|
+
const oldIndex = /* @__PURE__ */ new Map();
|
|
772
|
+
let count = 0;
|
|
773
|
+
let cur = r.nextSibling(start);
|
|
774
|
+
while (cur && cur !== end) {
|
|
775
|
+
const after = r.nextSibling(cur);
|
|
776
|
+
if (keep.has(cur)) oldIndex.set(cur, count++);
|
|
777
|
+
else r.remove(cur);
|
|
778
|
+
cur = after;
|
|
779
|
+
}
|
|
780
|
+
const parent = r.parentNode(end);
|
|
781
|
+
const n = next.length;
|
|
782
|
+
const positions = new Array(n);
|
|
783
|
+
for (let i = 0; i < n; i++) positions[i] = oldIndex.get(next[i]) ?? -1;
|
|
784
|
+
const stable = new Uint8Array(n);
|
|
785
|
+
for (const i of longestIncreasingSubsequence(positions)) stable[i] = 1;
|
|
786
|
+
const anchors = new Array(n);
|
|
787
|
+
let anchor = end;
|
|
788
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
789
|
+
anchors[i] = anchor;
|
|
790
|
+
if (stable[i]) anchor = next[i];
|
|
791
|
+
}
|
|
792
|
+
for (let i = 0; i < n; i++) {
|
|
793
|
+
if (!stable[i]) r.insert(parent, next[i], anchors[i]);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
622
797
|
// src/runtime/h.ts
|
|
623
798
|
function h(tag, props, ...children) {
|
|
624
799
|
const r = getRenderer();
|
|
@@ -659,22 +834,6 @@ function toNodes(value) {
|
|
|
659
834
|
}
|
|
660
835
|
return out;
|
|
661
836
|
}
|
|
662
|
-
function reconcile(start, end, next) {
|
|
663
|
-
const r = getRenderer();
|
|
664
|
-
const keep = new Set(next);
|
|
665
|
-
let cur = r.nextSibling(start);
|
|
666
|
-
while (cur && cur !== end) {
|
|
667
|
-
const after = r.nextSibling(cur);
|
|
668
|
-
if (!keep.has(cur)) r.remove(cur);
|
|
669
|
-
cur = after;
|
|
670
|
-
}
|
|
671
|
-
const parent = r.parentNode(end);
|
|
672
|
-
let ref = r.nextSibling(start);
|
|
673
|
-
for (const node of next) {
|
|
674
|
-
if (node === ref) ref = r.nextSibling(ref);
|
|
675
|
-
else r.insert(parent, node, ref);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
837
|
function appendChildren(parent, children) {
|
|
679
838
|
const r = getRenderer();
|
|
680
839
|
for (const child of children.flat(Infinity)) {
|
|
@@ -692,7 +851,7 @@ function appendChildren(parent, children) {
|
|
|
692
851
|
|
|
693
852
|
// src/runtime/render.ts
|
|
694
853
|
function render(component, container) {
|
|
695
|
-
return createRoot((
|
|
854
|
+
return createRoot((dispose2) => {
|
|
696
855
|
const r = getRenderer();
|
|
697
856
|
const node = component();
|
|
698
857
|
if (typeof node === "function") {
|
|
@@ -703,7 +862,7 @@ function render(component, container) {
|
|
|
703
862
|
r.clear(container);
|
|
704
863
|
r.insert(container, node);
|
|
705
864
|
return () => {
|
|
706
|
-
|
|
865
|
+
dispose2();
|
|
707
866
|
r.clear(container);
|
|
708
867
|
};
|
|
709
868
|
});
|
|
@@ -744,9 +903,9 @@ function For(props) {
|
|
|
744
903
|
}
|
|
745
904
|
let entry = cache.get(k);
|
|
746
905
|
if (!entry) {
|
|
747
|
-
entry = createRoot((
|
|
906
|
+
entry = createRoot((dispose2) => ({
|
|
748
907
|
node: props.children(item, i),
|
|
749
|
-
dispose
|
|
908
|
+
dispose: dispose2
|
|
750
909
|
}));
|
|
751
910
|
}
|
|
752
911
|
next.set(k, entry);
|
|
@@ -909,7 +1068,7 @@ function resolve5(value) {
|
|
|
909
1068
|
return typeof value === "function" ? value() : value;
|
|
910
1069
|
}
|
|
911
1070
|
function Suspense(props) {
|
|
912
|
-
const [
|
|
1071
|
+
const [pending, setPending] = createSignal(0);
|
|
913
1072
|
const [ready, setReady] = createSignal(false);
|
|
914
1073
|
const state = {
|
|
915
1074
|
add() {
|
|
@@ -930,7 +1089,7 @@ function Suspense(props) {
|
|
|
930
1089
|
)
|
|
931
1090
|
);
|
|
932
1091
|
createEffect(() => {
|
|
933
|
-
if (
|
|
1092
|
+
if (pending() === 0) setReady(true);
|
|
934
1093
|
});
|
|
935
1094
|
return () => ready() ? content : untrack(() => resolve5(props.fallback ?? null));
|
|
936
1095
|
}
|
|
@@ -982,6 +1141,7 @@ function lazy(loader) {
|
|
|
982
1141
|
createMemo,
|
|
983
1142
|
createResource,
|
|
984
1143
|
createRoot,
|
|
1144
|
+
createSelector,
|
|
985
1145
|
createSignal,
|
|
986
1146
|
createStore,
|
|
987
1147
|
getRenderer,
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,8 @@ type Cleanup = () => void;
|
|
|
2
2
|
declare function batch<T>(fn: () => T): T;
|
|
3
3
|
declare function createSignal<T>(value: T): readonly [() => T, (next: T | ((prev: T) => T)) => void];
|
|
4
4
|
declare function createEffect(fn: () => void): void;
|
|
5
|
+
declare function createMemo<T>(fn: () => T): () => T;
|
|
6
|
+
declare function createSelector<T>(source: () => T): (key: T) => boolean;
|
|
5
7
|
declare function onCleanup(fn: Cleanup): void;
|
|
6
8
|
declare function createRoot<T>(fn: (dispose: () => void) => T): T;
|
|
7
9
|
declare function onMount(fn: () => void): void;
|
|
@@ -15,8 +17,6 @@ declare function createContext<T>(defaultValue: T): Context<T>;
|
|
|
15
17
|
declare function provide<T, R>(ctx: Context<T>, value: T, fn: () => R): R;
|
|
16
18
|
declare function useContext<T>(ctx: Context<T>): T;
|
|
17
19
|
|
|
18
|
-
declare function createMemo<T>(fn: () => T): () => T;
|
|
19
|
-
|
|
20
20
|
interface Resource<T> {
|
|
21
21
|
(): T | undefined;
|
|
22
22
|
loading: () => boolean;
|
|
@@ -141,5 +141,5 @@ declare function Fragment(props: {
|
|
|
141
141
|
declare function setRenderer(renderer: Renderer): void;
|
|
142
142
|
declare function getRenderer(): Renderer;
|
|
143
143
|
|
|
144
|
-
export { Dynamic, ErrorBoundary, For, Fragment, JSX, Match, Portal, Show, Suspense, Switch, batch, catchError, createContext, createEffect, createMemo, createResource, createRoot, createSignal, createStore, getRenderer, h, jsx, jsxDEV, jsxs, lazy, onCleanup, onMount, provide, render, setRenderer, untrack, unwrap, useContext };
|
|
144
|
+
export { Dynamic, ErrorBoundary, For, Fragment, JSX, Match, Portal, Show, Suspense, Switch, batch, catchError, createContext, createEffect, createMemo, createResource, createRoot, createSelector, createSignal, createStore, getRenderer, h, jsx, jsxDEV, jsxs, lazy, onCleanup, onMount, provide, render, setRenderer, untrack, unwrap, useContext };
|
|
145
145
|
export type { Child, Context, HostNode, MatchDef, Renderer, Resource, ResourceActions, SetStoreFunction };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ type Cleanup = () => void;
|
|
|
2
2
|
declare function batch<T>(fn: () => T): T;
|
|
3
3
|
declare function createSignal<T>(value: T): readonly [() => T, (next: T | ((prev: T) => T)) => void];
|
|
4
4
|
declare function createEffect(fn: () => void): void;
|
|
5
|
+
declare function createMemo<T>(fn: () => T): () => T;
|
|
6
|
+
declare function createSelector<T>(source: () => T): (key: T) => boolean;
|
|
5
7
|
declare function onCleanup(fn: Cleanup): void;
|
|
6
8
|
declare function createRoot<T>(fn: (dispose: () => void) => T): T;
|
|
7
9
|
declare function onMount(fn: () => void): void;
|
|
@@ -15,8 +17,6 @@ declare function createContext<T>(defaultValue: T): Context<T>;
|
|
|
15
17
|
declare function provide<T, R>(ctx: Context<T>, value: T, fn: () => R): R;
|
|
16
18
|
declare function useContext<T>(ctx: Context<T>): T;
|
|
17
19
|
|
|
18
|
-
declare function createMemo<T>(fn: () => T): () => T;
|
|
19
|
-
|
|
20
20
|
interface Resource<T> {
|
|
21
21
|
(): T | undefined;
|
|
22
22
|
loading: () => boolean;
|
|
@@ -141,5 +141,5 @@ declare function Fragment(props: {
|
|
|
141
141
|
declare function setRenderer(renderer: Renderer): void;
|
|
142
142
|
declare function getRenderer(): Renderer;
|
|
143
143
|
|
|
144
|
-
export { Dynamic, ErrorBoundary, For, Fragment, JSX, Match, Portal, Show, Suspense, Switch, batch, catchError, createContext, createEffect, createMemo, createResource, createRoot, createSignal, createStore, getRenderer, h, jsx, jsxDEV, jsxs, lazy, onCleanup, onMount, provide, render, setRenderer, untrack, unwrap, useContext };
|
|
144
|
+
export { Dynamic, ErrorBoundary, For, Fragment, JSX, Match, Portal, Show, Suspense, Switch, batch, catchError, createContext, createEffect, createMemo, createResource, createRoot, createSelector, createSignal, createStore, getRenderer, h, jsx, jsxDEV, jsxs, lazy, onCleanup, onMount, provide, render, setRenderer, untrack, unwrap, useContext };
|
|
145
145
|
export type { Child, Context, HostNode, MatchDef, Renderer, Resource, ResourceActions, SetStoreFunction };
|
package/dist/index.js
CHANGED
|
@@ -22,16 +22,19 @@ function logError(message, error) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// src/reactivity/signal.ts
|
|
25
|
+
var CLEAN = 0;
|
|
26
|
+
var CHECK = 1;
|
|
27
|
+
var DIRTY = 2;
|
|
25
28
|
var currentOwner = null;
|
|
26
|
-
var
|
|
29
|
+
var listener = null;
|
|
27
30
|
function clean(owner) {
|
|
28
31
|
const fns = owner.cleanups;
|
|
29
32
|
owner.cleanups = [];
|
|
30
33
|
for (const fn of fns) fn();
|
|
31
34
|
}
|
|
32
35
|
function cleanComputation(c) {
|
|
33
|
-
for (const
|
|
34
|
-
c.
|
|
36
|
+
for (const source of c.sources) source.observers.delete(c);
|
|
37
|
+
c.sources.clear();
|
|
35
38
|
clean(c);
|
|
36
39
|
}
|
|
37
40
|
function addCleanup(fn) {
|
|
@@ -47,11 +50,104 @@ function handleError(error, owner) {
|
|
|
47
50
|
throw error;
|
|
48
51
|
}
|
|
49
52
|
var batchDepth = 0;
|
|
50
|
-
var
|
|
53
|
+
var flushing = false;
|
|
54
|
+
var queued = /* @__PURE__ */ new Set();
|
|
55
|
+
var isComputation = (source) => "fn" in source;
|
|
56
|
+
function track(source) {
|
|
57
|
+
if (listener) {
|
|
58
|
+
source.observers.add(listener);
|
|
59
|
+
listener.sources.add(source);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function mark(node, state) {
|
|
63
|
+
if (node.disposed || node.state >= state) return;
|
|
64
|
+
const wasClean = node.state === CLEAN;
|
|
65
|
+
node.state = state;
|
|
66
|
+
if (!wasClean) return;
|
|
67
|
+
if (node.isEffect) {
|
|
68
|
+
queued.add(node);
|
|
69
|
+
} else {
|
|
70
|
+
for (const observer of node.observers) mark(observer, CHECK);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function notify(source) {
|
|
74
|
+
for (const observer of source.observers) mark(observer, DIRTY);
|
|
75
|
+
if (batchDepth === 0 && !flushing) flush();
|
|
76
|
+
}
|
|
77
|
+
function run(node) {
|
|
78
|
+
cleanComputation(node);
|
|
79
|
+
const prevOwner = currentOwner;
|
|
80
|
+
const prevListener = listener;
|
|
81
|
+
currentOwner = node;
|
|
82
|
+
listener = node;
|
|
83
|
+
node.state = CLEAN;
|
|
84
|
+
try {
|
|
85
|
+
const result = node.fn();
|
|
86
|
+
if (!node.isEffect) {
|
|
87
|
+
const changed = node.hasValue && !Object.is(node.value, result);
|
|
88
|
+
node.value = result;
|
|
89
|
+
node.hasValue = true;
|
|
90
|
+
if (changed) {
|
|
91
|
+
for (const observer of node.observers) {
|
|
92
|
+
if (observer.state === CHECK) observer.state = DIRTY;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
handleError(error, node);
|
|
98
|
+
} finally {
|
|
99
|
+
currentOwner = prevOwner;
|
|
100
|
+
listener = prevListener;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function update(node) {
|
|
104
|
+
if (node.disposed) {
|
|
105
|
+
node.state = CLEAN;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (node.state === CHECK) {
|
|
109
|
+
for (const source of [...node.sources]) {
|
|
110
|
+
if (isComputation(source)) {
|
|
111
|
+
update(source);
|
|
112
|
+
if (node.state === DIRTY) break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (node.state === DIRTY) run(node);
|
|
117
|
+
else node.state = CLEAN;
|
|
118
|
+
}
|
|
51
119
|
function flush() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
120
|
+
flushing = true;
|
|
121
|
+
let failure = null;
|
|
122
|
+
let steps = 0;
|
|
123
|
+
try {
|
|
124
|
+
while (queued.size > 0) {
|
|
125
|
+
if (++steps > 1e5) {
|
|
126
|
+
queued.clear();
|
|
127
|
+
failure ??= {
|
|
128
|
+
error: new Error(
|
|
129
|
+
"Cajoa: updates never settled. An effect probably keeps changing a signal that it also reads."
|
|
130
|
+
)
|
|
131
|
+
};
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
const effect = queued.values().next().value;
|
|
135
|
+
queued.delete(effect);
|
|
136
|
+
try {
|
|
137
|
+
update(effect);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
failure ??= { error };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} finally {
|
|
143
|
+
flushing = false;
|
|
144
|
+
}
|
|
145
|
+
if (failure) throw failure.error;
|
|
146
|
+
}
|
|
147
|
+
function dispose(node) {
|
|
148
|
+
node.disposed = true;
|
|
149
|
+
queued.delete(node);
|
|
150
|
+
cleanComputation(node);
|
|
55
151
|
}
|
|
56
152
|
function batch(fn) {
|
|
57
153
|
batchDepth++;
|
|
@@ -59,58 +155,84 @@ function batch(fn) {
|
|
|
59
155
|
return fn();
|
|
60
156
|
} finally {
|
|
61
157
|
batchDepth--;
|
|
62
|
-
if (batchDepth === 0) flush();
|
|
158
|
+
if (batchDepth === 0 && !flushing) flush();
|
|
63
159
|
}
|
|
64
160
|
}
|
|
65
161
|
function createSignal(value) {
|
|
66
|
-
const
|
|
162
|
+
const source = { observers: /* @__PURE__ */ new Set() };
|
|
67
163
|
const get = () => {
|
|
68
|
-
|
|
69
|
-
subs.add(currentEffect);
|
|
70
|
-
currentEffect.deps.add(subs);
|
|
71
|
-
}
|
|
164
|
+
track(source);
|
|
72
165
|
return value;
|
|
73
166
|
};
|
|
74
167
|
const set = (next) => {
|
|
75
168
|
const v = typeof next === "function" ? next(value) : next;
|
|
76
169
|
if (Object.is(v, value)) return;
|
|
77
170
|
value = v;
|
|
78
|
-
|
|
79
|
-
if (batchDepth > 0)
|
|
80
|
-
pending.add(effect);
|
|
81
|
-
else effect.run();
|
|
82
|
-
}
|
|
171
|
+
notify(source);
|
|
83
172
|
};
|
|
84
173
|
return [get, set];
|
|
85
174
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
175
|
+
function createComputation(fn, isEffect) {
|
|
176
|
+
return {
|
|
177
|
+
fn,
|
|
178
|
+
isEffect,
|
|
88
179
|
cleanups: [],
|
|
89
180
|
parent: currentOwner,
|
|
90
|
-
|
|
181
|
+
sources: /* @__PURE__ */ new Set(),
|
|
182
|
+
observers: /* @__PURE__ */ new Set(),
|
|
183
|
+
state: DIRTY,
|
|
91
184
|
disposed: false,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
185
|
+
hasValue: false,
|
|
186
|
+
value: void 0
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function createEffect(fn) {
|
|
190
|
+
const node = createComputation(fn, true);
|
|
191
|
+
addCleanup(() => dispose(node));
|
|
192
|
+
run(node);
|
|
193
|
+
}
|
|
194
|
+
function createMemo(fn) {
|
|
195
|
+
const node = createComputation(fn, false);
|
|
196
|
+
addCleanup(() => dispose(node));
|
|
197
|
+
run(node);
|
|
198
|
+
return () => {
|
|
199
|
+
if (node.state !== CLEAN) update(node);
|
|
200
|
+
track(node);
|
|
201
|
+
return node.value;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function createSelector(source) {
|
|
205
|
+
const cells = /* @__PURE__ */ new Map();
|
|
206
|
+
let previous = untrack(source);
|
|
207
|
+
createEffect(() => {
|
|
208
|
+
const next = source();
|
|
209
|
+
if (Object.is(next, previous)) return;
|
|
210
|
+
const old = previous;
|
|
211
|
+
previous = next;
|
|
212
|
+
batch(() => {
|
|
213
|
+
for (const key of [old, next]) {
|
|
214
|
+
const cell = cells.get(key);
|
|
215
|
+
if (cell) notify(cell);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
return (key) => {
|
|
220
|
+
const current2 = untrack(source);
|
|
221
|
+
if (listener) {
|
|
222
|
+
let cell = cells.get(key);
|
|
223
|
+
if (!cell) {
|
|
224
|
+
cell = { observers: /* @__PURE__ */ new Set() };
|
|
225
|
+
cells.set(key, cell);
|
|
106
226
|
}
|
|
227
|
+
track(cell);
|
|
228
|
+
const mine = cell;
|
|
229
|
+
listener.cleanups.push(() => {
|
|
230
|
+
if (mine.observers.size === 0 && cells.get(key) === mine)
|
|
231
|
+
cells.delete(key);
|
|
232
|
+
});
|
|
107
233
|
}
|
|
234
|
+
return Object.is(current2, key);
|
|
108
235
|
};
|
|
109
|
-
addCleanup(() => {
|
|
110
|
-
effect.disposed = true;
|
|
111
|
-
cleanComputation(effect);
|
|
112
|
-
});
|
|
113
|
-
effect.run();
|
|
114
236
|
}
|
|
115
237
|
function onCleanup(fn) {
|
|
116
238
|
if (!currentOwner) {
|
|
@@ -123,40 +245,40 @@ function onCleanup(fn) {
|
|
|
123
245
|
function createRoot(fn) {
|
|
124
246
|
const root = { cleanups: [], parent: currentOwner };
|
|
125
247
|
const prevOwner = currentOwner;
|
|
126
|
-
const
|
|
248
|
+
const prevListener = listener;
|
|
127
249
|
currentOwner = root;
|
|
128
|
-
|
|
250
|
+
listener = null;
|
|
129
251
|
try {
|
|
130
252
|
return fn(() => clean(root));
|
|
131
253
|
} finally {
|
|
132
254
|
currentOwner = prevOwner;
|
|
133
|
-
|
|
255
|
+
listener = prevListener;
|
|
134
256
|
}
|
|
135
257
|
}
|
|
136
258
|
function onMount(fn) {
|
|
137
259
|
const owner = currentOwner;
|
|
138
260
|
Promise.resolve().then(() => {
|
|
139
261
|
const prevOwner = currentOwner;
|
|
140
|
-
const
|
|
262
|
+
const prevListener = listener;
|
|
141
263
|
currentOwner = owner;
|
|
142
|
-
|
|
264
|
+
listener = null;
|
|
143
265
|
try {
|
|
144
266
|
fn();
|
|
145
267
|
} catch (error) {
|
|
146
268
|
handleError(error, owner);
|
|
147
269
|
} finally {
|
|
148
270
|
currentOwner = prevOwner;
|
|
149
|
-
|
|
271
|
+
listener = prevListener;
|
|
150
272
|
}
|
|
151
273
|
});
|
|
152
274
|
}
|
|
153
275
|
function untrack(fn) {
|
|
154
|
-
const prev =
|
|
155
|
-
|
|
276
|
+
const prev = listener;
|
|
277
|
+
listener = null;
|
|
156
278
|
try {
|
|
157
279
|
return fn();
|
|
158
280
|
} finally {
|
|
159
|
-
|
|
281
|
+
listener = prev;
|
|
160
282
|
}
|
|
161
283
|
}
|
|
162
284
|
function catchError(fn, handler) {
|
|
@@ -214,13 +336,6 @@ function useContext(ctx) {
|
|
|
214
336
|
return ctx.defaultValue;
|
|
215
337
|
}
|
|
216
338
|
|
|
217
|
-
// src/reactivity/memo.ts
|
|
218
|
-
function createMemo(fn) {
|
|
219
|
-
const [value, setValue] = createSignal(void 0);
|
|
220
|
-
createEffect(() => setValue(() => fn()));
|
|
221
|
-
return value;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
339
|
// src/reactivity/suspense.ts
|
|
225
340
|
var SuspenseContext = createContext(null);
|
|
226
341
|
function trackPending() {
|
|
@@ -240,12 +355,12 @@ function createResource(a, b) {
|
|
|
240
355
|
const [failure, setFailure] = createSignal(null);
|
|
241
356
|
const [loading, setLoading] = createSignal(false);
|
|
242
357
|
const [version, setVersion] = createSignal(0);
|
|
243
|
-
let
|
|
244
|
-
const
|
|
358
|
+
let run2 = 0;
|
|
359
|
+
const track2 = trackPending();
|
|
245
360
|
let release;
|
|
246
361
|
let settled = false;
|
|
247
362
|
const finish = (id, outcome) => {
|
|
248
|
-
if (id !==
|
|
363
|
+
if (id !== run2) return;
|
|
249
364
|
settled = true;
|
|
250
365
|
batch(() => {
|
|
251
366
|
setLoading(false);
|
|
@@ -262,10 +377,10 @@ function createResource(a, b) {
|
|
|
262
377
|
createEffect(() => {
|
|
263
378
|
const s = source();
|
|
264
379
|
version();
|
|
265
|
-
|
|
266
|
-
const id =
|
|
380
|
+
run2++;
|
|
381
|
+
const id = run2;
|
|
267
382
|
onCleanup(() => {
|
|
268
|
-
|
|
383
|
+
run2++;
|
|
269
384
|
release?.();
|
|
270
385
|
release = void 0;
|
|
271
386
|
});
|
|
@@ -277,7 +392,7 @@ function createResource(a, b) {
|
|
|
277
392
|
});
|
|
278
393
|
return;
|
|
279
394
|
}
|
|
280
|
-
if (!settled &&
|
|
395
|
+
if (!settled && track2 && !release) release = track2();
|
|
281
396
|
setLoading(true);
|
|
282
397
|
setFailure(null);
|
|
283
398
|
let result;
|
|
@@ -562,6 +677,65 @@ function getRenderer() {
|
|
|
562
677
|
return current;
|
|
563
678
|
}
|
|
564
679
|
|
|
680
|
+
// src/runtime/reconcile.ts
|
|
681
|
+
function longestIncreasingSubsequence(values) {
|
|
682
|
+
const predecessor = new Array(values.length);
|
|
683
|
+
const tails = [];
|
|
684
|
+
for (let i = 0; i < values.length; i++) {
|
|
685
|
+
const v = values[i];
|
|
686
|
+
if (v < 0) continue;
|
|
687
|
+
let lo;
|
|
688
|
+
if (tails.length === 0 || values[tails[tails.length - 1]] < v) {
|
|
689
|
+
lo = tails.length;
|
|
690
|
+
} else {
|
|
691
|
+
lo = 0;
|
|
692
|
+
let hi = tails.length - 1;
|
|
693
|
+
while (lo < hi) {
|
|
694
|
+
const mid = lo + hi >> 1;
|
|
695
|
+
if (values[tails[mid]] < v) lo = mid + 1;
|
|
696
|
+
else hi = mid;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
predecessor[i] = lo > 0 ? tails[lo - 1] : -1;
|
|
700
|
+
tails[lo] = i;
|
|
701
|
+
}
|
|
702
|
+
const result = new Array(tails.length);
|
|
703
|
+
let k = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
704
|
+
for (let j = tails.length - 1; j >= 0; j--) {
|
|
705
|
+
result[j] = k;
|
|
706
|
+
k = predecessor[k];
|
|
707
|
+
}
|
|
708
|
+
return result;
|
|
709
|
+
}
|
|
710
|
+
function reconcile(start, end, next) {
|
|
711
|
+
const r = getRenderer();
|
|
712
|
+
const keep = new Set(next);
|
|
713
|
+
const oldIndex = /* @__PURE__ */ new Map();
|
|
714
|
+
let count = 0;
|
|
715
|
+
let cur = r.nextSibling(start);
|
|
716
|
+
while (cur && cur !== end) {
|
|
717
|
+
const after = r.nextSibling(cur);
|
|
718
|
+
if (keep.has(cur)) oldIndex.set(cur, count++);
|
|
719
|
+
else r.remove(cur);
|
|
720
|
+
cur = after;
|
|
721
|
+
}
|
|
722
|
+
const parent = r.parentNode(end);
|
|
723
|
+
const n = next.length;
|
|
724
|
+
const positions = new Array(n);
|
|
725
|
+
for (let i = 0; i < n; i++) positions[i] = oldIndex.get(next[i]) ?? -1;
|
|
726
|
+
const stable = new Uint8Array(n);
|
|
727
|
+
for (const i of longestIncreasingSubsequence(positions)) stable[i] = 1;
|
|
728
|
+
const anchors = new Array(n);
|
|
729
|
+
let anchor = end;
|
|
730
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
731
|
+
anchors[i] = anchor;
|
|
732
|
+
if (stable[i]) anchor = next[i];
|
|
733
|
+
}
|
|
734
|
+
for (let i = 0; i < n; i++) {
|
|
735
|
+
if (!stable[i]) r.insert(parent, next[i], anchors[i]);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
565
739
|
// src/runtime/h.ts
|
|
566
740
|
function h(tag, props, ...children) {
|
|
567
741
|
const r = getRenderer();
|
|
@@ -602,22 +776,6 @@ function toNodes(value) {
|
|
|
602
776
|
}
|
|
603
777
|
return out;
|
|
604
778
|
}
|
|
605
|
-
function reconcile(start, end, next) {
|
|
606
|
-
const r = getRenderer();
|
|
607
|
-
const keep = new Set(next);
|
|
608
|
-
let cur = r.nextSibling(start);
|
|
609
|
-
while (cur && cur !== end) {
|
|
610
|
-
const after = r.nextSibling(cur);
|
|
611
|
-
if (!keep.has(cur)) r.remove(cur);
|
|
612
|
-
cur = after;
|
|
613
|
-
}
|
|
614
|
-
const parent = r.parentNode(end);
|
|
615
|
-
let ref = r.nextSibling(start);
|
|
616
|
-
for (const node of next) {
|
|
617
|
-
if (node === ref) ref = r.nextSibling(ref);
|
|
618
|
-
else r.insert(parent, node, ref);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
779
|
function appendChildren(parent, children) {
|
|
622
780
|
const r = getRenderer();
|
|
623
781
|
for (const child of children.flat(Infinity)) {
|
|
@@ -635,7 +793,7 @@ function appendChildren(parent, children) {
|
|
|
635
793
|
|
|
636
794
|
// src/runtime/render.ts
|
|
637
795
|
function render(component, container) {
|
|
638
|
-
return createRoot((
|
|
796
|
+
return createRoot((dispose2) => {
|
|
639
797
|
const r = getRenderer();
|
|
640
798
|
const node = component();
|
|
641
799
|
if (typeof node === "function") {
|
|
@@ -646,7 +804,7 @@ function render(component, container) {
|
|
|
646
804
|
r.clear(container);
|
|
647
805
|
r.insert(container, node);
|
|
648
806
|
return () => {
|
|
649
|
-
|
|
807
|
+
dispose2();
|
|
650
808
|
r.clear(container);
|
|
651
809
|
};
|
|
652
810
|
});
|
|
@@ -687,9 +845,9 @@ function For(props) {
|
|
|
687
845
|
}
|
|
688
846
|
let entry = cache.get(k);
|
|
689
847
|
if (!entry) {
|
|
690
|
-
entry = createRoot((
|
|
848
|
+
entry = createRoot((dispose2) => ({
|
|
691
849
|
node: props.children(item, i),
|
|
692
|
-
dispose
|
|
850
|
+
dispose: dispose2
|
|
693
851
|
}));
|
|
694
852
|
}
|
|
695
853
|
next.set(k, entry);
|
|
@@ -852,7 +1010,7 @@ function resolve5(value) {
|
|
|
852
1010
|
return typeof value === "function" ? value() : value;
|
|
853
1011
|
}
|
|
854
1012
|
function Suspense(props) {
|
|
855
|
-
const [
|
|
1013
|
+
const [pending, setPending] = createSignal(0);
|
|
856
1014
|
const [ready, setReady] = createSignal(false);
|
|
857
1015
|
const state = {
|
|
858
1016
|
add() {
|
|
@@ -873,7 +1031,7 @@ function Suspense(props) {
|
|
|
873
1031
|
)
|
|
874
1032
|
);
|
|
875
1033
|
createEffect(() => {
|
|
876
|
-
if (
|
|
1034
|
+
if (pending() === 0) setReady(true);
|
|
877
1035
|
});
|
|
878
1036
|
return () => ready() ? content : untrack(() => resolve5(props.fallback ?? null));
|
|
879
1037
|
}
|
|
@@ -924,6 +1082,7 @@ export {
|
|
|
924
1082
|
createMemo,
|
|
925
1083
|
createResource,
|
|
926
1084
|
createRoot,
|
|
1085
|
+
createSelector,
|
|
927
1086
|
createSignal,
|
|
928
1087
|
createStore,
|
|
929
1088
|
getRenderer,
|