valdres 0.2.0-pre.26 → 0.2.0-pre.28
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 +39 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96,6 +96,9 @@ var equal = (a, b, updatedAtomsSet) => {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
+
// src/utils/isAtomFamily.ts
|
|
100
|
+
var isAtomFamily = (state) => state && Object.hasOwn(state, "__valdresAtomFamilyMap");
|
|
101
|
+
|
|
99
102
|
// src/utils/isAtom.ts
|
|
100
103
|
var isAtom = (state) => Object.hasOwn(state, "defaultValue");
|
|
101
104
|
|
|
@@ -156,9 +159,6 @@ ${generateSelectorTrace(this.selectors)}`;
|
|
|
156
159
|
}
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
// src/utils/isAtomFamily.ts
|
|
160
|
-
var isAtomFamily = (state) => state && Object.hasOwn(state, "__valdresAtomFamilyMap");
|
|
161
|
-
|
|
162
162
|
// src/utils/isSelector.ts
|
|
163
163
|
var isSelector = (state) => state && Object.hasOwn(state, "get");
|
|
164
164
|
|
|
@@ -277,6 +277,14 @@ function getState(state, data, initializedAtomsSet, circularDependencySet) {
|
|
|
277
277
|
if (isAtom(state)) {
|
|
278
278
|
if ("parent" in data)
|
|
279
279
|
return getState(state, data.parent, initializedAtomsSet, circularDependencySet);
|
|
280
|
+
if (isFamilyAtom(state)) {
|
|
281
|
+
const familyValue = data.values.get(state.family);
|
|
282
|
+
if (familyValue?.__index) {
|
|
283
|
+
if (isAtomDeletedInFamilyIndex(state, familyValue.__index)) {
|
|
284
|
+
return state.defaultValue;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
280
288
|
initAtom(state, data, initializedAtomsSet);
|
|
281
289
|
initializedAtomsSet.add(state);
|
|
282
290
|
return data.values.get(state);
|
|
@@ -310,6 +318,15 @@ var findClosestStoreWithAtomInitialized = (atom, data) => {
|
|
|
310
318
|
return data;
|
|
311
319
|
return findClosestStoreWithAtomInitialized(atom, data.parent);
|
|
312
320
|
};
|
|
321
|
+
var isAtomDeletedInFamilyIndex = (atom, index) => {
|
|
322
|
+
if (index.deleted.has(atom))
|
|
323
|
+
return true;
|
|
324
|
+
if (index.created.has(atom))
|
|
325
|
+
return false;
|
|
326
|
+
if (index.parentIndex)
|
|
327
|
+
return isAtomDeletedInFamilyIndex(atom, index.parentIndex);
|
|
328
|
+
return false;
|
|
329
|
+
};
|
|
313
330
|
|
|
314
331
|
// src/lib/initSelector.ts
|
|
315
332
|
class SuspendAndWaitForResolveError extends Error {
|
|
@@ -569,6 +586,20 @@ var propagateDeletedAtoms = (atoms, data, subscriptions = new Set, families = ne
|
|
|
569
586
|
}
|
|
570
587
|
}
|
|
571
588
|
propagateDirtySelectors(atoms, selectors, data, subscriptions, families);
|
|
589
|
+
if (families.size > 0 && data.scopes) {
|
|
590
|
+
for (const scopeId in data.scopes) {
|
|
591
|
+
const scope = data.scopes[scopeId];
|
|
592
|
+
const familiesInScope = [];
|
|
593
|
+
for (const family of families.keys()) {
|
|
594
|
+
if (scope.values.has(family)) {
|
|
595
|
+
familiesInScope.push(family);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (familiesInScope.length > 0) {
|
|
599
|
+
propagateUpdatedAtoms(familiesInScope, scope, undefined, undefined, false, timestamp, true);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
572
603
|
};
|
|
573
604
|
var propagateUpdatedAtoms = (atoms, data, subscriptions = new Set, families = new Map, isRecursive = false, timestamp = performance.now(), selectorsOnly = false) => {
|
|
574
605
|
const selectors = new Set;
|
|
@@ -602,6 +633,8 @@ var propagateUpdatedAtoms = (atoms, data, subscriptions = new Set, families = ne
|
|
|
602
633
|
for (const atom of atoms) {
|
|
603
634
|
if (!scope.values.has(atom)) {
|
|
604
635
|
atomsToUpdateInScope.push(atom);
|
|
636
|
+
} else if (isAtomFamily(atom)) {
|
|
637
|
+
atomsToUpdateInScope.push(atom);
|
|
605
638
|
}
|
|
606
639
|
}
|
|
607
640
|
if (atomsToUpdateInScope.length > 0) {
|
|
@@ -1025,6 +1058,7 @@ class Transaction {
|
|
|
1025
1058
|
setAtoms(this.atomMap, this.data, initializedAtomsSet);
|
|
1026
1059
|
if (this.deleteSet?.size) {
|
|
1027
1060
|
deleteAtomFamilyAtoms(this.deleteSet, this.data);
|
|
1061
|
+
propagateDeletedAtoms([...this.deleteSet], this.data);
|
|
1028
1062
|
}
|
|
1029
1063
|
if (this._scopedTransactions) {
|
|
1030
1064
|
for (const [, scopedTxn] of this._scopedTransactions) {
|
|
@@ -1518,9 +1552,9 @@ var isFamilySelector = (state) => isFamilyState(state) && isSelector(state);
|
|
|
1518
1552
|
|
|
1519
1553
|
// src/index.ts
|
|
1520
1554
|
if (globalThis.__valdres__) {
|
|
1521
|
-
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${"0.2.0-pre.
|
|
1555
|
+
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${"0.2.0-pre.28"}`);
|
|
1522
1556
|
} else {
|
|
1523
|
-
globalThis.__valdres__ = "0.2.0-pre.
|
|
1557
|
+
globalThis.__valdres__ = "0.2.0-pre.28";
|
|
1524
1558
|
}
|
|
1525
1559
|
export {
|
|
1526
1560
|
store,
|