valdres 0.2.0-pre.20 → 0.2.0-pre.21
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
CHANGED
|
@@ -144,6 +144,18 @@ ${generateSelectorTrace(this.selectors)}`;
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
// src/errors/SelectorCircularDependencyError.ts
|
|
148
|
+
class SelectorCircularDependencyError extends SelectorEvaluationError {
|
|
149
|
+
constructor() {
|
|
150
|
+
super();
|
|
151
|
+
}
|
|
152
|
+
get message() {
|
|
153
|
+
const firstSelectorName = this.selectors[0].name ?? "Anonymous Selector";
|
|
154
|
+
return `Circular dependency detected in '${firstSelectorName}'
|
|
155
|
+
${generateSelectorTrace(this.selectors)}`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
147
159
|
// src/utils/isAtomFamily.ts
|
|
148
160
|
var isAtomFamily = (state) => state && Object.hasOwn(state, "__valdresAtomFamilyMap");
|
|
149
161
|
|
|
@@ -317,7 +329,9 @@ var getOrInitDependentsSet = (state, data) => {
|
|
|
317
329
|
};
|
|
318
330
|
var evaluateSelector = (selector, data, initializedAtomsSet, circularDependencySet = new WeakSet) => {
|
|
319
331
|
const updatedDependencies = new Set;
|
|
320
|
-
if (circularDependencySet.has(selector)) {
|
|
332
|
+
if (circularDependencySet.has(selector)) {
|
|
333
|
+
throw new SelectorCircularDependencyError;
|
|
334
|
+
}
|
|
321
335
|
circularDependencySet.add(selector);
|
|
322
336
|
let result;
|
|
323
337
|
try {
|
|
@@ -349,6 +363,7 @@ var evaluateSelector = (selector, data, initializedAtomsSet, circularDependencyS
|
|
|
349
363
|
set.delete(selector);
|
|
350
364
|
}
|
|
351
365
|
data.stateDependencies.set(selector, updatedDependencies);
|
|
366
|
+
circularDependencySet.delete(selector);
|
|
352
367
|
return result;
|
|
353
368
|
};
|
|
354
369
|
var handleSelectorResult = (value, selector, data) => {
|
|
@@ -555,16 +570,18 @@ var propagateDeletedAtoms = (atoms, data, subscriptions = new Set, families = ne
|
|
|
555
570
|
}
|
|
556
571
|
propagateDirtySelectors(atoms, selectors, data, subscriptions, families);
|
|
557
572
|
};
|
|
558
|
-
var propagateUpdatedAtoms = (atoms, data, subscriptions = new Set, families = new Map, isRecursive = false, timestamp = performance.now()) => {
|
|
573
|
+
var propagateUpdatedAtoms = (atoms, data, subscriptions = new Set, families = new Map, isRecursive = false, timestamp = performance.now(), selectorsOnly = false) => {
|
|
559
574
|
const selectors = new Set;
|
|
560
575
|
for (const atom of atoms) {
|
|
561
576
|
addSetToSet(data.stateDependents.get(atom), selectors);
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
if (
|
|
565
|
-
families.
|
|
577
|
+
if (!selectorsOnly) {
|
|
578
|
+
addSetToSet(data.subscriptions.get(atom), subscriptions);
|
|
579
|
+
if (isFamilyAtom(atom)) {
|
|
580
|
+
if (!families.has(atom.family)) {
|
|
581
|
+
families.set(atom.family, new Set);
|
|
582
|
+
}
|
|
583
|
+
families.get(atom.family).add(atom);
|
|
566
584
|
}
|
|
567
|
-
families.get(atom.family).add(atom);
|
|
568
585
|
}
|
|
569
586
|
}
|
|
570
587
|
if (families.size > 0) {
|
|
@@ -578,6 +595,20 @@ var propagateUpdatedAtoms = (atoms, data, subscriptions = new Set, families = ne
|
|
|
578
595
|
}
|
|
579
596
|
if (!isRecursive) {
|
|
580
597
|
propagateDirtySelectors(atoms, selectors, data, subscriptions, families);
|
|
598
|
+
if (data.scopes) {
|
|
599
|
+
for (const scopeId in data.scopes) {
|
|
600
|
+
const scope = data.scopes[scopeId];
|
|
601
|
+
const atomsToUpdateInScope = [];
|
|
602
|
+
for (const atom of atoms) {
|
|
603
|
+
if (!scope.values.has(atom)) {
|
|
604
|
+
atomsToUpdateInScope.push(atom);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (atomsToUpdateInScope.length > 0) {
|
|
608
|
+
propagateUpdatedAtoms(atomsToUpdateInScope, scope, undefined, undefined, false, timestamp, true);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
581
612
|
}
|
|
582
613
|
};
|
|
583
614
|
var propagateDirtySelectors = (updatedAtoms, selectors, data, subscriptions, families) => {
|
|
@@ -1472,9 +1503,9 @@ var isFamilySelector = (state) => isFamilyState(state) && isSelector(state);
|
|
|
1472
1503
|
|
|
1473
1504
|
// src/index.ts
|
|
1474
1505
|
if (globalThis.__valdres__) {
|
|
1475
|
-
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${"0.2.0-pre.
|
|
1506
|
+
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${"0.2.0-pre.21"}`);
|
|
1476
1507
|
} else {
|
|
1477
|
-
globalThis.__valdres__ = "0.2.0-pre.
|
|
1508
|
+
globalThis.__valdres__ = "0.2.0-pre.21";
|
|
1478
1509
|
}
|
|
1479
1510
|
export {
|
|
1480
1511
|
store,
|
|
@@ -20,6 +20,6 @@ export declare const createAtomFamilyIndex: (parentIndex?: AtomFamilyIndex) => A
|
|
|
20
20
|
export declare const deleteFamilyAtomsFromSet: (family: Family<any>, familyAtoms: Set<AtomFamilyAtom<any>>, data: StoreData, timestamp: number) => void;
|
|
21
21
|
export declare const addFamilyAtomsToSet: (family: Family<any>, familyAtoms: Set<AtomFamilyAtom<any>>, data: StoreData, timestamp: Number) => void;
|
|
22
22
|
export declare const propagateDeletedAtoms: (atoms: AtomFamilyAtom<any, any>[], data: StoreData, subscriptions?: Set<Subscription>, families?: Map<AtomFamily<any>, Set<AtomFamilyAtom<any>>>, timestamp?: number) => void;
|
|
23
|
-
export declare const propagateUpdatedAtoms: (atoms: (Atom<any> | AtomFamilyAtom<any, any> | AtomFamily<any, any>)[], data: StoreData, subscriptions?: Set<Subscription>, families?: Map<AtomFamily<any>, Set<AtomFamilyAtom<any>>>, isRecursive?: boolean, timestamp?: number) => void;
|
|
23
|
+
export declare const propagateUpdatedAtoms: (atoms: (Atom<any> | AtomFamilyAtom<any, any> | AtomFamily<any, any>)[], data: StoreData, subscriptions?: Set<Subscription>, families?: Map<AtomFamily<any>, Set<AtomFamilyAtom<any>>>, isRecursive?: boolean, timestamp?: number, selectorsOnly?: boolean) => void;
|
|
24
24
|
export declare const propagateDirtySelectors: (updatedAtoms: Atom[], selectors: Set<Selector>, data: StoreData, subscriptions: Set<Subscription>, families: Map<AtomFamily<any>, Set<AtomFamilyAtom<any>>>) => void;
|
|
25
25
|
export {};
|