atom.io 0.12.0 → 0.13.0

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.
Files changed (81) hide show
  1. package/dist/index.cjs.map +1 -1
  2. package/dist/index.d.cts +6 -3
  3. package/dist/index.d.ts +6 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/metafile-cjs.json +1 -1
  6. package/dist/metafile-esm.json +1 -1
  7. package/internal/dist/index.cjs +1579 -1498
  8. package/internal/dist/index.cjs.map +1 -1
  9. package/internal/dist/index.d.cts +34 -14
  10. package/internal/dist/index.d.ts +34 -14
  11. package/internal/dist/index.js +1577 -1499
  12. package/internal/dist/index.js.map +1 -1
  13. package/internal/dist/metafile-cjs.json +1 -1
  14. package/internal/dist/metafile-esm.json +1 -1
  15. package/internal/src/atom/create-atom.ts +4 -4
  16. package/internal/src/atom/delete-atom.ts +11 -11
  17. package/internal/src/atom/is-default.ts +5 -5
  18. package/internal/src/caching.ts +12 -10
  19. package/internal/src/families/create-atom-family.ts +3 -3
  20. package/internal/src/families/create-readonly-selector-family.ts +3 -3
  21. package/internal/src/families/create-selector-family.ts +4 -4
  22. package/internal/src/index.ts +4 -2
  23. package/internal/src/keys.ts +4 -4
  24. package/internal/src/lazy-map.ts +37 -0
  25. package/internal/src/lineage.ts +18 -0
  26. package/internal/src/mutable/create-mutable-atom.ts +5 -4
  27. package/internal/src/mutable/get-json-family.ts +3 -3
  28. package/internal/src/mutable/tracker.ts +13 -10
  29. package/internal/src/operation.ts +19 -19
  30. package/internal/src/selector/create-read-write-selector.ts +5 -4
  31. package/internal/src/selector/create-readonly-selector.ts +4 -3
  32. package/internal/src/selector/create-selector.ts +6 -6
  33. package/internal/src/selector/delete-selector.ts +10 -10
  34. package/internal/src/selector/get-selector-dependency-keys.ts +2 -2
  35. package/internal/src/selector/register-selector.ts +4 -4
  36. package/internal/src/selector/update-selector-atoms.ts +2 -2
  37. package/internal/src/set-state/copy-mutable-if-needed.ts +4 -3
  38. package/internal/src/set-state/copy-mutable-in-transaction.ts +10 -16
  39. package/internal/src/set-state/copy-mutable-into-new-store.ts +1 -1
  40. package/internal/src/set-state/evict-downstream.ts +5 -5
  41. package/internal/src/set-state/set-atom.ts +6 -1
  42. package/internal/src/set-state/stow-update.ts +7 -2
  43. package/internal/src/store/store.ts +31 -24
  44. package/internal/src/store/withdraw-new-family-member.ts +3 -4
  45. package/internal/src/store/withdraw.ts +58 -59
  46. package/internal/src/subject.ts +14 -0
  47. package/internal/src/subscribe/recall-state.ts +5 -5
  48. package/internal/src/timeline/add-atom-to-timeline.ts +37 -27
  49. package/internal/src/timeline/create-timeline.ts +6 -8
  50. package/internal/src/timeline/time-travel.ts +22 -4
  51. package/internal/src/transaction/abort-transaction.ts +5 -3
  52. package/internal/src/transaction/apply-transaction.ts +80 -58
  53. package/internal/src/transaction/build-transaction.ts +34 -23
  54. package/internal/src/transaction/create-transaction.ts +6 -9
  55. package/internal/src/transaction/index.ts +2 -10
  56. package/internal/src/transaction/redo-transaction.ts +15 -10
  57. package/internal/src/transaction/undo-transaction.ts +15 -16
  58. package/introspection/dist/index.cjs +2 -2
  59. package/introspection/dist/index.cjs.map +1 -1
  60. package/introspection/dist/index.js +3 -3
  61. package/introspection/dist/index.js.map +1 -1
  62. package/introspection/src/attach-atom-index.ts +2 -2
  63. package/introspection/src/attach-selector-index.ts +2 -2
  64. package/package.json +3 -3
  65. package/react-devtools/dist/index.cjs +22 -8
  66. package/react-devtools/dist/index.cjs.map +1 -1
  67. package/react-devtools/dist/index.d.cts +17 -9
  68. package/react-devtools/dist/index.d.ts +17 -9
  69. package/react-devtools/dist/index.js +22 -8
  70. package/react-devtools/dist/index.js.map +1 -1
  71. package/react-devtools/dist/metafile-cjs.json +1 -1
  72. package/react-devtools/dist/metafile-esm.json +1 -1
  73. package/react-devtools/src/Updates.tsx +22 -10
  74. package/src/transaction.ts +7 -2
  75. package/transceivers/set-rtx/dist/index.cjs.map +1 -1
  76. package/transceivers/set-rtx/dist/index.d.cts +2 -2
  77. package/transceivers/set-rtx/dist/index.d.ts +2 -2
  78. package/transceivers/set-rtx/dist/index.js.map +1 -1
  79. package/transceivers/set-rtx/dist/metafile-cjs.json +1 -1
  80. package/transceivers/set-rtx/dist/metafile-esm.json +1 -1
  81. package/transceivers/set-rtx/src/set-rtx.ts +3 -3
