valdres 0.2.0-alpha.44 → 0.2.0-alpha.45
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
|
@@ -566,11 +566,12 @@ var recursivlyResetTxnSelectorCache = (state, txnSubscribers, txnSelectorCache)
|
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
};
|
|
569
|
-
var transaction = (callback, data) => {
|
|
569
|
+
var transaction = (callback, data, autoCommit = true) => {
|
|
570
570
|
let txnAtomMap = new Map;
|
|
571
571
|
let txnSelectorCache = new Map;
|
|
572
572
|
let txnSubscribers = new Map;
|
|
573
573
|
let dirtySelectors = new Set;
|
|
574
|
+
let scopedTransactions;
|
|
574
575
|
const txnGet = (state) => {
|
|
575
576
|
if (isAtom(state)) {
|
|
576
577
|
return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState(state, data);
|
|
@@ -621,9 +622,34 @@ var transaction = (callback, data) => {
|
|
|
621
622
|
const commit = () => {
|
|
622
623
|
setAtoms(txnAtomMap, data);
|
|
623
624
|
dirtySelectors.clear();
|
|
625
|
+
if (scopedTransactions) {
|
|
626
|
+
for (const scopedTxn of Object.values(scopedTransactions)) {
|
|
627
|
+
scopedTxn[3]();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
624
630
|
};
|
|
625
|
-
const result = callback(txnSet, txnGet, txnReset, commit)
|
|
626
|
-
|
|
631
|
+
const result = callback(txnSet, txnGet, txnReset, commit, (scopeId, callback2) => {
|
|
632
|
+
if (scopeId in data.scopes) {
|
|
633
|
+
const scopedData = data.scopes[scopeId];
|
|
634
|
+
if (scopedTransactions?.[scopeId] === undefined) {
|
|
635
|
+
scopedTransactions ||= {};
|
|
636
|
+
transaction((set, get, reset, commit2, scope) => {
|
|
637
|
+
scopedTransactions[scopeId] = [
|
|
638
|
+
set,
|
|
639
|
+
get,
|
|
640
|
+
reset,
|
|
641
|
+
commit2,
|
|
642
|
+
scope
|
|
643
|
+
];
|
|
644
|
+
}, scopedData, false);
|
|
645
|
+
}
|
|
646
|
+
callback2(...scopedTransactions[scopeId]);
|
|
647
|
+
} else {
|
|
648
|
+
throw new Error("Scope not found");
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
if (autoCommit)
|
|
652
|
+
commit();
|
|
627
653
|
return result;
|
|
628
654
|
};
|
|
629
655
|
|
|
@@ -695,7 +721,7 @@ var store = (id) => {
|
|
|
695
721
|
return storeFromStoreData(data);
|
|
696
722
|
};
|
|
697
723
|
// package.json
|
|
698
|
-
var version = "0.2.0-alpha.
|
|
724
|
+
var version = "0.2.0-alpha.44";
|
|
699
725
|
|
|
700
726
|
// src/globalStore.ts
|
|
701
727
|
if (globalThis.__valdres__) {
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import type { State } from "../types/State";
|
|
2
1
|
import type { StoreData } from "../types/StoreData";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
type SetValdresValue = <V>(state: State<V>, value: V) => void;
|
|
6
|
-
type ResetValdresValue = <V>(atom: Atom<V>) => V;
|
|
7
|
-
type TransactionInterface = (set: SetValdresValue, get: GetValdresValue, reset: ResetValdresValue, commit: () => void) => void;
|
|
8
|
-
export declare const transaction: (callback: TransactionInterface, data: StoreData) => void;
|
|
9
|
-
export {};
|
|
2
|
+
import type { TransactionFn } from "../types/TransactionFn";
|
|
3
|
+
export declare const transaction: (callback: TransactionFn, data: StoreData, autoCommit?: boolean) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { GetValue } from "./GetValue";
|
|
2
2
|
import type { ResetAtom } from "./ResetAtom";
|
|
3
3
|
import type { SetAtom } from "./SetAtom";
|
|
4
|
-
export type TransactionFn = (set: SetAtom, get: GetValue, reset: ResetAtom, commit: () => void) => void;
|
|
4
|
+
export type TransactionFn = (set: SetAtom, get: GetValue, reset: ResetAtom, commit: () => void, scope: (scopeId: string, callback: TransactionFn) => void) => void;
|
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.45",
|
|
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": "8d9c1d1c9108b11ae9201a2bcd139f384d3884c5"
|
|
40
40
|
}
|