valdres 1.0.0-beta.1 → 1.0.0-beta.2
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.js +81 -80
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -417,96 +417,97 @@ var evaluateSelector = (selector, data, initializedAtomsSet, circularDependencyS
|
|
|
417
417
|
throw new SelectorCircularDependencyError;
|
|
418
418
|
}
|
|
419
419
|
circularDependencySet.add(selector);
|
|
420
|
-
const prev = data.abortControllers.get(selector);
|
|
421
|
-
let options;
|
|
422
|
-
if (prev === false) {
|
|
423
|
-
let cached = syncOptionsCache.get(data);
|
|
424
|
-
if (!cached) {
|
|
425
|
-
cached = { signal: neverAbortedSignal, storeId: data.id };
|
|
426
|
-
syncOptionsCache.set(data, cached);
|
|
427
|
-
}
|
|
428
|
-
options = cached;
|
|
429
|
-
} else {
|
|
430
|
-
if (prev)
|
|
431
|
-
prev.abort();
|
|
432
|
-
const abortController = new AbortController;
|
|
433
|
-
data.abortControllers.set(selector, abortController);
|
|
434
|
-
options = { signal: abortController.signal, storeId: data.id };
|
|
435
|
-
}
|
|
436
|
-
let allDepsThisEval;
|
|
437
|
-
let result;
|
|
438
420
|
try {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
421
|
+
const prev = data.abortControllers.get(selector);
|
|
422
|
+
let options;
|
|
423
|
+
if (prev === false) {
|
|
424
|
+
let cached = syncOptionsCache.get(data);
|
|
425
|
+
if (!cached) {
|
|
426
|
+
cached = { signal: neverAbortedSignal, storeId: data.id };
|
|
427
|
+
syncOptionsCache.set(data, cached);
|
|
428
|
+
}
|
|
429
|
+
options = cached;
|
|
430
|
+
} else {
|
|
431
|
+
if (prev)
|
|
432
|
+
prev.abort();
|
|
433
|
+
const abortController = new AbortController;
|
|
434
|
+
data.abortControllers.set(selector, abortController);
|
|
435
|
+
options = { signal: abortController.signal, storeId: data.id };
|
|
436
|
+
}
|
|
437
|
+
let allDepsThisEval;
|
|
438
|
+
let result;
|
|
439
|
+
try {
|
|
440
|
+
result = selector.get((state) => {
|
|
441
|
+
if (evaluationComplete) {
|
|
442
|
+
if (!evalCtx.revoked && allDepsThisEval) {
|
|
443
|
+
allDepsThisEval.add(state);
|
|
444
|
+
}
|
|
445
|
+
if (evalCtx.revoked) {
|
|
446
|
+
return getState(state, data, new Set);
|
|
447
|
+
}
|
|
448
|
+
return lateGet(state, selector, data);
|
|
443
449
|
}
|
|
444
|
-
|
|
445
|
-
|
|
450
|
+
const value = getState(state, data, initializedAtomsSet, circularDependencySet);
|
|
451
|
+
updatedDepsArray.push(state);
|
|
452
|
+
if (!depsChanged && (!currentDependencies || !currentDependencies.has(state))) {
|
|
453
|
+
depsChanged = true;
|
|
446
454
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
455
|
+
if (isPromiseLike(value))
|
|
456
|
+
throw new SuspendAndWaitForResolveError(value);
|
|
457
|
+
return value;
|
|
458
|
+
}, options);
|
|
459
|
+
} catch (error) {
|
|
460
|
+
if (error instanceof NeedsInitError)
|
|
461
|
+
throw error;
|
|
462
|
+
if (error instanceof SuspendAndWaitForResolveError) {
|
|
463
|
+
result = error;
|
|
464
|
+
} else if (error instanceof SelectorEvaluationError) {
|
|
465
|
+
throw error;
|
|
466
|
+
} else {
|
|
467
|
+
throw new SelectorEvaluationError(error);
|
|
453
468
|
}
|
|
454
|
-
if (isPromiseLike(value))
|
|
455
|
-
throw new SuspendAndWaitForResolveError(value);
|
|
456
|
-
return value;
|
|
457
|
-
}, options);
|
|
458
|
-
} catch (error) {
|
|
459
|
-
if (error instanceof NeedsInitError) {
|
|
460
|
-
circularDependencySet.delete(selector);
|
|
461
|
-
throw error;
|
|
462
|
-
}
|
|
463
|
-
if (error instanceof SuspendAndWaitForResolveError) {
|
|
464
|
-
result = error;
|
|
465
|
-
} else if (error instanceof SelectorEvaluationError) {
|
|
466
|
-
throw error;
|
|
467
|
-
} else {
|
|
468
|
-
throw new SelectorEvaluationError(error);
|
|
469
469
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
depsChanged = true;
|
|
475
|
-
}
|
|
476
|
-
if (depsChanged || !currentDependencies) {
|
|
477
|
-
const updatedDependencies = new Set(updatedDepsArray);
|
|
478
|
-
if (isAsyncResult && currentDependencies) {
|
|
479
|
-
for (const dep of currentDependencies) {
|
|
480
|
-
updatedDependencies.add(dep);
|
|
481
|
-
}
|
|
470
|
+
evaluationComplete = true;
|
|
471
|
+
const isAsyncResult = result instanceof SuspendAndWaitForResolveError || isPromiseLike(result);
|
|
472
|
+
if (!isAsyncResult && !depsChanged && currentDependencies && currentDependencies.size !== updatedDepsArray.length) {
|
|
473
|
+
depsChanged = true;
|
|
482
474
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
if (
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
addedDepsOut.add(state);
|
|
475
|
+
if (depsChanged || !currentDependencies) {
|
|
476
|
+
const updatedDependencies = new Set(updatedDepsArray);
|
|
477
|
+
if (isAsyncResult && currentDependencies) {
|
|
478
|
+
for (const dep of currentDependencies) {
|
|
479
|
+
updatedDependencies.add(dep);
|
|
480
|
+
}
|
|
490
481
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (!updatedDependencies.has(state)) {
|
|
482
|
+
const prev2 = currentDependencies ?? new Set;
|
|
483
|
+
for (const state of updatedDependencies) {
|
|
484
|
+
if (!prev2.has(state)) {
|
|
495
485
|
const set = getOrInitDependentsSet(state, data);
|
|
496
|
-
set.
|
|
497
|
-
if (
|
|
498
|
-
|
|
486
|
+
set.add(selector);
|
|
487
|
+
if (addedDepsOut)
|
|
488
|
+
addedDepsOut.add(state);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (!isAsyncResult) {
|
|
492
|
+
for (const state of prev2) {
|
|
493
|
+
if (!updatedDependencies.has(state)) {
|
|
494
|
+
const set = getOrInitDependentsSet(state, data);
|
|
495
|
+
set.delete(selector);
|
|
496
|
+
if (removedDepsOut)
|
|
497
|
+
removedDepsOut.add(state);
|
|
498
|
+
}
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
|
+
data.stateDependencies.set(selector, updatedDependencies);
|
|
501
502
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
503
|
+
if (isPromiseLike(result)) {
|
|
504
|
+
allDepsThisEval = new Set(updatedDepsArray);
|
|
505
|
+
pendingAsyncDeps.set(result, allDepsThisEval);
|
|
506
|
+
}
|
|
507
|
+
return result;
|
|
508
|
+
} finally {
|
|
509
|
+
circularDependencySet.delete(selector);
|
|
507
510
|
}
|
|
508
|
-
circularDependencySet.delete(selector);
|
|
509
|
-
return result;
|
|
510
511
|
};
|
|
511
512
|
var handleSelectorResult = (value, selector, data) => {
|
|
512
513
|
if (value instanceof SuspendAndWaitForResolveError) {
|
|
@@ -2402,9 +2403,9 @@ var isFamilySelector = (state) => isFamilyState(state) && isSelector(state);
|
|
|
2402
2403
|
|
|
2403
2404
|
// src/index.ts
|
|
2404
2405
|
if (globalThis.__valdres__) {
|
|
2405
|
-
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${"1.0.0-beta.
|
|
2406
|
+
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${"1.0.0-beta.2"}`);
|
|
2406
2407
|
} else {
|
|
2407
|
-
globalThis.__valdres__ = "1.0.0-beta.
|
|
2408
|
+
globalThis.__valdres__ = "1.0.0-beta.2";
|
|
2408
2409
|
}
|
|
2409
2410
|
export {
|
|
2410
2411
|
store,
|