valdres 0.2.0-alpha.47 → 0.2.0-alpha.48

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,6 +566,13 @@ var recursivlyResetTxnSelectorCache = (state, txnSubscribers, txnSelectorCache)
566
566
  }
567
567
  }
568
568
  };
569
+ var captureScopedTransaction = (scopedData) => {
570
+ let txn;
571
+ transaction((scopedTxn) => {
572
+ txn = scopedTxn;
573
+ }, scopedData, false);
574
+ return txn;
575
+ };
569
576
  var transaction = (callback, data, autoCommit = true) => {
570
577
  let txnAtomMap = new Map;
571
578
  let txnSelectorCache = new Map;
@@ -624,7 +631,7 @@ var transaction = (callback, data, autoCommit = true) => {
624
631
  dirtySelectors.clear();
625
632
  if (scopedTransactions) {
626
633
  for (const scopedTxn of Object.values(scopedTransactions)) {
627
- scopedTxn[3]();
634
+ scopedTxn.commit();
628
635
  }
629
636
  }
630
637
  };
@@ -636,19 +643,13 @@ var transaction = (callback, data, autoCommit = true) => {
636
643
  scope: (scopeId, callback2) => {
637
644
  if (scopeId in data.scopes) {
638
645
  const scopedData = data.scopes[scopeId];
639
- if (scopedTransactions?.[scopeId] === undefined) {
640
- scopedTransactions ||= {};
641
- transaction(({ set, get, reset, commit: commit2, scope }) => {
642
- scopedTransactions[scopeId] = [
643
- set,
644
- get,
645
- reset,
646
- commit2,
647
- scope
648
- ];
649
- }, scopedData, false);
646
+ if (scopedTransactions === undefined) {
647
+ scopedTransactions = {};
648
+ }
649
+ if (scopedTransactions[scopeId] === undefined) {
650
+ scopedTransactions[scopeId] = captureScopedTransaction(scopedData);
650
651
  }
651
- callback2(...scopedTransactions[scopeId]);
652
+ return callback2(scopedTransactions[scopeId]);
652
653
  } else {
653
654
  throw new Error(`Scope '${scopeId}' not found. Registered scopes: ${Object.keys(data.scopes).join(", ")}`);
654
655
  }
@@ -727,7 +728,7 @@ var store = (id) => {
727
728
  return storeFromStoreData(data);
728
729
  };
729
730
  // package.json
730
- var version = "0.2.0-alpha.46";
731
+ var version = "0.2.0-alpha.47";
731
732
 
732
733
  // src/globalStore.ts
733
734
  if (globalThis.__valdres__) {
@@ -1,3 +1,3 @@
1
1
  import type { StoreData } from "../types/StoreData";
2
2
  import type { TransactionFn } from "../types/TransactionFn";
3
- export declare const transaction: (callback: TransactionFn, data: StoreData, autoCommit?: boolean) => void;
3
+ export declare const transaction: (callback: TransactionFn, data: StoreData, autoCommit?: boolean) => any;
@@ -1,2 +1,2 @@
1
1
  import type { TransactionInterface } from "./TransactionInterface";
2
- export type TransactionFn = (args: TransactionInterface) => void;
2
+ export type TransactionFn = (args: TransactionInterface) => any;
@@ -7,5 +7,5 @@ export type TransactionInterface = {
7
7
  get: GetValue;
8
8
  reset: ResetAtom;
9
9
  commit: () => void;
10
- scope: (scopeId: string, callback: TransactionFn) => void;
10
+ scope: <Callback extends TransactionFn>(scopeId: string, callback: Callback) => ReturnType<Callback>;
11
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.2.0-alpha.47",
3
+ "version": "0.2.0-alpha.48",
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": "c26d007ebb65bdcfb7fd81122cc51b4bcc8f4d22"
39
+ "gitHead": "65baebd620f63795b27466864bf54a249323bd57"
40
40
  }