valdres 0.2.0-alpha.59 → 0.2.0-alpha.60
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 +24 -11
- package/dist/types/src/lib/transaction.d.ts +2 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -614,22 +614,27 @@ var recursivlyResetTxnSelectorCache = (state, txnSubscribers, txnSelectorCache)
|
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
616
|
};
|
|
617
|
-
var captureScopedTransaction = (scopedData) => {
|
|
617
|
+
var captureScopedTransaction = (scopedData, parentGet) => {
|
|
618
618
|
let txn;
|
|
619
619
|
transaction((scopedTxn) => {
|
|
620
620
|
txn = scopedTxn;
|
|
621
|
-
}, scopedData, false);
|
|
621
|
+
}, scopedData, false, parentGet);
|
|
622
622
|
return txn;
|
|
623
623
|
};
|
|
624
|
-
var transaction = (callback, data, autoCommit = true) => {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
624
|
+
var transaction = (callback, data, autoCommit = true, parentScopeGet) => {
|
|
625
|
+
const txnAtomMap = new Map;
|
|
626
|
+
const txnSelectorCache = new Map;
|
|
627
|
+
const txnSubscribers = new Map;
|
|
628
|
+
const dirtySelectors = new Set;
|
|
629
629
|
let scopedTransactions;
|
|
630
630
|
const txnGet = (state) => {
|
|
631
631
|
if (isAtom(state)) {
|
|
632
|
-
|
|
632
|
+
if (txnAtomMap.has(state)) {
|
|
633
|
+
return txnAtomMap.get(state);
|
|
634
|
+
} else if (parentScopeGet) {
|
|
635
|
+
return parentScopeGet(state);
|
|
636
|
+
}
|
|
637
|
+
return getState(state, data);
|
|
633
638
|
} else if (isSelector(state)) {
|
|
634
639
|
if (txnSelectorCache.has(state)) {
|
|
635
640
|
return txnSelectorCache.get(state);
|
|
@@ -647,8 +652,8 @@ var transaction = (callback, data, autoCommit = true) => {
|
|
|
647
652
|
}
|
|
648
653
|
txnSelectorCache.set(state, res);
|
|
649
654
|
return res;
|
|
650
|
-
} else if (
|
|
651
|
-
return
|
|
655
|
+
} else if (isAtomFamily(state)) {
|
|
656
|
+
return txnGet(state.__keysSelector);
|
|
652
657
|
} else {
|
|
653
658
|
throw new Error("Unsupported state");
|
|
654
659
|
}
|
|
@@ -668,6 +673,14 @@ var transaction = (callback, data, autoCommit = true) => {
|
|
|
668
673
|
recursivlyResetTxnSelectorCache(atom, txnSubscribers, txnSelectorCache);
|
|
669
674
|
}
|
|
670
675
|
txnAtomMap.set(atom, value);
|
|
676
|
+
if (isFamilyAtom(atom)) {
|
|
677
|
+
const currentKeySet = txnGet(atom.family.__keysAtom);
|
|
678
|
+
if (!currentKeySet.has(atom.familyKey)) {
|
|
679
|
+
const newSet = new Set(currentKeySet);
|
|
680
|
+
newSet.add(atom.familyKey);
|
|
681
|
+
txnSet(atom.family.__keysAtom, newSet);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
671
684
|
return value;
|
|
672
685
|
};
|
|
673
686
|
const txnReset = (atom) => {
|
|
@@ -696,7 +709,7 @@ var transaction = (callback, data, autoCommit = true) => {
|
|
|
696
709
|
scopedTransactions = {};
|
|
697
710
|
}
|
|
698
711
|
if (scopedTransactions[scopeId] === undefined) {
|
|
699
|
-
scopedTransactions[scopeId] = captureScopedTransaction(scopedData);
|
|
712
|
+
scopedTransactions[scopeId] = captureScopedTransaction(scopedData, txnGet);
|
|
700
713
|
}
|
|
701
714
|
return callback2(scopedTransactions[scopeId]);
|
|
702
715
|
} else {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GetValue } from "../types/GetValue";
|
|
1
2
|
import type { StoreData } from "../types/StoreData";
|
|
2
3
|
import type { TransactionFn } from "../types/TransactionFn";
|
|
3
|
-
export declare const transaction: (callback: TransactionFn, data: StoreData, autoCommit?: boolean) => any;
|
|
4
|
+
export declare const transaction: (callback: TransactionFn, data: StoreData, autoCommit?: boolean, parentScopeGet?: GetValue) => any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valdres",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.60",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Eigil Sagafos"
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"access": "public",
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "68285bc25279979283ccf0e75e91248a15445dca"
|
|
40
40
|
}
|