atom.io 0.15.4 → 0.15.6
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/data/dist/index.cjs +20 -16
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.js +21 -17
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +6 -2
- package/dist/index.cjs +21 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +69 -18
- package/dist/index.js +157 -1
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +88 -146
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +29 -17
- package/internal/dist/index.js +79 -92
- package/internal/dist/index.js.map +1 -1
- package/internal/src/get-environment-data.ts +18 -0
- package/internal/src/index.ts +2 -0
- package/internal/src/ingest-updates/index.ts +3 -0
- package/internal/src/ingest-updates/ingest-atom-update.ts +14 -0
- package/internal/src/ingest-updates/ingest-selector-update.ts +17 -0
- package/internal/src/ingest-updates/ingest-transaction-update.ts +22 -0
- package/internal/src/mutable/tracker.ts +1 -1
- package/internal/src/not-found-error.ts +3 -8
- package/internal/src/operation.ts +3 -3
- package/internal/src/selector/create-read-write-selector.ts +5 -3
- package/internal/src/selector/create-readonly-selector.ts +2 -2
- package/internal/src/selector/register-selector.ts +6 -4
- package/internal/src/selector/update-selector-atoms.ts +2 -2
- package/internal/src/set-state/set-atom.ts +8 -3
- package/internal/src/store/deposit.ts +5 -5
- package/internal/src/store/withdraw-new-family-member.ts +8 -11
- package/internal/src/store/withdraw.ts +4 -3
- package/internal/src/subscribe/subscribe-to-state.ts +2 -2
- package/internal/src/timeline/time-travel.ts +18 -44
- package/internal/src/transaction/apply-transaction.ts +3 -49
- package/internal/src/transaction/build-transaction.ts +8 -1
- package/internal/src/transaction/create-transaction.ts +3 -3
- package/internal/src/transaction/index.ts +2 -2
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +4 -4
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +2 -2
- package/introspection/src/attach-selector-index.ts +2 -2
- package/introspection/src/index.ts +1 -1
- package/package.json +8 -8
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +3 -3
- package/react/dist/index.js.map +1 -1
- package/react/src/store-hooks.ts +4 -4
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.ts +3 -3
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +3 -3
- package/react-devtools/src/StateIndex.tsx +3 -3
- package/realtime-client/dist/index.cjs +67 -65
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +6 -5
- package/realtime-client/dist/index.js +62 -61
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/pull-family-member.ts +1 -1
- package/realtime-client/src/pull.ts +1 -1
- package/realtime-client/src/push.ts +2 -3
- package/realtime-client/src/realtime-state.ts +8 -0
- package/realtime-client/src/server-action.ts +65 -65
- package/realtime-react/dist/index.cjs +88 -52
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +11 -6
- package/realtime-react/dist/index.js +87 -51
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/on-mount.ts +23 -0
- package/realtime-react/src/realtime-context.tsx +12 -2
- package/realtime-react/src/use-pull-family-member.ts +5 -8
- package/realtime-react/src/use-pull-mutable-family-member.ts +4 -7
- package/realtime-react/src/use-pull-mutable.ts +4 -7
- package/realtime-react/src/use-pull.ts +5 -8
- package/realtime-react/src/use-push.ts +5 -9
- package/realtime-react/src/use-realtime-service.ts +30 -0
- package/realtime-react/src/use-server-action.ts +8 -8
- package/realtime-server/dist/index.cjs +109 -40
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +7 -6
- package/realtime-server/dist/index.js +90 -39
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/hook-composition/expose-family.ts +2 -2
- package/realtime-server/src/hook-composition/expose-mutable-family.ts +1 -1
- package/realtime-server/src/hook-composition/expose-single.ts +1 -1
- package/realtime-server/src/hook-composition/index.ts +2 -1
- package/realtime-server/src/hook-composition/receive-state.ts +2 -2
- package/realtime-server/src/hook-composition/receive-transaction.ts +13 -32
- package/realtime-server/src/hook-composition/sync-transaction.ts +92 -0
- package/realtime-testing/dist/index.cjs +3 -3
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.js +2 -2
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +4 -3
- package/src/atom.ts +30 -7
- package/src/dispose.ts +2 -2
- package/src/find-state.ts +64 -0
- package/src/get-state.ts +2 -2
- package/src/index.ts +15 -2
- package/src/logger.ts +1 -0
- package/src/selector.ts +16 -0
- package/src/set-state.ts +2 -2
- package/src/silo.ts +2 -2
- package/src/timeline.ts +2 -2
- package/src/transaction.ts +31 -12
- package/dist/chunk-RLZQ6IIY.js +0 -147
- package/dist/chunk-RLZQ6IIY.js.map +0 -1
package/internal/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FamilyMetadata as FamilyMetadata$1, SelectorOptions, SelectorToken, ReadonlySelectorOptions, ReadonlySelectorToken, Transactors,
|
|
1
|
+
import { FamilyMetadata as FamilyMetadata$1, SelectorOptions, SelectorToken, ReadonlySelectorOptions, ReadonlySelectorToken, Transactors, WritableToken, ƒn as _n, TransactionUpdate, TransactionOptions, TransactionToken, TransactorsWithRunAndEnv, AtomToken, ReadableToken, MutableAtomOptions, MutableAtomToken, MutableAtomFamilyOptions, MutableAtomFamily, SelectorFamily, AtomFamily, TimelineManageable, StateUpdate, TokenType, TimelineUpdate, TimelineOptions, TimelineToken, ReadonlySelectorFamily, AtomIOLogger, Logger, AtomOptions, AtomFamilyOptions, ReadonlySelectorFamilyOptions, SelectorFamilyOptions, KeyedStateUpdate, UpdateHandler, TransactionUpdateHandler } from 'atom.io';
|
|
2
2
|
import { Json } from 'atom.io/json';
|
|
3
3
|
import { Store as Store$1 } from 'atom.io/internal';
|
|
4
4
|
|
|
@@ -73,20 +73,20 @@ declare const registerSelector: (selectorKey: string, store: Store) => Transacto
|
|
|
73
73
|
declare const traceSelectorAtoms: (selectorKey: string, directDependencyKey: StateKey<unknown>, store: Store) => AtomKey<unknown>[];
|
|
74
74
|
declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) => AtomKey<unknown>[];
|
|
75
75
|
|
|
76
|
-
declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> |
|
|
76
|
+
declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | WritableToken<unknown>, store: Store) => void;
|
|
77
77
|
|
|
78
78
|
declare const abortTransaction: (store: Store) => void;
|
|
79
79
|
|
|
80
80
|
declare const applyTransaction: <ƒ extends _n>(output: ReturnType<ƒ>, store: Store) => void;
|
|
81
81
|
|
|
82
|
-
declare const buildTransaction: (key: string, params: any[], store: Store) => void;
|
|
82
|
+
declare const buildTransaction: (key: string, params: any[], store: Store, id?: string) => void;
|
|
83
83
|
|
|
84
84
|
type Transaction<ƒ extends _n> = {
|
|
85
85
|
key: string;
|
|
86
86
|
type: `transaction`;
|
|
87
87
|
install: (store: Store) => void;
|
|
88
88
|
subject: Subject<TransactionUpdate<ƒ>>;
|
|
89
|
-
run: (
|
|
89
|
+
run: (parameters: Parameters<ƒ>, id?: string) => ReturnType<ƒ>;
|
|
90
90
|
};
|
|
91
91
|
declare function createTransaction<ƒ extends _n>(options: TransactionOptions<ƒ>, store: Store): TransactionToken<ƒ>;
|
|
92
92
|
|
|
@@ -96,15 +96,15 @@ type TransactionMeta<ƒ extends _n> = {
|
|
|
96
96
|
phase: `applying` | `building`;
|
|
97
97
|
time: number;
|
|
98
98
|
update: TransactionUpdate<ƒ>;
|
|
99
|
-
transactors:
|
|
99
|
+
transactors: TransactorsWithRunAndEnv;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
declare function deposit<T>(state: Atom<T>): AtomToken<T>;
|
|
103
103
|
declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
|
|
104
|
-
declare function deposit<T>(state: Atom<T> | Selector<T>):
|
|
104
|
+
declare function deposit<T>(state: Atom<T> | Selector<T>): WritableToken<T>;
|
|
105
105
|
declare function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>;
|
|
106
106
|
declare function deposit<T>(state: Transaction<T extends _n ? T : never>): TransactionToken<T>;
|
|
107
|
-
declare function deposit<T>(state:
|
|
107
|
+
declare function deposit<T>(state: StateNode<T>): ReadableToken<T>;
|
|
108
108
|
|
|
109
109
|
type primitive = boolean | number | string | null;
|
|
110
110
|
|
|
@@ -246,9 +246,9 @@ type OperationProgress = {
|
|
|
246
246
|
done: Set<string>;
|
|
247
247
|
prev: Map<string, any>;
|
|
248
248
|
time: number;
|
|
249
|
-
token:
|
|
249
|
+
token: WritableToken<any>;
|
|
250
250
|
};
|
|
251
|
-
declare const openOperation: (token:
|
|
251
|
+
declare const openOperation: (token: WritableToken<any>, store: Store) => `rejection` | undefined;
|
|
252
252
|
declare const closeOperation: (store: Store) => void;
|
|
253
253
|
declare const isDone: (key: string, store: Store) => boolean;
|
|
254
254
|
declare const markDone: (key: string, store: Store) => void;
|
|
@@ -286,7 +286,7 @@ declare function createTimeline<ManagedAtom extends TimelineManageable>(options:
|
|
|
286
286
|
|
|
287
287
|
declare const addAtomToTimeline: (atomToken: AtomToken<any>, tl: Timeline<any>, store: Store) => void;
|
|
288
288
|
|
|
289
|
-
declare const timeTravel: (
|
|
289
|
+
declare const timeTravel: (action: `redo` | `undo`, token: TimelineToken<any>, store: Store) => void;
|
|
290
290
|
|
|
291
291
|
declare class Store implements Lineage {
|
|
292
292
|
parent: Store | null;
|
|
@@ -330,17 +330,17 @@ declare const clearStore: (store: Store) => void;
|
|
|
330
330
|
|
|
331
331
|
declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | undefined;
|
|
332
332
|
declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T> | undefined;
|
|
333
|
-
declare function withdraw<T>(token:
|
|
333
|
+
declare function withdraw<T>(token: WritableToken<T>, store: Store): Atom<T> | Selector<T> | undefined;
|
|
334
334
|
declare function withdraw<T>(token: ReadonlySelectorToken<T>, store: Store): ReadonlySelector<T> | undefined;
|
|
335
335
|
declare function withdraw<T>(token: TransactionToken<T>, store: Store): Transaction<T extends _n ? T : never> | undefined;
|
|
336
|
-
declare function withdraw<T>(token: ReadableToken<T>, store: Store):
|
|
336
|
+
declare function withdraw<T>(token: ReadableToken<T>, store: Store): StateNode<T> | undefined;
|
|
337
337
|
declare function withdraw<T>(token: TimelineToken<T>, store: Store): Timeline<T extends TimelineManageable ? T : never> | undefined;
|
|
338
338
|
|
|
339
339
|
declare function withdrawNewFamilyMember<T>(token: AtomToken<T>, store: Store): Atom<T> | undefined;
|
|
340
340
|
declare function withdrawNewFamilyMember<T>(token: SelectorToken<T>, store: Store): Selector<T> | undefined;
|
|
341
341
|
declare function withdrawNewFamilyMember<T>(token: ReadonlySelectorToken<T>, store: Store): ReadonlySelector<T> | undefined;
|
|
342
|
-
declare function withdrawNewFamilyMember<T>(token:
|
|
343
|
-
declare function withdrawNewFamilyMember<T>(token:
|
|
342
|
+
declare function withdrawNewFamilyMember<T>(token: WritableToken<T>, store: Store): Atom<T> | Selector<T> | undefined;
|
|
343
|
+
declare function withdrawNewFamilyMember<T>(token: ReadableToken<T>, store: Store): StateNode<T> | undefined;
|
|
344
344
|
|
|
345
345
|
declare function createAtom<T>(options: AtomOptions<T> | MutableAtomOptions<any, any>, family: FamilyMetadata$1 | undefined, store: Store): AtomToken<T>;
|
|
346
346
|
|
|
@@ -396,6 +396,18 @@ declare function createReadonlySelectorFamily<T, K extends Json.Serializable>(op
|
|
|
396
396
|
declare function createSelectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>, store: Store): SelectorFamily<T, K>;
|
|
397
397
|
declare function createSelectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
|
|
398
398
|
|
|
399
|
+
type EnvironmentData = {
|
|
400
|
+
runtime: `browser` | `node` | `unknown`;
|
|
401
|
+
store: Store;
|
|
402
|
+
};
|
|
403
|
+
declare function getEnvironmentData(store: Store): EnvironmentData;
|
|
404
|
+
|
|
405
|
+
declare function ingestAtomUpdate(applying: `newValue` | `oldValue`, atomUpdate: KeyedStateUpdate<any>, store: Store): void;
|
|
406
|
+
|
|
407
|
+
declare function ingestSelectorUpdate(applying: `newValue` | `oldValue`, selectorUpdate: TimelineSelectorUpdate<any>, store: Store): void;
|
|
408
|
+
|
|
409
|
+
declare function ingestTransactionUpdate(applying: `newValue` | `oldValue`, transactionUpdate: TransactionUpdate<any>, store: Store): void;
|
|
410
|
+
|
|
399
411
|
declare class LazyMap<K, V> extends Map<K, V> {
|
|
400
412
|
protected readonly source: Map<K, V>;
|
|
401
413
|
deleted: Set<K>;
|
|
@@ -408,7 +420,7 @@ declare class LazyMap<K, V> extends Map<K, V> {
|
|
|
408
420
|
}
|
|
409
421
|
|
|
410
422
|
declare class NotFoundError extends Error {
|
|
411
|
-
constructor(token:
|
|
423
|
+
constructor(token: ReadableToken<any>, store: Store);
|
|
412
424
|
}
|
|
413
425
|
|
|
414
426
|
declare const readOrComputeValue: <T>(state: StateNode<T>, target: Store) => T;
|
|
@@ -420,7 +432,7 @@ declare const setAtomOrSelector: <T>(state: Atom<T> | Selector<T>, value: T | ((
|
|
|
420
432
|
|
|
421
433
|
declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
|
|
422
434
|
|
|
423
|
-
declare function subscribeToState<T>(token:
|
|
435
|
+
declare function subscribeToState<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key: string, store: Store): () => void;
|
|
424
436
|
|
|
425
437
|
declare const subscribeToTimeline: <ManagedAtom extends TimelineManageable>(token: TimelineToken<ManagedAtom>, handleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void, key: string, store: Store$1) => (() => void);
|
|
426
438
|
|
|
@@ -428,4 +440,4 @@ declare const subscribeToTransaction: <ƒ extends _n>(token: TransactionToken<ƒ
|
|
|
428
440
|
|
|
429
441
|
type StateNode<T> = Atom<T> | ReadonlySelector<T> | Selector<T>;
|
|
430
442
|
|
|
431
|
-
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, type StateNode, 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, createRegularAtom, createRegularAtomFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
|
443
|
+
export { type Atom, type AtomKey, type EnvironmentData, 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, type StateNode, 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, createRegularAtom, createRegularAtomFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getEnvironmentData, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestSelectorUpdate, ingestTransactionUpdate, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
package/internal/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { getState as getState$1, setState as setState$1, runTransaction } from '../../dist/chunk-RLZQ6IIY.js';
|
|
2
1
|
import { Junction } from '../../dist/chunk-NYTGCPHB.js';
|
|
3
2
|
import { __spreadValues, __spreadProps } from '../../dist/chunk-PZLG2HP3.js';
|
|
4
3
|
import { selectJson, stringifyJson, parseJson, selectJsonFamily } from 'atom.io/json';
|
|
5
|
-
import { AtomIOLogger, getState, setState } from 'atom.io';
|
|
4
|
+
import { AtomIOLogger, findInStore, getState, setState, runTransaction } from 'atom.io';
|
|
6
5
|
import { withdraw as withdraw$1 } from 'atom.io/internal';
|
|
7
6
|
|
|
8
7
|
// internal/src/lineage.ts
|
|
@@ -353,10 +352,13 @@ var setAtom = (atom, next, target) => {
|
|
|
353
352
|
const update = { oldValue, newValue };
|
|
354
353
|
if (target.transactionMeta === null) {
|
|
355
354
|
emitUpdate(atom, update, target);
|
|
356
|
-
} else if (target.
|
|
357
|
-
emitUpdate(atom, update, target.parent);
|
|
358
|
-
} else {
|
|
355
|
+
} else if (target.on.transactionApplying && target.parent) {
|
|
359
356
|
stowUpdate(atom, update, target);
|
|
357
|
+
if (atom.key.startsWith(`*`)) {
|
|
358
|
+
const mutableKey = atom.key.slice(1);
|
|
359
|
+
const mutable = target.valueMap.get(mutableKey);
|
|
360
|
+
mutable.do(update.newValue);
|
|
361
|
+
}
|
|
360
362
|
}
|
|
361
363
|
};
|
|
362
364
|
|
|
@@ -654,24 +656,27 @@ var registerSelector = (selectorKey, store) => ({
|
|
|
654
656
|
updateSelectorAtoms(selectorKey, dependency, store);
|
|
655
657
|
return dependencyValue;
|
|
656
658
|
},
|
|
657
|
-
set: (
|
|
658
|
-
const state = withdraw(
|
|
659
|
+
set: (WritableToken, newValue) => {
|
|
660
|
+
const state = withdraw(WritableToken, store);
|
|
659
661
|
if (state === void 0) {
|
|
660
662
|
throw new Error(
|
|
661
|
-
`State "${
|
|
663
|
+
`State "${WritableToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
662
664
|
);
|
|
663
665
|
}
|
|
664
666
|
setAtomOrSelector(state, newValue, store);
|
|
665
|
-
}
|
|
667
|
+
},
|
|
668
|
+
find: (token, key) => findInStore(token, key, store)
|
|
666
669
|
});
|
|
667
670
|
|
|
668
671
|
// internal/src/selector/create-read-write-selector.ts
|
|
669
672
|
var createReadWriteSelector = (options, family, store) => {
|
|
670
673
|
const target = newest(store);
|
|
671
674
|
const subject = new Subject();
|
|
672
|
-
const
|
|
675
|
+
const transactors = registerSelector(options.key, store);
|
|
676
|
+
const { find, get } = transactors;
|
|
677
|
+
const readonlyTransactors = { find, get };
|
|
673
678
|
const getSelf = () => {
|
|
674
|
-
const value = options.get(
|
|
679
|
+
const value = options.get(readonlyTransactors);
|
|
675
680
|
cacheValue(options.key, value, subject, newest(store));
|
|
676
681
|
return value;
|
|
677
682
|
};
|
|
@@ -693,7 +698,7 @@ var createReadWriteSelector = (options, family, store) => {
|
|
|
693
698
|
if (target.transactionMeta === null) {
|
|
694
699
|
subject.next({ newValue, oldValue });
|
|
695
700
|
}
|
|
696
|
-
options.set(
|
|
701
|
+
options.set(transactors, newValue);
|
|
697
702
|
};
|
|
698
703
|
const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
699
704
|
subject,
|
|
@@ -720,9 +725,9 @@ var createReadWriteSelector = (options, family, store) => {
|
|
|
720
725
|
var createReadonlySelector = (options, family, store) => {
|
|
721
726
|
const target = newest(store);
|
|
722
727
|
const subject = new Subject();
|
|
723
|
-
const { get } = registerSelector(options.key, store);
|
|
728
|
+
const { get, find } = registerSelector(options.key, store);
|
|
724
729
|
const getSelf = () => {
|
|
725
|
-
const value = options.get({ get });
|
|
730
|
+
const value = options.get({ get, find });
|
|
726
731
|
cacheValue(options.key, value, subject, store);
|
|
727
732
|
return value;
|
|
728
733
|
};
|
|
@@ -1405,7 +1410,7 @@ function createAtom(options, family, store) {
|
|
|
1405
1410
|
}
|
|
1406
1411
|
|
|
1407
1412
|
// internal/src/atom/delete-atom.ts
|
|
1408
|
-
function
|
|
1413
|
+
function deleteAtom(atomToken, store) {
|
|
1409
1414
|
var _a, _b;
|
|
1410
1415
|
const target = newest(store);
|
|
1411
1416
|
const { key } = atomToken;
|
|
@@ -1436,6 +1441,39 @@ function deleteAtom2(atomToken, store) {
|
|
|
1436
1441
|
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1437
1442
|
}
|
|
1438
1443
|
|
|
1444
|
+
// internal/src/get-environment-data.ts
|
|
1445
|
+
function getEnvironmentData(store) {
|
|
1446
|
+
return {
|
|
1447
|
+
runtime: typeof window === `undefined` ? typeof global === `object` ? `node` : `unknown` : `browser`,
|
|
1448
|
+
store
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
function ingestAtomUpdate(applying, atomUpdate, store) {
|
|
1452
|
+
const { key, newValue, oldValue } = atomUpdate;
|
|
1453
|
+
const value = applying === `newValue` ? newValue : oldValue;
|
|
1454
|
+
setState({ key, type: `atom` }, value, store);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
// internal/src/ingest-updates/ingest-selector-update.ts
|
|
1458
|
+
function ingestSelectorUpdate(applying, selectorUpdate, store) {
|
|
1459
|
+
const updates = applying === `newValue` ? selectorUpdate.atomUpdates : [...selectorUpdate.atomUpdates].reverse();
|
|
1460
|
+
for (const atomUpdate of updates) {
|
|
1461
|
+
ingestAtomUpdate(applying, atomUpdate, store);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// internal/src/ingest-updates/ingest-transaction-update.ts
|
|
1466
|
+
function ingestTransactionUpdate(applying, transactionUpdate, store) {
|
|
1467
|
+
const updates = applying === `newValue` ? transactionUpdate.updates : [...transactionUpdate.updates].reverse();
|
|
1468
|
+
for (const updateFromTransaction of updates) {
|
|
1469
|
+
if (`newValue` in updateFromTransaction) {
|
|
1470
|
+
ingestAtomUpdate(applying, updateFromTransaction, store);
|
|
1471
|
+
} else {
|
|
1472
|
+
ingestTransactionUpdate(applying, updateFromTransaction, store);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1439
1477
|
// internal/src/lazy-map.ts
|
|
1440
1478
|
var LazyMap = class extends Map {
|
|
1441
1479
|
constructor(source) {
|
|
@@ -1789,10 +1827,11 @@ function createTimeline(options, store, data) {
|
|
|
1789
1827
|
store.on.timelineCreation.next(token);
|
|
1790
1828
|
return token;
|
|
1791
1829
|
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1830
|
+
|
|
1831
|
+
// internal/src/timeline/time-travel.ts
|
|
1832
|
+
var timeTravel = (action, token, store) => {
|
|
1794
1833
|
store.logger.info(
|
|
1795
|
-
|
|
1834
|
+
action === `redo` ? `\u23E9` : `\u23EA`,
|
|
1796
1835
|
`timeline`,
|
|
1797
1836
|
token.key,
|
|
1798
1837
|
action
|
|
@@ -1807,53 +1846,36 @@ var timeTravel = (direction, token, store) => {
|
|
|
1807
1846
|
);
|
|
1808
1847
|
return;
|
|
1809
1848
|
}
|
|
1810
|
-
if (
|
|
1849
|
+
if (action === `redo` && timelineData.at === timelineData.history.length || action === `undo` && timelineData.at === 0) {
|
|
1811
1850
|
store.logger.warn(
|
|
1812
1851
|
`\u{1F481}`,
|
|
1813
1852
|
`timeline`,
|
|
1814
1853
|
token.key,
|
|
1815
|
-
`Failed to ${action} at the ${
|
|
1854
|
+
`Failed to ${action} at the ${action === `redo` ? `end` : `beginning`} of timeline "${token.key}". There is nothing to ${action}.`
|
|
1816
1855
|
);
|
|
1817
1856
|
return;
|
|
1818
1857
|
}
|
|
1819
|
-
timelineData.timeTraveling =
|
|
1820
|
-
if (
|
|
1858
|
+
timelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`;
|
|
1859
|
+
if (action === `undo`) {
|
|
1821
1860
|
--timelineData.at;
|
|
1822
1861
|
}
|
|
1823
1862
|
const update = timelineData.history[timelineData.at];
|
|
1824
|
-
const
|
|
1825
|
-
const { key, newValue, oldValue } = atomUpdate;
|
|
1826
|
-
const value = direction === `forward` ? newValue : oldValue;
|
|
1827
|
-
setState({ key, type: `atom` }, value, store);
|
|
1828
|
-
};
|
|
1829
|
-
const updateValuesFromTransactionUpdate = (transactionUpdate) => {
|
|
1830
|
-
const updates = direction === `forward` ? transactionUpdate.updates : [...transactionUpdate.updates].reverse();
|
|
1831
|
-
for (const updateFromTransaction of updates) {
|
|
1832
|
-
if (`newValue` in updateFromTransaction) {
|
|
1833
|
-
updateValues(updateFromTransaction);
|
|
1834
|
-
} else {
|
|
1835
|
-
updateValuesFromTransactionUpdate(updateFromTransaction);
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
};
|
|
1863
|
+
const applying = action === `redo` ? `newValue` : `oldValue`;
|
|
1839
1864
|
switch (update.type) {
|
|
1840
1865
|
case `atom_update`: {
|
|
1841
|
-
|
|
1866
|
+
ingestAtomUpdate(applying, update, store);
|
|
1842
1867
|
break;
|
|
1843
1868
|
}
|
|
1844
1869
|
case `selector_update`: {
|
|
1845
|
-
|
|
1846
|
-
for (const atomUpdate of updates) {
|
|
1847
|
-
updateValues(atomUpdate);
|
|
1848
|
-
}
|
|
1870
|
+
ingestSelectorUpdate(applying, update, store);
|
|
1849
1871
|
break;
|
|
1850
1872
|
}
|
|
1851
1873
|
case `transaction_update`: {
|
|
1852
|
-
|
|
1874
|
+
ingestTransactionUpdate(applying, update, store);
|
|
1853
1875
|
break;
|
|
1854
1876
|
}
|
|
1855
1877
|
}
|
|
1856
|
-
if (
|
|
1878
|
+
if (action === `redo`) {
|
|
1857
1879
|
++timelineData.at;
|
|
1858
1880
|
}
|
|
1859
1881
|
timelineData.subject.next(action);
|
|
@@ -1886,44 +1908,8 @@ var abortTransaction = (store) => {
|
|
|
1886
1908
|
);
|
|
1887
1909
|
target.parent.child = null;
|
|
1888
1910
|
};
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
const { key, newValue } = update;
|
|
1892
|
-
const token = { key, type: `atom` };
|
|
1893
|
-
if (!parent.valueMap.has(token.key)) {
|
|
1894
|
-
if (token.family) {
|
|
1895
|
-
const family = parent.families.get(token.family.key);
|
|
1896
|
-
if (family) {
|
|
1897
|
-
family(token.family.subKey);
|
|
1898
|
-
}
|
|
1899
|
-
} else {
|
|
1900
|
-
const newAtom = child.atoms.get(token.key);
|
|
1901
|
-
if (!newAtom) {
|
|
1902
|
-
throw new Error(
|
|
1903
|
-
`Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${(_a = child.transactionMeta) == null ? void 0 : _a.update.key}" to store "${parent.config.name}"`
|
|
1904
|
-
);
|
|
1905
|
-
}
|
|
1906
|
-
parent.atoms.set(newAtom.key, newAtom);
|
|
1907
|
-
parent.valueMap.set(newAtom.key, newAtom.default);
|
|
1908
|
-
parent.logger.info(
|
|
1909
|
-
`\u{1F528}`,
|
|
1910
|
-
`transaction`,
|
|
1911
|
-
(_c = (_b = child.transactionMeta) == null ? void 0 : _b.update.key) != null ? _c : `???`,
|
|
1912
|
-
`Adding atom "${newAtom.key}"`
|
|
1913
|
-
);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
setState(token, newValue, parent);
|
|
1917
|
-
}
|
|
1918
|
-
function ingestTransactionUpdate(transactionUpdate, parent, child) {
|
|
1919
|
-
for (const update of transactionUpdate.updates) {
|
|
1920
|
-
if (`newValue` in update) {
|
|
1921
|
-
ingestAtomUpdate(update, parent, child);
|
|
1922
|
-
} else {
|
|
1923
|
-
ingestTransactionUpdate(update, parent, child);
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1911
|
+
|
|
1912
|
+
// internal/src/transaction/apply-transaction.ts
|
|
1927
1913
|
var applyTransaction = (output, store) => {
|
|
1928
1914
|
var _a;
|
|
1929
1915
|
const child = newest(store);
|
|
@@ -1969,7 +1955,7 @@ var applyTransaction = (output, store) => {
|
|
|
1969
1955
|
);
|
|
1970
1956
|
}
|
|
1971
1957
|
}
|
|
1972
|
-
ingestTransactionUpdate(child.transactionMeta.update, parent
|
|
1958
|
+
ingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent);
|
|
1973
1959
|
if (parent.transactionMeta === null) {
|
|
1974
1960
|
const myTransaction = withdraw(
|
|
1975
1961
|
{ key: child.transactionMeta.update.key, type: `transaction` },
|
|
@@ -1987,9 +1973,7 @@ var applyTransaction = (output, store) => {
|
|
|
1987
1973
|
}
|
|
1988
1974
|
parent.on.transactionApplying.next(null);
|
|
1989
1975
|
};
|
|
1990
|
-
|
|
1991
|
-
// internal/src/transaction/build-transaction.ts
|
|
1992
|
-
var buildTransaction = (key, params, store) => {
|
|
1976
|
+
var buildTransaction = (key, params, store, id) => {
|
|
1993
1977
|
const parent = newest(store);
|
|
1994
1978
|
const child = {
|
|
1995
1979
|
parent,
|
|
@@ -2020,14 +2004,17 @@ var buildTransaction = (key, params, store) => {
|
|
|
2020
2004
|
time: Date.now(),
|
|
2021
2005
|
update: {
|
|
2022
2006
|
key,
|
|
2007
|
+
id: id != null ? id : Math.random().toString(36).slice(2),
|
|
2023
2008
|
updates: [],
|
|
2024
2009
|
params,
|
|
2025
2010
|
output: void 0
|
|
2026
2011
|
},
|
|
2027
2012
|
transactors: {
|
|
2028
|
-
get: (token) => getState
|
|
2029
|
-
set: (token, value) => setState
|
|
2030
|
-
run: (token) => runTransaction(token, child)
|
|
2013
|
+
get: (token) => getState(token, child),
|
|
2014
|
+
set: (token, value) => setState(token, value, child),
|
|
2015
|
+
run: (token) => runTransaction(token, child),
|
|
2016
|
+
find: (token, key2) => findInStore(token, key2, child),
|
|
2017
|
+
env: () => getEnvironmentData(child)
|
|
2031
2018
|
}
|
|
2032
2019
|
};
|
|
2033
2020
|
parent.child = child;
|
|
@@ -2045,8 +2032,8 @@ function createTransaction(options, store) {
|
|
|
2045
2032
|
const newTransaction = {
|
|
2046
2033
|
key: options.key,
|
|
2047
2034
|
type: `transaction`,
|
|
2048
|
-
run: (
|
|
2049
|
-
buildTransaction(options.key, params, store);
|
|
2035
|
+
run: (params, id) => {
|
|
2036
|
+
buildTransaction(options.key, params, store, id);
|
|
2050
2037
|
try {
|
|
2051
2038
|
const target2 = newest(store);
|
|
2052
2039
|
const { transactors } = target2.transactionMeta;
|
|
@@ -2072,6 +2059,6 @@ function createTransaction(options, store) {
|
|
|
2072
2059
|
// internal/src/transaction/index.ts
|
|
2073
2060
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
2074
2061
|
|
|
2075
|
-
export { FamilyTracker, Future, IMPLICIT, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelector, createSelectorFamily, createTimeline, createTransaction,
|
|
2062
|
+
export { FamilyTracker, Future, IMPLICIT, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getEnvironmentData, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestSelectorUpdate, ingestTransactionUpdate, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
|
2076
2063
|
//# sourceMappingURL=out.js.map
|
|
2077
2064
|
//# sourceMappingURL=index.js.map
|