@solidjs/signals 0.6.3 → 0.6.4
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/dev.js +270 -261
- package/dist/node.cjs +520 -511
- package/dist/prod.js +508 -499
- package/dist/types/boundaries.d.ts +1 -1
- package/dist/types/core/core.d.ts +1 -0
- package/dist/types/core/scheduler.d.ts +1 -1
- package/dist/types/signals.d.ts +0 -22
- package/dist/types/store/index.d.ts +1 -0
- package/dist/types/store/optimistic.d.ts +22 -0
- package/dist/types/store/projection.d.ts +6 -1
- package/dist/types/store/store.d.ts +1 -1
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -176,7 +176,7 @@ var Transition = class _Transition {
|
|
|
176
176
|
constructor() {
|
|
177
177
|
this._clonedQueues.set(globalQueue, this);
|
|
178
178
|
for (const child of globalQueue._children) {
|
|
179
|
-
cloneQueue(child, this, this
|
|
179
|
+
cloneQueue(child, this, this);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
enqueue(type, fn) {
|
|
@@ -276,8 +276,7 @@ var Transition = class _Transition {
|
|
|
276
276
|
try {
|
|
277
277
|
value = await temp.value;
|
|
278
278
|
} finally {
|
|
279
|
-
|
|
280
|
-
transition2 = transition2._done;
|
|
279
|
+
transition2 = latestTransition(transition2);
|
|
281
280
|
transition2._promises.delete(temp.value);
|
|
282
281
|
}
|
|
283
282
|
ActiveTransition = transition2;
|
|
@@ -291,8 +290,7 @@ var Transition = class _Transition {
|
|
|
291
290
|
if (result instanceof Promise) {
|
|
292
291
|
transition2._promises.add(result);
|
|
293
292
|
result.finally(() => {
|
|
294
|
-
|
|
295
|
-
transition2 = transition2._done;
|
|
293
|
+
transition2 = latestTransition(transition2);
|
|
296
294
|
transition2._promises.delete(result);
|
|
297
295
|
ActiveTransition = null;
|
|
298
296
|
finishTransition(transition2);
|
|
@@ -318,7 +316,7 @@ function transition(fn) {
|
|
|
318
316
|
let t = new Transition();
|
|
319
317
|
queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
|
|
320
318
|
}
|
|
321
|
-
function cloneGraph(node) {
|
|
319
|
+
function cloneGraph(node, optimistic) {
|
|
322
320
|
if (node._transition) {
|
|
323
321
|
if (node._transition !== ActiveTransition) {
|
|
324
322
|
mergeTransitions(node._transition, ActiveTransition);
|
|
@@ -332,48 +330,58 @@ function cloneGraph(node) {
|
|
|
332
330
|
_nextSibling: null,
|
|
333
331
|
_observers: null,
|
|
334
332
|
_sources: node._sources ? [...node._sources] : null,
|
|
335
|
-
_cloned: node
|
|
333
|
+
_cloned: node,
|
|
334
|
+
_optimistic: !!optimistic
|
|
336
335
|
});
|
|
336
|
+
delete clone._prevValue;
|
|
337
337
|
ActiveTransition._sources.set(node, clone);
|
|
338
338
|
node._transition = ActiveTransition;
|
|
339
|
-
if (node._sources) {
|
|
339
|
+
if (!optimistic && node._sources) {
|
|
340
340
|
for (let i = 0; i < node._sources.length; i++)
|
|
341
341
|
node._sources[i]._observers.push(clone);
|
|
342
342
|
}
|
|
343
343
|
if (node._observers) {
|
|
344
344
|
clone._observers = [];
|
|
345
345
|
for (let i = 0, length = node._observers.length; i < length; i++) {
|
|
346
|
-
!node._observers[i]._cloned && clone._observers.push(cloneGraph(node._observers[i]));
|
|
346
|
+
!node._observers[i]._cloned && clone._observers.push(cloneGraph(node._observers[i], optimistic));
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
return clone;
|
|
350
350
|
}
|
|
351
|
+
function latestTransition(t) {
|
|
352
|
+
while (t._done instanceof Transition)
|
|
353
|
+
t = t._done;
|
|
354
|
+
return t;
|
|
355
|
+
}
|
|
351
356
|
function replaceSourceObservers(node, transition2) {
|
|
352
357
|
let source;
|
|
358
|
+
let transitionSource;
|
|
353
359
|
let swap;
|
|
354
360
|
for (let i = 0; i < node._sources.length; i++) {
|
|
355
|
-
|
|
361
|
+
transitionSource = transition2._sources.get(node._sources[i]);
|
|
362
|
+
source = transitionSource || node._sources[i];
|
|
356
363
|
if (source._observers && (swap = source._observers.indexOf(node)) !== -1) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
remove && source._observers.pop();
|
|
364
|
+
source._observers[swap] = transitionSource ? node._cloned : source._observers[source._observers.length - 1];
|
|
365
|
+
!transitionSource && source._observers.pop();
|
|
360
366
|
}
|
|
361
367
|
}
|
|
362
368
|
}
|
|
363
|
-
function cloneQueue(queue, parent,
|
|
369
|
+
function cloneQueue(queue, parent, transition2) {
|
|
364
370
|
const clone = Object.create(Object.getPrototypeOf(queue));
|
|
365
371
|
Object.assign(clone, queue, {
|
|
366
372
|
_cloned: queue,
|
|
367
373
|
_parent: parent,
|
|
368
374
|
_children: [],
|
|
369
375
|
enqueue(type, fn) {
|
|
370
|
-
|
|
376
|
+
transition2 = latestTransition(transition2);
|
|
377
|
+
transition2.enqueue(type, fn);
|
|
371
378
|
},
|
|
372
379
|
notify(node, type, flags) {
|
|
373
380
|
node = node._cloned || node;
|
|
374
381
|
if (!clone._collectionType || type & LOADING_BIT) {
|
|
375
382
|
type &= ~LOADING_BIT;
|
|
376
|
-
|
|
383
|
+
transition2 = latestTransition(transition2);
|
|
384
|
+
transition2.notify(node, LOADING_BIT, flags);
|
|
377
385
|
if (!type)
|
|
378
386
|
return true;
|
|
379
387
|
}
|
|
@@ -381,9 +389,9 @@ function cloneQueue(queue, parent, clonedQueues) {
|
|
|
381
389
|
}
|
|
382
390
|
});
|
|
383
391
|
parent._children.push(clone);
|
|
384
|
-
|
|
392
|
+
transition2._clonedQueues.set(queue, clone);
|
|
385
393
|
for (const child of queue._children) {
|
|
386
|
-
cloneQueue(child, clone,
|
|
394
|
+
cloneQueue(child, clone, transition2);
|
|
387
395
|
}
|
|
388
396
|
}
|
|
389
397
|
function resolveQueues(children) {
|
|
@@ -447,6 +455,12 @@ function finishTransition(transition2) {
|
|
|
447
455
|
}
|
|
448
456
|
if (clone._sources)
|
|
449
457
|
replaceSourceObservers(clone, transition2);
|
|
458
|
+
if (clone._optimistic) {
|
|
459
|
+
clone.dispose();
|
|
460
|
+
clone.emptyDisposal();
|
|
461
|
+
delete source._transition;
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
450
464
|
if (clone._updated || clone._state === STATE_DISPOSED) {
|
|
451
465
|
source.dispose(clone._state === STATE_DISPOSED);
|
|
452
466
|
source.emptyDisposal();
|
|
@@ -645,6 +659,7 @@ var Computation = class extends Owner {
|
|
|
645
659
|
_forceNotify = false;
|
|
646
660
|
_transition;
|
|
647
661
|
_cloned;
|
|
662
|
+
_optimistic = false;
|
|
648
663
|
constructor(initialValue, compute2, options) {
|
|
649
664
|
super(options?.id, compute2 === null);
|
|
650
665
|
this._compute = compute2;
|
|
@@ -654,10 +669,8 @@ var Computation = class extends Owner {
|
|
|
654
669
|
this._name = options?.name ?? (this._compute ? "computed" : "signal");
|
|
655
670
|
if (options?.equals !== void 0)
|
|
656
671
|
this._equals = options.equals;
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (options?.unobserved)
|
|
660
|
-
this._unobserved = options?.unobserved;
|
|
672
|
+
this._pureWrite = !!options?.pureWrite;
|
|
673
|
+
this._unobserved = options?.unobserved;
|
|
661
674
|
if (ActiveTransition) {
|
|
662
675
|
this._transition = ActiveTransition;
|
|
663
676
|
ActiveTransition._sources.set(this, this);
|
|
@@ -1065,7 +1078,7 @@ var Effect = class extends Computation {
|
|
|
1065
1078
|
_notify(state, skipQueue) {
|
|
1066
1079
|
if (this._state >= state || skipQueue)
|
|
1067
1080
|
return;
|
|
1068
|
-
if (this._state === STATE_CLEAN)
|
|
1081
|
+
if (this._state === STATE_CLEAN || this._cloned && !ActiveTransition)
|
|
1069
1082
|
getQueue(this).enqueue(this._type, this._run.bind(this));
|
|
1070
1083
|
this._state = state;
|
|
1071
1084
|
}
|
|
@@ -1179,12 +1192,195 @@ function runTop(node) {
|
|
|
1179
1192
|
}
|
|
1180
1193
|
}
|
|
1181
1194
|
|
|
1195
|
+
// src/signals.ts
|
|
1196
|
+
function createSignal(first, second, third) {
|
|
1197
|
+
if (typeof first === "function") {
|
|
1198
|
+
const memo = createMemo((p) => {
|
|
1199
|
+
const node2 = new Computation(
|
|
1200
|
+
first(p ? untrack(p[0]) : second),
|
|
1201
|
+
null,
|
|
1202
|
+
third
|
|
1203
|
+
);
|
|
1204
|
+
return [node2.read.bind(node2), node2.write.bind(node2)];
|
|
1205
|
+
});
|
|
1206
|
+
return [() => memo()[0](), (value) => memo()[1](value)];
|
|
1207
|
+
}
|
|
1208
|
+
const o = getOwner();
|
|
1209
|
+
const needsId = o?.id != null;
|
|
1210
|
+
const node = new Computation(
|
|
1211
|
+
first,
|
|
1212
|
+
null,
|
|
1213
|
+
needsId ? { id: o.getNextChildId(), ...second } : second
|
|
1214
|
+
);
|
|
1215
|
+
return [node.read.bind(node), node.write.bind(node)];
|
|
1216
|
+
}
|
|
1217
|
+
function createMemo(compute2, value, options) {
|
|
1218
|
+
let node = new Computation(
|
|
1219
|
+
value,
|
|
1220
|
+
compute2,
|
|
1221
|
+
options
|
|
1222
|
+
);
|
|
1223
|
+
let resolvedValue;
|
|
1224
|
+
return () => {
|
|
1225
|
+
if (node) {
|
|
1226
|
+
if (node._state === STATE_DISPOSED) {
|
|
1227
|
+
node = void 0;
|
|
1228
|
+
return resolvedValue;
|
|
1229
|
+
}
|
|
1230
|
+
resolvedValue = node.wait();
|
|
1231
|
+
if (!node._sources?.length && node._nextSibling?._parent !== node && !(node._stateFlags & UNINITIALIZED_BIT)) {
|
|
1232
|
+
node.dispose();
|
|
1233
|
+
node = void 0;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
return resolvedValue;
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
function createAsync(compute2, value, options) {
|
|
1240
|
+
let refreshing = false;
|
|
1241
|
+
const node = new EagerComputation(
|
|
1242
|
+
value,
|
|
1243
|
+
(p) => {
|
|
1244
|
+
const source = compute2(p, refreshing);
|
|
1245
|
+
refreshing = false;
|
|
1246
|
+
const isPromise = source instanceof Promise;
|
|
1247
|
+
const iterator = source[Symbol.asyncIterator];
|
|
1248
|
+
if (!isPromise && !iterator) {
|
|
1249
|
+
return source;
|
|
1250
|
+
}
|
|
1251
|
+
let abort = false;
|
|
1252
|
+
onCleanup(() => abort = true);
|
|
1253
|
+
let transition2 = ActiveTransition;
|
|
1254
|
+
if (isPromise) {
|
|
1255
|
+
source.then(
|
|
1256
|
+
(value3) => {
|
|
1257
|
+
if (abort)
|
|
1258
|
+
return;
|
|
1259
|
+
if (transition2)
|
|
1260
|
+
return transition2.runTransition(() => {
|
|
1261
|
+
node.write(value3, 0, true);
|
|
1262
|
+
}, true);
|
|
1263
|
+
node.write(value3, 0, true);
|
|
1264
|
+
},
|
|
1265
|
+
(error) => {
|
|
1266
|
+
if (abort)
|
|
1267
|
+
return;
|
|
1268
|
+
if (transition2)
|
|
1269
|
+
return transition2.runTransition(() => node._setError(error), true);
|
|
1270
|
+
node._setError(error);
|
|
1271
|
+
}
|
|
1272
|
+
);
|
|
1273
|
+
} else {
|
|
1274
|
+
(async () => {
|
|
1275
|
+
try {
|
|
1276
|
+
for await (let value3 of source) {
|
|
1277
|
+
if (abort)
|
|
1278
|
+
return;
|
|
1279
|
+
if (transition2)
|
|
1280
|
+
return transition2.runTransition(() => {
|
|
1281
|
+
node.write(value3, 0, true);
|
|
1282
|
+
transition2 = null;
|
|
1283
|
+
}, true);
|
|
1284
|
+
node.write(value3, 0, true);
|
|
1285
|
+
}
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
if (abort)
|
|
1288
|
+
return;
|
|
1289
|
+
if (transition2)
|
|
1290
|
+
return transition2.runTransition(() => {
|
|
1291
|
+
node._setError(error);
|
|
1292
|
+
transition2 = null;
|
|
1293
|
+
}, true);
|
|
1294
|
+
node._setError(error);
|
|
1295
|
+
}
|
|
1296
|
+
})();
|
|
1297
|
+
}
|
|
1298
|
+
throw new NotReadyError();
|
|
1299
|
+
},
|
|
1300
|
+
options
|
|
1301
|
+
);
|
|
1302
|
+
const read = node.wait.bind(node);
|
|
1303
|
+
read.refresh = () => {
|
|
1304
|
+
let n = node;
|
|
1305
|
+
if (ActiveTransition && !node._cloned) {
|
|
1306
|
+
n = cloneGraph(node);
|
|
1307
|
+
}
|
|
1308
|
+
n._state = STATE_DIRTY;
|
|
1309
|
+
refreshing = true;
|
|
1310
|
+
n._updateIfNecessary();
|
|
1311
|
+
};
|
|
1312
|
+
return read;
|
|
1313
|
+
}
|
|
1314
|
+
function createEffect(compute2, effect, value, options) {
|
|
1315
|
+
void new Effect(
|
|
1316
|
+
value,
|
|
1317
|
+
compute2,
|
|
1318
|
+
effect.effect ? effect.effect : effect,
|
|
1319
|
+
effect.error,
|
|
1320
|
+
{ ...options, name: options?.name ?? "effect" }
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
function createRenderEffect(compute2, effect, value, options) {
|
|
1324
|
+
void new Effect(value, compute2, effect, void 0, {
|
|
1325
|
+
render: true,
|
|
1326
|
+
...{ ...options, name: options?.name ?? "effect" }
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
function createRoot(init, options) {
|
|
1330
|
+
const owner = new Owner(options?.id);
|
|
1331
|
+
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
1332
|
+
}
|
|
1333
|
+
function runWithOwner(owner, run) {
|
|
1334
|
+
return compute(owner, run, null);
|
|
1335
|
+
}
|
|
1336
|
+
function resolve(fn) {
|
|
1337
|
+
return new Promise((res, rej) => {
|
|
1338
|
+
createRoot((dispose) => {
|
|
1339
|
+
new EagerComputation(void 0, () => {
|
|
1340
|
+
try {
|
|
1341
|
+
res(fn());
|
|
1342
|
+
} catch (err) {
|
|
1343
|
+
if (err instanceof NotReadyError)
|
|
1344
|
+
throw err;
|
|
1345
|
+
rej(err);
|
|
1346
|
+
}
|
|
1347
|
+
dispose();
|
|
1348
|
+
});
|
|
1349
|
+
});
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
function createPending() {
|
|
1353
|
+
const node = new Computation(false, null);
|
|
1354
|
+
const reset = () => node.write(false);
|
|
1355
|
+
function write() {
|
|
1356
|
+
if (!ActiveTransition)
|
|
1357
|
+
return false;
|
|
1358
|
+
ActiveTransition.addOptimistic(reset);
|
|
1359
|
+
queueMicrotask(() => reset._transition && node.write(true));
|
|
1360
|
+
}
|
|
1361
|
+
function read() {
|
|
1362
|
+
const v = node.read();
|
|
1363
|
+
return ActiveTransition ? false : v;
|
|
1364
|
+
}
|
|
1365
|
+
return [read, write];
|
|
1366
|
+
}
|
|
1367
|
+
function useTransition() {
|
|
1368
|
+
const [pending, setPending] = createPending();
|
|
1369
|
+
function start(fn) {
|
|
1370
|
+
transition((resume) => {
|
|
1371
|
+
setPending(true);
|
|
1372
|
+
return fn(resume);
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
return [pending, start];
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1182
1378
|
// src/store/reconcile.ts
|
|
1183
1379
|
function unwrap(value) {
|
|
1184
1380
|
return value?.[$TARGET]?.[STORE_NODE] ?? value;
|
|
1185
1381
|
}
|
|
1186
|
-
function getOverrideValue(value, override, key) {
|
|
1187
|
-
return override && key in override ? override[key] : value[key];
|
|
1382
|
+
function getOverrideValue(value, override, nodes, key) {
|
|
1383
|
+
return nodes && key in nodes ? nodes[key].read() : override && key in override ? override[key] : value[key];
|
|
1188
1384
|
}
|
|
1189
1385
|
function getAllKeys(value, override, next) {
|
|
1190
1386
|
const keys = getKeys(value, override);
|
|
@@ -1197,6 +1393,7 @@ function applyState(next, state, keyFn, all) {
|
|
|
1197
1393
|
return;
|
|
1198
1394
|
const previous = target[STORE_VALUE];
|
|
1199
1395
|
const override = target[STORE_OVERRIDE];
|
|
1396
|
+
let nodes = target[STORE_NODE];
|
|
1200
1397
|
if (next === previous && !override)
|
|
1201
1398
|
return;
|
|
1202
1399
|
(target[STORE_LOOKUP] || storeLookup).set(next, target[$PROXY]);
|
|
@@ -1204,14 +1401,14 @@ function applyState(next, state, keyFn, all) {
|
|
|
1204
1401
|
target[STORE_OVERRIDE] = void 0;
|
|
1205
1402
|
if (Array.isArray(previous)) {
|
|
1206
1403
|
let changed = false;
|
|
1207
|
-
const prevLength = getOverrideValue(previous, override, "length");
|
|
1404
|
+
const prevLength = getOverrideValue(previous, override, nodes, "length");
|
|
1208
1405
|
if (next.length && prevLength && next[0] && keyFn(next[0]) != null) {
|
|
1209
1406
|
let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
|
|
1210
|
-
for (start = 0, end = Math.min(prevLength, next.length); start < end && ((item = getOverrideValue(previous, override, start)) === next[start] || item && next[start] && keyFn(item) === keyFn(next[start])); start++) {
|
|
1407
|
+
for (start = 0, end = Math.min(prevLength, next.length); start < end && ((item = getOverrideValue(previous, override, nodes, start)) === next[start] || item && next[start] && keyFn(item) === keyFn(next[start])); start++) {
|
|
1211
1408
|
applyState(next[start], wrap(item, target), keyFn, all);
|
|
1212
1409
|
}
|
|
1213
1410
|
const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
|
|
1214
|
-
for (end = prevLength - 1, newEnd = next.length - 1; end >= start && newEnd >= start && ((item = getOverrideValue(previous, override, end)) === next[newEnd] || item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])); end--, newEnd--) {
|
|
1411
|
+
for (end = prevLength - 1, newEnd = next.length - 1; end >= start && newEnd >= start && ((item = getOverrideValue(previous, override, nodes, end)) === next[newEnd] || item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])); end--, newEnd--) {
|
|
1215
1412
|
temp[newEnd] = item;
|
|
1216
1413
|
}
|
|
1217
1414
|
if (start > newEnd || start > end) {
|
|
@@ -1238,7 +1435,7 @@ function applyState(next, state, keyFn, all) {
|
|
|
1238
1435
|
newIndices.set(keyVal, j);
|
|
1239
1436
|
}
|
|
1240
1437
|
for (i = start; i <= end; i++) {
|
|
1241
|
-
item = getOverrideValue(previous, override, i);
|
|
1438
|
+
item = getOverrideValue(previous, override, nodes, i);
|
|
1242
1439
|
keyVal = item ? keyFn(item) : item;
|
|
1243
1440
|
j = newIndices.get(keyVal);
|
|
1244
1441
|
if (j !== void 0 && j !== -1) {
|
|
@@ -1259,7 +1456,7 @@ function applyState(next, state, keyFn, all) {
|
|
|
1259
1456
|
changed = true;
|
|
1260
1457
|
} else if (prevLength && next.length) {
|
|
1261
1458
|
for (let i = 0, len = next.length; i < len; i++) {
|
|
1262
|
-
const item = getOverrideValue(previous, override, i);
|
|
1459
|
+
const item = getOverrideValue(previous, override, nodes, i);
|
|
1263
1460
|
isWrappable(item) && applyState(next[i], wrap(item, target), keyFn, all);
|
|
1264
1461
|
}
|
|
1265
1462
|
}
|
|
@@ -1270,14 +1467,13 @@ function applyState(next, state, keyFn, all) {
|
|
|
1270
1467
|
changed && target[STORE_NODE][$TRACK]?.write(void 0);
|
|
1271
1468
|
return;
|
|
1272
1469
|
}
|
|
1273
|
-
let nodes = target[STORE_NODE];
|
|
1274
1470
|
if (nodes) {
|
|
1275
1471
|
const tracked = nodes[$TRACK];
|
|
1276
1472
|
const keys = tracked || all ? getAllKeys(previous, override, next) : Object.keys(nodes);
|
|
1277
1473
|
for (let i = 0, len = keys.length; i < len; i++) {
|
|
1278
1474
|
const key = keys[i];
|
|
1279
1475
|
const node = nodes[key];
|
|
1280
|
-
const previousValue = unwrap(getOverrideValue(previous, override, key));
|
|
1476
|
+
const previousValue = unwrap(getOverrideValue(previous, override, nodes, key));
|
|
1281
1477
|
let nextValue = unwrap(next[key]);
|
|
1282
1478
|
if (previousValue === nextValue)
|
|
1283
1479
|
continue;
|
|
@@ -1308,16 +1504,7 @@ function reconcile(value, key, all = false) {
|
|
|
1308
1504
|
}
|
|
1309
1505
|
|
|
1310
1506
|
// src/store/projection.ts
|
|
1311
|
-
function
|
|
1312
|
-
let wrappedStore;
|
|
1313
|
-
const node = new FirewallComputation(() => {
|
|
1314
|
-
storeSetter(wrappedStore, (s) => {
|
|
1315
|
-
const value = fn(s);
|
|
1316
|
-
if (value !== s && value !== void 0) {
|
|
1317
|
-
reconcile(value, options?.key || "id", options?.all)(s);
|
|
1318
|
-
}
|
|
1319
|
-
});
|
|
1320
|
-
});
|
|
1507
|
+
function createProjectionInternal(fn, initialValue = {}, options) {
|
|
1321
1508
|
const wrappedMap = /* @__PURE__ */ new WeakMap();
|
|
1322
1509
|
const traps = {
|
|
1323
1510
|
...storeTraps,
|
|
@@ -1328,7 +1515,7 @@ function createProjection(fn, initialValue = {}, options) {
|
|
|
1328
1515
|
return storeTraps.get(target, property, receiver);
|
|
1329
1516
|
}
|
|
1330
1517
|
};
|
|
1331
|
-
|
|
1518
|
+
const wrapProjection = (source) => {
|
|
1332
1519
|
if (wrappedMap.has(source))
|
|
1333
1520
|
return wrappedMap.get(source);
|
|
1334
1521
|
if (source[$TARGET]?.[STORE_WRAP] === wrapProjection)
|
|
@@ -1339,8 +1526,20 @@ function createProjection(fn, initialValue = {}, options) {
|
|
|
1339
1526
|
});
|
|
1340
1527
|
wrappedMap.set(source, wrapped);
|
|
1341
1528
|
return wrapped;
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1529
|
+
};
|
|
1530
|
+
const wrappedStore = wrapProjection(initialValue);
|
|
1531
|
+
const node = new FirewallComputation(() => {
|
|
1532
|
+
storeSetter(wrappedStore, (s) => {
|
|
1533
|
+
const value = fn(s);
|
|
1534
|
+
if (value !== s && value !== void 0) {
|
|
1535
|
+
reconcile(value, options?.key || "id", options?.all)(s);
|
|
1536
|
+
}
|
|
1537
|
+
});
|
|
1538
|
+
});
|
|
1539
|
+
return { store: wrappedStore, node };
|
|
1540
|
+
}
|
|
1541
|
+
function createProjection(fn, initialValue = {}, options) {
|
|
1542
|
+
return createProjectionInternal(fn, initialValue, options).store;
|
|
1344
1543
|
}
|
|
1345
1544
|
|
|
1346
1545
|
// src/store/store.ts
|
|
@@ -1476,7 +1675,7 @@ var storeTraps = {
|
|
|
1476
1675
|
untrack(() => {
|
|
1477
1676
|
const state = target[STORE_VALUE];
|
|
1478
1677
|
const base = state[property];
|
|
1479
|
-
const prev = target[STORE_OVERRIDE]
|
|
1678
|
+
const prev = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] : base;
|
|
1480
1679
|
const value = rawValue?.[$TARGET]?.[STORE_VALUE] ?? rawValue;
|
|
1481
1680
|
if (prev === value)
|
|
1482
1681
|
return true;
|
|
@@ -1508,7 +1707,7 @@ var storeTraps = {
|
|
|
1508
1707
|
deleteProperty(target, property) {
|
|
1509
1708
|
if (Writing?.has(target[$PROXY]) && target[STORE_OVERRIDE]?.[property] !== $DELETED) {
|
|
1510
1709
|
untrack(() => {
|
|
1511
|
-
const prev = target[STORE_OVERRIDE]
|
|
1710
|
+
const prev = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] : target[STORE_VALUE][property];
|
|
1512
1711
|
if (property in target[STORE_VALUE]) {
|
|
1513
1712
|
(target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = $DELETED;
|
|
1514
1713
|
} else if (target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]) {
|
|
@@ -1567,7 +1766,7 @@ function storeSetter(store, fn) {
|
|
|
1567
1766
|
}
|
|
1568
1767
|
}
|
|
1569
1768
|
function createStore(first, second, options) {
|
|
1570
|
-
const derived = typeof first === "function", wrappedStore = derived ?
|
|
1769
|
+
const derived = typeof first === "function", wrappedStore = derived ? createProjectionInternal(first, second, options).store : wrap(first);
|
|
1571
1770
|
return [wrappedStore, (fn) => storeSetter(wrappedStore, fn)];
|
|
1572
1771
|
}
|
|
1573
1772
|
function recursivelyNotify(state, lookup) {
|
|
@@ -1631,6 +1830,29 @@ function deep(store) {
|
|
|
1631
1830
|
return store[$DEEP];
|
|
1632
1831
|
}
|
|
1633
1832
|
|
|
1833
|
+
// src/store/optimistic.ts
|
|
1834
|
+
function createOptimistic(first, second, options) {
|
|
1835
|
+
const derived = typeof first === "function";
|
|
1836
|
+
const { store, node } = derived ? createProjectionInternal(first, second, options) : createProjectionInternal(() => {
|
|
1837
|
+
}, first);
|
|
1838
|
+
const reset = () => storeSetter(
|
|
1839
|
+
store,
|
|
1840
|
+
reconcile(
|
|
1841
|
+
derived ? first(store) || store : first,
|
|
1842
|
+
options?.key || "id",
|
|
1843
|
+
options?.all
|
|
1844
|
+
)
|
|
1845
|
+
);
|
|
1846
|
+
const write = (v) => {
|
|
1847
|
+
if (!ActiveTransition)
|
|
1848
|
+
throw new Error("createOptimistic can only be updated inside a transition");
|
|
1849
|
+
ActiveTransition.addOptimistic(reset);
|
|
1850
|
+
cloneGraph(node, true);
|
|
1851
|
+
queueMicrotask(() => reset._transition && storeSetter(store, v));
|
|
1852
|
+
};
|
|
1853
|
+
return [store, write];
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1634
1856
|
// src/store/utils.ts
|
|
1635
1857
|
function snapshot(item, map, lookup) {
|
|
1636
1858
|
let target, isArray, override, result, unwrapped, v;
|
|
@@ -1831,215 +2053,6 @@ function omit(props, ...keys) {
|
|
|
1831
2053
|
return result;
|
|
1832
2054
|
}
|
|
1833
2055
|
|
|
1834
|
-
// src/signals.ts
|
|
1835
|
-
function createSignal(first, second, third) {
|
|
1836
|
-
if (typeof first === "function") {
|
|
1837
|
-
const memo = createMemo((p) => {
|
|
1838
|
-
const node2 = new Computation(
|
|
1839
|
-
first(p ? untrack(p[0]) : second),
|
|
1840
|
-
null,
|
|
1841
|
-
third
|
|
1842
|
-
);
|
|
1843
|
-
return [node2.read.bind(node2), node2.write.bind(node2)];
|
|
1844
|
-
});
|
|
1845
|
-
return [() => memo()[0](), (value) => memo()[1](value)];
|
|
1846
|
-
}
|
|
1847
|
-
const o = getOwner();
|
|
1848
|
-
const needsId = o?.id != null;
|
|
1849
|
-
const node = new Computation(
|
|
1850
|
-
first,
|
|
1851
|
-
null,
|
|
1852
|
-
needsId ? { id: o.getNextChildId(), ...second } : second
|
|
1853
|
-
);
|
|
1854
|
-
return [node.read.bind(node), node.write.bind(node)];
|
|
1855
|
-
}
|
|
1856
|
-
function createMemo(compute2, value, options) {
|
|
1857
|
-
let node = new Computation(
|
|
1858
|
-
value,
|
|
1859
|
-
compute2,
|
|
1860
|
-
options
|
|
1861
|
-
);
|
|
1862
|
-
let resolvedValue;
|
|
1863
|
-
return () => {
|
|
1864
|
-
if (node) {
|
|
1865
|
-
if (node._state === STATE_DISPOSED) {
|
|
1866
|
-
node = void 0;
|
|
1867
|
-
return resolvedValue;
|
|
1868
|
-
}
|
|
1869
|
-
resolvedValue = node.wait();
|
|
1870
|
-
if (!node._sources?.length && node._nextSibling?._parent !== node && !(node._stateFlags & UNINITIALIZED_BIT)) {
|
|
1871
|
-
node.dispose();
|
|
1872
|
-
node = void 0;
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
return resolvedValue;
|
|
1876
|
-
};
|
|
1877
|
-
}
|
|
1878
|
-
function createAsync(compute2, value, options) {
|
|
1879
|
-
let refreshing = false;
|
|
1880
|
-
const node = new EagerComputation(
|
|
1881
|
-
value,
|
|
1882
|
-
(p) => {
|
|
1883
|
-
const source = compute2(p, refreshing);
|
|
1884
|
-
refreshing = false;
|
|
1885
|
-
const isPromise = source instanceof Promise;
|
|
1886
|
-
const iterator = source[Symbol.asyncIterator];
|
|
1887
|
-
if (!isPromise && !iterator) {
|
|
1888
|
-
return source;
|
|
1889
|
-
}
|
|
1890
|
-
let abort = false;
|
|
1891
|
-
onCleanup(() => abort = true);
|
|
1892
|
-
let transition2 = ActiveTransition;
|
|
1893
|
-
if (isPromise) {
|
|
1894
|
-
source.then(
|
|
1895
|
-
(value3) => {
|
|
1896
|
-
if (abort)
|
|
1897
|
-
return;
|
|
1898
|
-
if (transition2)
|
|
1899
|
-
return transition2.runTransition(() => {
|
|
1900
|
-
node.write(value3, 0, true);
|
|
1901
|
-
}, true);
|
|
1902
|
-
node.write(value3, 0, true);
|
|
1903
|
-
},
|
|
1904
|
-
(error) => {
|
|
1905
|
-
if (abort)
|
|
1906
|
-
return;
|
|
1907
|
-
if (transition2)
|
|
1908
|
-
return transition2.runTransition(() => node._setError(error), true);
|
|
1909
|
-
node._setError(error);
|
|
1910
|
-
}
|
|
1911
|
-
);
|
|
1912
|
-
} else {
|
|
1913
|
-
(async () => {
|
|
1914
|
-
try {
|
|
1915
|
-
for await (let value3 of source) {
|
|
1916
|
-
if (abort)
|
|
1917
|
-
return;
|
|
1918
|
-
if (transition2)
|
|
1919
|
-
return transition2.runTransition(() => {
|
|
1920
|
-
node.write(value3, 0, true);
|
|
1921
|
-
transition2 = null;
|
|
1922
|
-
}, true);
|
|
1923
|
-
node.write(value3, 0, true);
|
|
1924
|
-
}
|
|
1925
|
-
} catch (error) {
|
|
1926
|
-
if (abort)
|
|
1927
|
-
return;
|
|
1928
|
-
if (transition2)
|
|
1929
|
-
return transition2.runTransition(() => {
|
|
1930
|
-
node._setError(error);
|
|
1931
|
-
transition2 = null;
|
|
1932
|
-
}, true);
|
|
1933
|
-
node._setError(error);
|
|
1934
|
-
}
|
|
1935
|
-
})();
|
|
1936
|
-
}
|
|
1937
|
-
throw new NotReadyError();
|
|
1938
|
-
},
|
|
1939
|
-
options
|
|
1940
|
-
);
|
|
1941
|
-
const read = node.wait.bind(node);
|
|
1942
|
-
read.refresh = () => {
|
|
1943
|
-
let n = node;
|
|
1944
|
-
if (ActiveTransition && !node._cloned) {
|
|
1945
|
-
n = cloneGraph(node);
|
|
1946
|
-
}
|
|
1947
|
-
n._state = STATE_DIRTY;
|
|
1948
|
-
refreshing = true;
|
|
1949
|
-
n._updateIfNecessary();
|
|
1950
|
-
};
|
|
1951
|
-
return read;
|
|
1952
|
-
}
|
|
1953
|
-
function createEffect(compute2, effect, value, options) {
|
|
1954
|
-
void new Effect(
|
|
1955
|
-
value,
|
|
1956
|
-
compute2,
|
|
1957
|
-
effect.effect ? effect.effect : effect,
|
|
1958
|
-
effect.error,
|
|
1959
|
-
{ ...options, name: options?.name ?? "effect" }
|
|
1960
|
-
);
|
|
1961
|
-
}
|
|
1962
|
-
function createRenderEffect(compute2, effect, value, options) {
|
|
1963
|
-
void new Effect(value, compute2, effect, void 0, {
|
|
1964
|
-
render: true,
|
|
1965
|
-
...{ ...options, name: options?.name ?? "effect" }
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
function createRoot(init, options) {
|
|
1969
|
-
const owner = new Owner(options?.id);
|
|
1970
|
-
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
1971
|
-
}
|
|
1972
|
-
function runWithOwner(owner, run) {
|
|
1973
|
-
return compute(owner, run, null);
|
|
1974
|
-
}
|
|
1975
|
-
function resolve(fn) {
|
|
1976
|
-
return new Promise((res, rej) => {
|
|
1977
|
-
createRoot((dispose) => {
|
|
1978
|
-
new EagerComputation(void 0, () => {
|
|
1979
|
-
try {
|
|
1980
|
-
res(fn());
|
|
1981
|
-
} catch (err) {
|
|
1982
|
-
if (err instanceof NotReadyError)
|
|
1983
|
-
throw err;
|
|
1984
|
-
rej(err);
|
|
1985
|
-
}
|
|
1986
|
-
dispose();
|
|
1987
|
-
});
|
|
1988
|
-
});
|
|
1989
|
-
});
|
|
1990
|
-
}
|
|
1991
|
-
function createPending() {
|
|
1992
|
-
const node = new Computation(false, null);
|
|
1993
|
-
const reset = () => node.write(false);
|
|
1994
|
-
function write() {
|
|
1995
|
-
if (!ActiveTransition)
|
|
1996
|
-
return false;
|
|
1997
|
-
ActiveTransition.addOptimistic(reset);
|
|
1998
|
-
queueMicrotask(() => reset._transition && node.write(true));
|
|
1999
|
-
}
|
|
2000
|
-
function read() {
|
|
2001
|
-
const v = node.read();
|
|
2002
|
-
return ActiveTransition ? false : v;
|
|
2003
|
-
}
|
|
2004
|
-
return [read, write];
|
|
2005
|
-
}
|
|
2006
|
-
function useTransition() {
|
|
2007
|
-
const [pending, setPending] = createPending();
|
|
2008
|
-
function start(fn) {
|
|
2009
|
-
transition((resume) => {
|
|
2010
|
-
setPending(true);
|
|
2011
|
-
return fn(resume);
|
|
2012
|
-
});
|
|
2013
|
-
}
|
|
2014
|
-
return [pending, start];
|
|
2015
|
-
}
|
|
2016
|
-
function createOptimistic(first, second, options) {
|
|
2017
|
-
let store, setStore;
|
|
2018
|
-
if (typeof first === "function") {
|
|
2019
|
-
[store, setStore] = createStore((s) => {
|
|
2020
|
-
const value = first(s);
|
|
2021
|
-
if (!ActiveTransition)
|
|
2022
|
-
return value;
|
|
2023
|
-
ActiveTransition.addOptimistic(reset);
|
|
2024
|
-
}, {});
|
|
2025
|
-
} else
|
|
2026
|
-
[store, setStore] = createStore(first);
|
|
2027
|
-
const reset = () => setStore(
|
|
2028
|
-
reconcile(
|
|
2029
|
-
typeof first === "function" ? first(second) : first,
|
|
2030
|
-
options?.key || "id",
|
|
2031
|
-
options?.all
|
|
2032
|
-
)
|
|
2033
|
-
);
|
|
2034
|
-
function write(v) {
|
|
2035
|
-
if (!ActiveTransition)
|
|
2036
|
-
throw new Error("createOptimistic can only be updated inside a transition");
|
|
2037
|
-
ActiveTransition.addOptimistic(reset);
|
|
2038
|
-
queueMicrotask(() => reset._transition && setStore(v));
|
|
2039
|
-
}
|
|
2040
|
-
return [store, write];
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
2056
|
// src/map.ts
|
|
2044
2057
|
function mapArray(list, map, options) {
|
|
2045
2058
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
@@ -2282,8 +2295,6 @@ var ConditionalQueue = class extends Queue {
|
|
|
2282
2295
|
return super.run(type);
|
|
2283
2296
|
}
|
|
2284
2297
|
notify(node, type, flags) {
|
|
2285
|
-
if (ActiveTransition && ActiveTransition._clonedQueues.has(this))
|
|
2286
|
-
return ActiveTransition._clonedQueues.get(this).notify(node, type, flags);
|
|
2287
2298
|
if (this._disabled.read()) {
|
|
2288
2299
|
if (type & LOADING_BIT) {
|
|
2289
2300
|
if (flags & LOADING_BIT) {
|
|
@@ -2322,8 +2333,6 @@ var CollectionQueue = class extends Queue {
|
|
|
2322
2333
|
return super.run(type);
|
|
2323
2334
|
}
|
|
2324
2335
|
notify(node, type, flags) {
|
|
2325
|
-
if (ActiveTransition && ActiveTransition._clonedQueues.has(this))
|
|
2326
|
-
return ActiveTransition._clonedQueues.get(this).notify(node, type, flags);
|
|
2327
2336
|
if (!(type & this._collectionType))
|
|
2328
2337
|
return super.notify(node, type, flags);
|
|
2329
2338
|
if (flags & this._collectionType) {
|