@@ -8,6 +8,11 @@ declare class Subject<T> {
8
8
  private unsubscribe;
9
9
  next(value: T): void;
10
10
  }
11
+ declare class StatefulSubject<T> extends Subject<T> {
12
+ state: T;
13
+ constructor(initialState: T);
14
+ next(value: T): void;
15
+ }
11
16
 
12
17
  type Selector<T> = {
13
18
  key: string;
@@ -78,23 +83,18 @@ type Transaction<ƒ extends ƒn> = {
78
83
  run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
79
84
  };
80
85
  declare function createTransaction<ƒ extends ƒn>(options: TransactionOptions<ƒ>, store: Store): TransactionToken<ƒ>;
81
- declare const target: (store: Store) => StoreCore;
82
86
 
83
- declare const redoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
87
+ declare const redoTransactionUpdate: <ƒ extends ƒn>(transactionUpdate: TransactionUpdate<ƒ>, store: Store) => void;
84
88
 
85
- declare const undoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
89
+ declare const undoTransactionUpdate: <ƒ extends ƒn>(transactionUpdate: TransactionUpdate<ƒ>, store: Store) => void;
86
90
 
87
91
  declare const TRANSACTION_PHASES: readonly ["idle", "building", "applying"];
88
92
  type TransactionPhase = (typeof TRANSACTION_PHASES)[number];
89
- type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
93
+ type TransactionMeta<ƒ extends ƒn> = {
90
94
  phase: `applying` | `building`;
91
95
  time: number;
92
- core: StoreCore;
93
- };
94
- type TransactionIdle = {
95
- phase: `idle`;
96
+ update: TransactionUpdate<ƒ>;
96
97
  };
97
- type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
98
98
 
99
99
  declare function deposit<T>(state: Atom<T>): AtomToken<T>;
100
100
  declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
@@ -177,6 +177,13 @@ declare class Junction<const ASide extends string, const BSide extends string, c
177
177
  has(a: string, b?: string): boolean;
178
178
  }
179
179
 
