valdres 0.2.0-alpha.60 → 0.2.0-alpha.61

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
@@ -614,26 +614,35 @@ var recursivlyResetTxnSelectorCache = (state, txnSubscribers, txnSelectorCache)
614
614
  }
615
615
  }
616
616
  };
617
- var captureScopedTransaction = (scopedData, parentGet) => {
617
+ var captureScopedTransaction = (scopedData, parentGetFromTxnOrData) => {
618
618
  let txn;
619
619
  transaction((scopedTxn) => {
620
620
  txn = scopedTxn;
621
- }, scopedData, false, parentGet);
621
+ }, scopedData, false, parentGetFromTxnOrData);
622
622
  return txn;
623
623
  };
624
- var transaction = (callback, data, autoCommit = true, parentScopeGet) => {
624
+ var transaction = (callback, data, autoCommit = true, parentGetFromTxnOrData) => {
625
625
  const txnAtomMap = new Map;
626
626
  const txnSelectorCache = new Map;
627
627
  const txnSubscribers = new Map;
628
628
  const dirtySelectors = new Set;
629
629
  let scopedTransactions;
630
+ const getFromTxnOrData = (state) => {
631
+ if (txnAtomMap.has(state)) {
632
+ return txnAtomMap.get(state);
633
+ }
634
+ if (data.values.has(state)) {
635
+ return data.values.get(state);
636
+ }
637
+ if (parentGetFromTxnOrData) {
638
+ return parentGetFromTxnOrData(state);
639
+ }
640
+ };
630
641
  const txnGet = (state) => {
631
642
  if (isAtom(state)) {
632
- if (txnAtomMap.has(state)) {
633
- return txnAtomMap.get(state);
634
- } else if (parentScopeGet) {
635
- return parentScopeGet(state);
636
- }
643
+ const value = getFromTxnOrData(state);
644
+ if (value)
645
+ return value;
637
646
  return getState(state, data);
638
647
  } else if (isSelector(state)) {
639
648
  if (txnSelectorCache.has(state)) {
@@ -709,7 +718,7 @@ var transaction = (callback, data, autoCommit = true, parentScopeGet) => {
709
718
  scopedTransactions = {};
710
719
  }
711
720
  if (scopedTransactions[scopeId] === undefined) {
712
- scopedTransactions[scopeId] = captureScopedTransaction(scopedData, txnGet);
721
+ scopedTransactions[scopeId] = captureScopedTransaction(scopedData, getFromTxnOrData);
713
722
  }
714
723
  return callback2(scopedTransactions[scopeId]);
715
724
  } else {
@@ -1,4 +1,8 @@
1
- import type { GetValue } from "../types/GetValue";
1
+ import type { Atom } from "../types/Atom";
2
2
  import type { StoreData } from "../types/StoreData";
3
3
  import type { TransactionFn } from "../types/TransactionFn";
4
- export declare const transaction: (callback: TransactionFn, data: StoreData, autoCommit?: boolean, parentScopeGet?: GetValue) => any;
4
+ type GetAtomValue = {
5
+ <V>(atom: Atom<V>): V;
6
+ };
7
+ export declare const transaction: (callback: TransactionFn, data: StoreData, autoCommit?: boolean, parentGetFromTxnOrData?: GetAtomValue) => any;
8
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.2.0-alpha.60",
3
+ "version": "0.2.0-alpha.61",
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": "68285bc25279979283ccf0e75e91248a15445dca"
39
+ "gitHead": "083c7d5aa913e9a641d1456e82276c20d8162f0e"
40
40
  }