atom.io 0.15.4 → 0.15.5
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 +82 -143
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +29 -17
- package/internal/dist/index.js +73 -89
- 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/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
|
|
@@ -654,24 +653,27 @@ var registerSelector = (selectorKey, store) => ({
|
|
|
654
653
|
updateSelectorAtoms(selectorKey, dependency, store);
|
|
655
654
|
return dependencyValue;
|
|
656
655
|
},
|
|
657
|
-
set: (
|
|
658
|
-
const state = withdraw(
|
|
656
|
+
set: (WritableToken, newValue) => {
|
|
657
|
+
const state = withdraw(WritableToken, store);
|
|
659
658
|
if (state === void 0) {
|
|
660
659
|
throw new Error(
|
|
661
|
-
`State "${
|
|
660
|
+
`State "${WritableToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
662
661
|
);
|
|
663
662
|
}
|
|
664
663
|
setAtomOrSelector(state, newValue, store);
|
|
665
|
-
}
|
|
664
|
+
},
|
|
665
|
+
find: (token, key) => findInStore(token, key, store)
|
|
666
666
|
});
|
|
667
667
|
|
|
668
668
|
// internal/src/selector/create-read-write-selector.ts
|
|
669
669
|
var createReadWriteSelector = (options, family, store) => {
|
|
670
670
|
const target = newest(store);
|
|
671
671
|
const subject = new Subject();
|
|
672
|
-
const
|
|
672
|
+
const transactors = registerSelector(options.key, store);
|
|
673
|
+
const { find, get } = transactors;
|
|
674
|
+
const readonlyTransactors = { find, get };
|
|
673
675
|
const getSelf = () => {
|
|
674
|
-
const value = options.get(
|
|
676
|
+
const value = options.get(readonlyTransactors);
|
|
675
677
|
cacheValue(options.key, value, subject, newest(store));
|
|
676
678
|
return value;
|
|
677
679
|
};
|
|
@@ -693,7 +695,7 @@ var createReadWriteSelector = (options, family, store) => {
|
|
|
693
695
|
if (target.transactionMeta === null) {
|
|
694
696
|
subject.next({ newValue, oldValue });
|
|
695
697
|
}
|
|
696
|
-
options.set(
|
|
698
|
+
options.set(transactors, newValue);
|
|
697
699
|
};
|
|
698
700
|
const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
699
701
|
subject,
|
|
@@ -720,9 +722,9 @@ var createReadWriteSelector = (options, family, store) => {
|
|
|
720
722
|
var createReadonlySelector = (options, family, store) => {
|
|
721
723
|
const target = newest(store);
|
|
722
724
|
const subject = new Subject();
|
|
723
|
-
const { get } = registerSelector(options.key, store);
|
|
725
|
+
const { get, find } = registerSelector(options.key, store);
|
|
724
726
|
const getSelf = () => {
|
|
725
|
-
const value = options.get({ get });
|
|
727
|
+
const value = options.get({ get, find });
|
|
726
728
|
cacheValue(options.key, value, subject, store);
|
|
727
729
|
return value;
|
|
728
730
|
};
|
|
@@ -1405,7 +1407,7 @@ function createAtom(options, family, store) {
|
|
|
1405
1407
|
}
|
|
1406
1408
|
|
|
1407
1409
|
// internal/src/atom/delete-atom.ts
|
|
1408
|
-
function
|
|
1410
|
+
function deleteAtom(atomToken, store) {
|
|
1409
1411
|
var _a, _b;
|
|
1410
1412
|
const target = newest(store);
|
|
1411
1413
|
const { key } = atomToken;
|
|
@@ -1436,6 +1438,39 @@ function deleteAtom2(atomToken, store) {
|
|
|
1436
1438
|
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1437
1439
|
}
|
|
1438
1440
|
|
|
1441
|
+
// internal/src/get-environment-data.ts
|
|
1442
|
+
function getEnvironmentData(store) {
|
|
1443
|
+
return {
|
|
1444
|
+
runtime: typeof window === `undefined` ? typeof global === `object` ? `node` : `unknown` : `browser`,
|
|
1445
|
+
store
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
function ingestAtomUpdate(applying, atomUpdate, store) {
|
|
1449
|
+
const { key, newValue, oldValue } = atomUpdate;
|
|
1450
|
+
const value = applying === `newValue` ? newValue : oldValue;
|
|
1451
|
+
setState({ key, type: `atom` }, value, store);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// internal/src/ingest-updates/ingest-selector-update.ts
|
|
1455
|
+
function ingestSelectorUpdate(applying, selectorUpdate, store) {
|
|
1456
|
+
const updates = applying === `newValue` ? selectorUpdate.atomUpdates : [...selectorUpdate.atomUpdates].reverse();
|
|
1457
|
+
for (const atomUpdate of updates) {
|
|
1458
|
+
ingestAtomUpdate(applying, atomUpdate, store);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
// internal/src/ingest-updates/ingest-transaction-update.ts
|
|
1463
|
+
function ingestTransactionUpdate(applying, transactionUpdate, store) {
|
|
1464
|
+
const updates = applying === `newValue` ? transactionUpdate.updates : [...transactionUpdate.updates].reverse();
|
|
1465
|
+
for (const updateFromTransaction of updates) {
|
|
1466
|
+
if (`newValue` in updateFromTransaction) {
|
|
1467
|
+
ingestAtomUpdate(applying, updateFromTransaction, store);
|
|
1468
|
+
} else {
|
|
1469
|
+
ingestTransactionUpdate(applying, updateFromTransaction, store);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1439
1474
|
// internal/src/lazy-map.ts
|
|
1440
1475
|
var LazyMap = class extends Map {
|
|
1441
1476
|
constructor(source) {
|
|
@@ -1789,10 +1824,11 @@ function createTimeline(options, store, data) {
|
|
|
1789
1824
|
store.on.timelineCreation.next(token);
|
|
1790
1825
|
return token;
|
|
1791
1826
|
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1827
|
+
|
|
1828
|
+
// internal/src/timeline/time-travel.ts
|
|
1829
|
+
var timeTravel = (action, token, store) => {
|
|
1794
1830
|
store.logger.info(
|
|
1795
|
-
|
|
1831
|
+
action === `redo` ? `\u23E9` : `\u23EA`,
|
|
1796
1832
|
`timeline`,
|
|
1797
1833
|
token.key,
|
|
1798
1834
|
action
|
|
@@ -1807,53 +1843,36 @@ var timeTravel = (direction, token, store) => {
|
|
|
1807
1843
|
);
|
|
1808
1844
|
return;
|
|
1809
1845
|
}
|
|
1810
|
-
if (
|
|
1846
|
+
if (action === `redo` && timelineData.at === timelineData.history.length || action === `undo` && timelineData.at === 0) {
|
|
1811
1847
|
store.logger.warn(
|
|
1812
1848
|
`\u{1F481}`,
|
|
1813
1849
|
`timeline`,
|
|
1814
1850
|
token.key,
|
|
1815
|
-
`Failed to ${action} at the ${
|
|
1851
|
+
`Failed to ${action} at the ${action === `redo` ? `end` : `beginning`} of timeline "${token.key}". There is nothing to ${action}.`
|
|
1816
1852
|
);
|
|
1817
1853
|
return;
|
|
1818
1854
|
}
|
|
1819
|
-
timelineData.timeTraveling =
|
|
1820
|
-
if (
|
|
1855
|
+
timelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`;
|
|
1856
|
+
if (action === `undo`) {
|
|
1821
1857
|
--timelineData.at;
|
|
1822
1858
|
}
|
|
1823
1859
|
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
|
-
};
|
|
1860
|
+
const applying = action === `redo` ? `newValue` : `oldValue`;
|
|
1839
1861
|
switch (update.type) {
|
|
1840
1862
|
case `atom_update`: {
|
|
1841
|
-
|
|
1863
|
+
ingestAtomUpdate(applying, update, store);
|
|
1842
1864
|
break;
|
|
1843
1865
|
}
|
|
1844
1866
|
case `selector_update`: {
|
|
1845
|
-
|
|
1846
|
-
for (const atomUpdate of updates) {
|
|
1847
|
-
updateValues(atomUpdate);
|
|
1848
|
-
}
|
|
1867
|
+
ingestSelectorUpdate(applying, update, store);
|
|
1849
1868
|
break;
|
|
1850
1869
|
}
|
|
1851
1870
|
case `transaction_update`: {
|
|
1852
|
-
|
|
1871
|
+
ingestTransactionUpdate(applying, update, store);
|
|
1853
1872
|
break;
|
|
1854
1873
|
}
|
|
1855
1874
|
}
|
|
1856
|
-
if (
|
|
1875
|
+
if (action === `redo`) {
|
|
1857
1876
|
++timelineData.at;
|
|
1858
1877
|
}
|
|
1859
1878
|
timelineData.subject.next(action);
|
|
@@ -1886,44 +1905,8 @@ var abortTransaction = (store) => {
|
|
|
1886
1905
|
);
|
|
1887
1906
|
target.parent.child = null;
|
|
1888
1907
|
};
|
|
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
|
-
}
|
|
1908
|
+
|
|
1909
|
+
// internal/src/transaction/apply-transaction.ts
|
|
1927
1910
|
var applyTransaction = (output, store) => {
|
|
1928
1911
|
var _a;
|
|
1929
1912
|
const child = newest(store);
|
|
@@ -1969,7 +1952,7 @@ var applyTransaction = (output, store) => {
|
|
|
1969
1952
|
);
|
|
1970
1953
|
}
|
|
1971
1954
|
}
|
|
1972
|
-
ingestTransactionUpdate(child.transactionMeta.update, parent
|
|
1955
|
+
ingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent);
|
|
1973
1956
|
if (parent.transactionMeta === null) {
|
|
1974
1957
|
const myTransaction = withdraw(
|
|
1975
1958
|
{ key: child.transactionMeta.update.key, type: `transaction` },
|
|
@@ -1987,9 +1970,7 @@ var applyTransaction = (output, store) => {
|
|
|
1987
1970
|
}
|
|
1988
1971
|
parent.on.transactionApplying.next(null);
|
|
1989
1972
|
};
|
|
1990
|
-
|
|
1991
|
-
// internal/src/transaction/build-transaction.ts
|
|
1992
|
-
var buildTransaction = (key, params, store) => {
|
|
1973
|
+
var buildTransaction = (key, params, store, id) => {
|
|
1993
1974
|
const parent = newest(store);
|
|
1994
1975
|
const child = {
|
|
1995
1976
|
parent,
|
|
@@ -2020,14 +2001,17 @@ var buildTransaction = (key, params, store) => {
|
|
|
2020
2001
|
time: Date.now(),
|
|
2021
2002
|
update: {
|
|
2022
2003
|
key,
|
|
2004
|
+
id: id != null ? id : Math.random().toString(36).slice(2),
|
|
2023
2005
|
updates: [],
|
|
2024
2006
|
params,
|
|
2025
2007
|
output: void 0
|
|
2026
2008
|
},
|
|
2027
2009
|
transactors: {
|
|
2028
|
-
get: (token) => getState
|
|
2029
|
-
set: (token, value) => setState
|
|
2030
|
-
run: (token) => runTransaction(token, child)
|
|
2010
|
+
get: (token) => getState(token, child),
|
|
2011
|
+
set: (token, value) => setState(token, value, child),
|
|
2012
|
+
run: (token) => runTransaction(token, child),
|
|
2013
|
+
find: (token, key2) => findInStore(token, key2, child),
|
|
2014
|
+
env: () => getEnvironmentData(child)
|
|
2031
2015
|
}
|
|
2032
2016
|
};
|
|
2033
2017
|
parent.child = child;
|
|
@@ -2045,8 +2029,8 @@ function createTransaction(options, store) {
|
|
|
2045
2029
|
const newTransaction = {
|
|
2046
2030
|
key: options.key,
|
|
2047
2031
|
type: `transaction`,
|
|
2048
|
-
run: (
|
|
2049
|
-
buildTransaction(options.key, params, store);
|
|
2032
|
+
run: (params, id) => {
|
|
2033
|
+
buildTransaction(options.key, params, store, id);
|
|
2050
2034
|
try {
|
|
2051
2035
|
const target2 = newest(store);
|
|
2052
2036
|
const { transactors } = target2.transactionMeta;
|
|
@@ -2072,6 +2056,6 @@ function createTransaction(options, store) {
|
|
|
2072
2056
|
// internal/src/transaction/index.ts
|
|
2073
2057
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
2074
2058
|
|
|
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,
|
|
2059
|
+
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
2060
|
//# sourceMappingURL=out.js.map
|
|
2077
2061
|
//# sourceMappingURL=index.js.map
|