180
+ interface Lineage {
181
+ parent: typeof this | null;
182
+ child: typeof this | null;
183
+ }
184
+ declare function newest<T extends Lineage>(scion: T): T;
185
+ declare function eldest<T extends Lineage>(scion: T): T;
186
+
180
187
  interface Transceiver<Signal extends Json.Serializable> {
181
188
  do: (update: Signal) => void;
182
189
  undo: (update: Signal) => void;
@@ -277,8 +284,9 @@ declare const addAtomToTimeline: (atomToken: AtomToken<any>, tl: Timeline, store
277
284
 
278
285
  declare const timeTravel: (direction: `backward` | `forward`, token: TimelineToken, store: Store) => void;
279
286
 
280
- type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `families` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `trackers` | `transactions` | `valueMap`>;
281
- declare class Store {
287
+ declare class Store implements Lineage {
288
+ parent: Store | null;
289
+ child: Store | null;
282
290
  valueMap: Map<string, any>;
283
291
  atoms: Map<string, Atom<any> | MutableAtom<any>>;
284
292
  selectors: Map<string, Selector<any>>;
@@ -298,10 +306,11 @@ declare class Store {
298
306
  selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
299
307
  transactionCreation: Subject<TransactionToken<ƒn>>;
300
308
  timelineCreation: Subject<TimelineToken>;
309
+ transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
301
310
  operationStatus: Subject<OperationProgress>;
302
311
  };
303
312
  operation: OperationProgress;
304
- transactionStatus: TransactionStatus<ƒn>;
313
+ transactionMeta: TransactionMeta<ƒn> | null;
305
314
  config: {
306
315
  name: string;
307
316
  };
@@ -378,12 +387,23 @@ declare function createReadonlySelectorFamily<T, K extends Json.Serializable>(op
378
387
  declare function createSelectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>, store: Store): SelectorFamily<T, K>;
379
388
  declare function createSelectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
380
389
 
381
- declare const readOrComputeValue: <T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>, store: Store) => T;
390
+ declare class LazyMap<K, V> extends Map<K, V> {
391
+ protected readonly source: Map<K, V>;
392
+ deleted: Set<K>;
393
+ constructor(source: Map<K, V>);
394
+ get(key: K): V | undefined;
395
+ set(key: K, value: V): this;
396
+ hasOwn(key: K): boolean;
397
+ has(key: K): boolean;
398
+ delete(key: K): boolean;
399
+ }
382
400
 
383
401
  declare class NotFoundError extends Error {
384
402
  constructor(token: ReadonlySelectorToken<any> | StateToken<any>, store: Store);
385
403
  }
386
404
 
405
+ declare const readOrComputeValue: <T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>, store: Store) => T;
406
+
387
407
  type Modify<T> = (thing: T) => T;
388
408
  declare const become: <T>(nextVersionOfThing: T | Modify<T>) => (originalThing: T) => T;
389
409
 
@@ -391,4 +411,4 @@ declare const setAtomOrSelector: <T>(state: Atom<T> | Selector<T>, value: T | ((
391
411
 
392
412
  declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
393
413
 
394
- export { type Atom, type AtomKey, FamilyTracker, Future, IMPLICIT, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, Store, type StoreCore, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionIdle, type TransactionPhase, type TransactionStatus, type TransactionUpdateInProgress, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, isAtomDefault, isAtomKey, isAtomMutable, isAtomTokenMutable, isDone, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, readOrComputeValue, redoTransactionUpdate, registerSelector, setAtomOrSelector, subscribeToRootAtoms, target, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, undoTransactionUpdate, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
414
+ export { type Atom, type AtomKey, FamilyTracker, Future, IMPLICIT, LazyMap, type Lineage, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, StatefulSubject, Store, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionMeta, type TransactionPhase, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, isAtomDefault, isAtomKey, isAtomMutable, isAtomTokenMutable, isDone, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, redoTransactionUpdate, registerSelector, setAtomOrSelector, subscribeToRootAtoms, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, undoTransactionUpdate, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
@@ -8,6 +8,11 @@ declare class Subject<T> {
8
8
  private unsubscribe;
9
9
  next(value: T): void;
10
10
  }
11
+ declare class StatefulSubject<T> extends Subject<T> {
12
+ state: T;
13
+ constructor(initialState: T);
14
+ next(value: T): void;
15
+ }
11
16
 
12
17
  type Selector<T> = {
13
18
  key: string;
@@ -78,23 +83,18 @@ type Transaction<ƒ extends ƒn> = {
78
83
  run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
79
84
  };
80
85
  declare function createTransaction<ƒ extends ƒn>(options: TransactionOptions<ƒ>, store: Store): TransactionToken<ƒ>;
81
- declare const target: (store: Store) => StoreCore;
82
86
 
83
- declare const redoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
87
+ declare const redoTransactionUpdate: <ƒ extends ƒn>(transactionUpdate: TransactionUpdate<ƒ>, store: Store) => void;
84
88
 
85
- declare const undoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
89
+ declare const undoTransactionUpdate: <ƒ extends ƒn>(transactionUpdate: TransactionUpdate<ƒ>, store: Store) => void;
86
90
 
87
91
  declare const TRANSACTION_PHASES: readonly ["idle", "building", "applying"];
88
92
  type TransactionPhase = (typeof TRANSACTION_PHASES)[number];
89
- type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
93
+ type TransactionMeta<ƒ extends ƒn> = {
90
94
  phase: `applying` | `building`;
91
95
  time: number;
92
- core: StoreCore;
93
- };
94
- type TransactionIdle = {
95
- phase: `idle`;
96
+ update: TransactionUpdate<ƒ>;
96
97
  };
97
- type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
98
98
 
99
99
  declare function deposit<T>(state: Atom<T>): AtomToken<T>;
100
100
  declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
@@ -177,6 +177,13 @@ declare class Junction<const ASide extends string, const BSide extends string, c
177
177
  has(a: string, b?: string): boolean;
178
178
  }
179
179
 
180
+ interface Lineage {
181
+ parent: typeof this | null;
182
+ child: typeof this | null;
183
+ }
184
+ declare function newest<T extends Lineage>(scion: T): T;
185
+ declare function eldest<T extends Lineage>(scion: T): T;
186
+
180
187
  interface Transceiver<Signal extends Json.Serializable> {
181
188
  do: (update: Signal) => void;
182
189
  undo: (update: Signal) => void;
@@ -277,8 +284,9 @@ declare const addAtomToTimeline: (atomToken: AtomToken<any>, tl: Timeline, store
277
284
 
278
285
  declare const timeTravel: (direction: `backward` | `forward`, token: TimelineToken, store: Store) => void;
279
286
 
280
- type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `families` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `trackers` | `transactions` | `valueMap`>;
281
- declare class Store {
287
+ declare class Store implements Lineage {
288
+ parent: Store | null;
289
+ child: Store | null;
282
290
  valueMap: Map<string, any>;
283
291
  atoms: Map<string, Atom<any> | MutableAtom<any>>;
284
292
  selectors: Map<string, Selector<any>>;
@@ -298,10 +306,11 @@ declare class Store {
298
306
  selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
299
307
  transactionCreation: Subject<TransactionToken<ƒn>>;
300
308
  timelineCreation: Subject<TimelineToken>;
309
+ transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
301
310
  operationStatus: Subject<OperationProgress>;
302
311
  };
303
312
  operation: OperationProgress;
304
- transactionStatus: TransactionStatus<ƒn>;
313
+ transactionMeta: TransactionMeta<ƒn> | null;
305
314
  config: {
306
315
  name: string;
307
316
  };
@@ -378,12 +387,23 @@ declare function createReadonlySelectorFamily<T, K extends Json.Serializable>(op
378
387
  declare function createSelectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>, store: Store): SelectorFamily<T, K>;
379
388
  declare function createSelectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
380
389
 
381
- declare const readOrComputeValue: <T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>, store: Store) => T;
390
+ declare class LazyMap<K, V> extends Map<K, V> {
391
+ protected readonly source: Map<K, V>;
392
+ deleted: Set<K>;
393
+ constructor(source: Map<K, V>);
394
+ get(key: K): V | undefined;
395
+ set(key: K, value: V): this;
396
+ hasOwn(key: K): boolean;
397
+ has(key: K): boolean;
398
+ delete(key: K): boolean;
399
+ }
382
400
 
383
401
  declare class NotFoundError extends Error {
384
402
  constructor(token: ReadonlySelectorToken<any> | StateToken<any>, store: Store);
385
403
  }
386
404
 
405
+ declare const readOrComputeValue: <T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>, store: Store) => T;
406
+
387
407
  type Modify<T> = (thing: T) => T;
388
408
  declare const become: <T>(nextVersionOfThing: T | Modify<T>) => (originalThing: T) => T;
389
409
 
@@ -391,4 +411,4 @@ declare const setAtomOrSelector: <T>(state: Atom<T> | Selector<T>, value: T | ((
391
411
 
392
412
  declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
393
413
 
394
- export { type Atom, type AtomKey, FamilyTracker, Future, IMPLICIT, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, Store, type StoreCore, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionIdle, type TransactionPhase, type TransactionStatus, type TransactionUpdateInProgress, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, isAtomDefault, isAtomKey, isAtomMutable, isAtomTokenMutable, isDone, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, readOrComputeValue, redoTransactionUpdate, registerSelector, setAtomOrSelector, subscribeToRootAtoms, target, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, undoTransactionUpdate, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
414
+ export { type Atom, type AtomKey, FamilyTracker, Future, IMPLICIT, LazyMap, type Lineage, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, StatefulSubject, Store, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionMeta, type TransactionPhase, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, isAtomDefault, isAtomKey, isAtomMutable, isAtomTokenMutable, isDone, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, redoTransactionUpdate, registerSelector, setAtomOrSelector, subscribeToRootAtoms, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, undoTransactionUpdate, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };