atom.io 0.15.1 → 0.15.2
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 +4 -10
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +9 -9
- package/data/dist/index.js +4 -10
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +13 -19
- package/dist/{chunk-S7R5MU6A.js → chunk-K22LR3V6.js} +3 -2
- package/dist/chunk-K22LR3V6.js.map +1 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +1 -1
- package/internal/dist/index.cjs +110 -92
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +7 -4
- package/internal/dist/index.js +110 -92
- package/internal/dist/index.js.map +1 -1
- package/internal/src/caching.ts +9 -7
- package/internal/src/index.ts +5 -0
- package/internal/src/mutable/tracker.ts +35 -17
- package/internal/src/read-or-compute-value.ts +8 -12
- package/internal/src/set-state/copy-mutable-in-transaction.ts +4 -4
- package/internal/src/set-state/set-atom-or-selector.ts +7 -4
- package/internal/src/transaction/apply-transaction.ts +1 -0
- package/package.json +4 -4
- package/react-devtools/dist/index.d.ts +2 -0
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +1 -1
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/src/index.ts +5 -0
- package/src/set-state.ts +3 -1
- package/transceivers/set-rtx/dist/index.cjs +8 -5
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.js +8 -5
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/transceivers/set-rtx/src/set-rtx.ts +8 -5
- package/dist/chunk-S7R5MU6A.js.map +0 -1
package/internal/dist/index.d.ts
CHANGED
|
@@ -219,10 +219,12 @@ declare class Tracker<Mutable extends Transceiver<any>> {
|
|
|
219
219
|
private Update;
|
|
220
220
|
private initializeState;
|
|
221
221
|
private unsubscribeFromInnerValue;
|
|
222
|
+
private unsubscribeFromState;
|
|
222
223
|
private observeCore;
|
|
223
224
|
private updateCore;
|
|
224
225
|
mutableState: MutableAtomToken<Mutable, Json.Serializable>;
|
|
225
226
|
latestUpdateState: AtomToken<typeof this.Update | null>;
|
|
227
|
+
dispose: () => void;
|
|
226
228
|
constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store: Store);
|
|
227
229
|
}
|
|
228
230
|
|
|
@@ -381,8 +383,7 @@ declare class Future<T> extends Promise<T> {
|
|
|
381
383
|
|
|
382
384
|
declare function cacheValue<T>(key: string, value: T, subject: Subject<StateUpdate<unknown>>, store: Store): T;
|
|
383
385
|
declare function cacheValue<T extends Promise<any>>(key: string, value: T, subject: Subject<StateUpdate<unknown>>, store: Store): Future<T>;
|
|
384
|
-
declare const readCachedValue: <T>(
|
|
385
|
-
declare const isValueCached: (key: string, target: Store) => boolean;
|
|
386
|
+
declare const readCachedValue: <T>(token: StateNode<any>, target: Store) => T;
|
|
386
387
|
declare const evictCachedValue: (key: string, target: Store) => void;
|
|
387
388
|
|
|
388
389
|
declare function createAtomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>, store: Store): MutableAtomFamily<T, J, K>;
|
|
@@ -410,7 +411,7 @@ declare class NotFoundError extends Error {
|
|
|
410
411
|
constructor(token: ReadonlySelectorToken<any> | StateToken<any>, store: Store);
|
|
411
412
|
}
|
|
412
413
|
|
|
413
|
-
declare const readOrComputeValue: <T>(state:
|
|
414
|
+
declare const readOrComputeValue: <T>(state: StateNode<T>, target: Store) => T;
|
|
414
415
|
|
|
415
416
|
type Modify<T> = (thing: T) => T;
|
|
416
417
|
declare const become: <T>(nextVersionOfThing: T | Modify<T>) => (originalThing: T) => T;
|
|
@@ -425,4 +426,6 @@ declare const subscribeToTimeline: (token: TimelineToken, handleUpdate: (update:
|
|
|
425
426
|
|
|
426
427
|
declare const subscribeToTransaction: <ƒ extends _n>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, key: string, store: Store$1) => (() => void);
|
|
427
428
|
|
|
428
|
-
|
|
429
|
+
type StateNode<T> = Atom<T> | ReadonlySelector<T> | Selector<T>;
|
|
430
|
+
|
|
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 };
|
package/internal/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getState as getState$1, setState as setState$1, runTransaction } from '../../dist/chunk-
|
|
1
|
+
import { getState as getState$1, setState as setState$1, runTransaction } from '../../dist/chunk-K22LR3V6.js';
|
|
2
2
|
import { Junction } from '../../dist/chunk-NYTGCPHB.js';
|
|
3
3
|
import { __spreadValues, __spreadProps } from '../../dist/chunk-PZLG2HP3.js';
|
|
4
4
|
import { selectJson, stringifyJson, parseJson, selectJsonFamily } from 'atom.io/json';
|
|
@@ -38,6 +38,55 @@ var Future = class extends Promise {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
42
|
+
function copyMutableIfNeeded(atom, transform, origin, target) {
|
|
43
|
+
const originValue = origin.valueMap.get(atom.key);
|
|
44
|
+
const targetValue = target.valueMap.get(atom.key);
|
|
45
|
+
if (originValue === targetValue) {
|
|
46
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
47
|
+
const jsonValue = transform.toJson(originValue);
|
|
48
|
+
const copiedValue = transform.fromJson(jsonValue);
|
|
49
|
+
target.valueMap.set(atom.key, copiedValue);
|
|
50
|
+
new Tracker(atom, origin);
|
|
51
|
+
return copiedValue;
|
|
52
|
+
}
|
|
53
|
+
return targetValue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// internal/src/set-state/copy-mutable-in-transaction.ts
|
|
57
|
+
function copyMutableIfWithinTransaction(oldValue, atom, store) {
|
|
58
|
+
const target = newest(store);
|
|
59
|
+
const parent = target.parent;
|
|
60
|
+
if (parent !== null) {
|
|
61
|
+
if (`family` in atom) {
|
|
62
|
+
const family = parent.families.get(atom.family.key);
|
|
63
|
+
if (family && family.type === `atom_family`) {
|
|
64
|
+
const result = copyMutableFamilyMemberWithinTransaction(
|
|
65
|
+
atom,
|
|
66
|
+
family,
|
|
67
|
+
parent,
|
|
68
|
+
target
|
|
69
|
+
);
|
|
70
|
+
if (result) {
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (`toJson` in atom && `fromJson` in atom) {
|
|
76
|
+
const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
|
|
77
|
+
return copiedValue;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return oldValue;
|
|
81
|
+
}
|
|
82
|
+
function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
|
|
83
|
+
if (`toJson` in family && `fromJson` in family) {
|
|
84
|
+
const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
|
|
85
|
+
return copyCreated;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
41
90
|
// internal/src/caching.ts
|
|
42
91
|
function cacheValue(key, value, subject, target) {
|
|
43
92
|
const currentValue = target.valueMap.get(key);
|
|
@@ -63,11 +112,12 @@ function cacheValue(key, value, subject, target) {
|
|
|
63
112
|
target.valueMap.set(key, value);
|
|
64
113
|
return value;
|
|
65
114
|
}
|
|
66
|
-
var readCachedValue = (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
115
|
+
var readCachedValue = (token, target) => {
|
|
116
|
+
let value = target.valueMap.get(token.key);
|
|
117
|
+
if (token.type === `atom`) {
|
|
118
|
+
value = copyMutableIfWithinTransaction(value, token, target);
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
71
121
|
};
|
|
72
122
|
var evictCachedValue = (key, target) => {
|
|
73
123
|
const currentValue = target.valueMap.get(key);
|
|
@@ -82,17 +132,17 @@ var evictCachedValue = (key, target) => {
|
|
|
82
132
|
};
|
|
83
133
|
|
|
84
134
|
// internal/src/read-or-compute-value.ts
|
|
85
|
-
var readOrComputeValue = (state,
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
return readCachedValue(state
|
|
135
|
+
var readOrComputeValue = (state, target) => {
|
|
136
|
+
if (target.valueMap.has(state.key)) {
|
|
137
|
+
target.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
138
|
+
return readCachedValue(state, target);
|
|
89
139
|
}
|
|
90
140
|
if (state.type !== `atom`) {
|
|
91
|
-
|
|
141
|
+
target.logger.info(`\u{1F9EE}`, state.type, state.key, `computing value`);
|
|
92
142
|
return state.get();
|
|
93
143
|
}
|
|
94
144
|
const fallback = state.default instanceof Function ? state.default() : state.default;
|
|
95
|
-
|
|
145
|
+
target.logger.info(
|
|
96
146
|
`\u{1F481}`,
|
|
97
147
|
`atom`,
|
|
98
148
|
state.key,
|
|
@@ -200,55 +250,6 @@ var StatefulSubject = class extends Subject {
|
|
|
200
250
|
}
|
|
201
251
|
};
|
|
202
252
|
|
|
203
|
-
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
204
|
-
function copyMutableIfNeeded(atom, transform, origin, target) {
|
|
205
|
-
const originValue = origin.valueMap.get(atom.key);
|
|
206
|
-
const targetValue = target.valueMap.get(atom.key);
|
|
207
|
-
if (originValue === targetValue) {
|
|
208
|
-
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
209
|
-
const jsonValue = transform.toJson(originValue);
|
|
210
|
-
const copiedValue = transform.fromJson(jsonValue);
|
|
211
|
-
target.valueMap.set(atom.key, copiedValue);
|
|
212
|
-
new Tracker(atom, origin);
|
|
213
|
-
return copiedValue;
|
|
214
|
-
}
|
|
215
|
-
return targetValue;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// internal/src/set-state/copy-mutable-in-transaction.ts
|
|
219
|
-
function copyMutableIfWithinTransaction(oldValue, atom, store) {
|
|
220
|
-
const target = newest(store);
|
|
221
|
-
const parent = target.parent;
|
|
222
|
-
if (parent !== null) {
|
|
223
|
-
if (`toJson` in atom && `fromJson` in atom) {
|
|
224
|
-
const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
|
|
225
|
-
return copiedValue;
|
|
226
|
-
}
|
|
227
|
-
if (`family` in atom) {
|
|
228
|
-
const family = parent.families.get(atom.family.key);
|
|
229
|
-
if (family && family.type === `atom_family`) {
|
|
230
|
-
const result = copyMutableFamilyMemberWithinTransaction(
|
|
231
|
-
atom,
|
|
232
|
-
family,
|
|
233
|
-
parent,
|
|
234
|
-
target
|
|
235
|
-
);
|
|
236
|
-
if (result) {
|
|
237
|
-
return result;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return oldValue;
|
|
243
|
-
}
|
|
244
|
-
function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
|
|
245
|
-
if (`toJson` in family && `fromJson` in family) {
|
|
246
|
-
const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
|
|
247
|
-
return copyCreated;
|
|
248
|
-
}
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
253
|
// internal/src/set-state/emit-update.ts
|
|
253
254
|
var emitUpdate = (state, update, store) => {
|
|
254
255
|
store.logger.info(
|
|
@@ -361,10 +362,13 @@ var setAtom = (atom, next, target) => {
|
|
|
361
362
|
|
|
362
363
|
// internal/src/set-state/set-atom-or-selector.ts
|
|
363
364
|
var setAtomOrSelector = (state, value, store) => {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
365
|
+
switch (state.type) {
|
|
366
|
+
case `atom`:
|
|
367
|
+
setAtom(state, value, store);
|
|
368
|
+
break;
|
|
369
|
+
case `selector`:
|
|
370
|
+
state.set(value);
|
|
371
|
+
break;
|
|
368
372
|
}
|
|
369
373
|
};
|
|
370
374
|
|
|
@@ -925,15 +929,6 @@ var subscribeToTransaction = (token, handleUpdate, key, store) => {
|
|
|
925
929
|
};
|
|
926
930
|
};
|
|
927
931
|
var Tracker = class {
|
|
928
|
-
constructor(mutableState, store) {
|
|
929
|
-
this.unsubscribeFromInnerValue = null;
|
|
930
|
-
this.mutableState = mutableState;
|
|
931
|
-
const target = newest(store);
|
|
932
|
-
this.latestUpdateState = this.initializeState(mutableState, target);
|
|
933
|
-
this.observeCore(mutableState, this.latestUpdateState, target);
|
|
934
|
-
this.updateCore(mutableState, this.latestUpdateState, target);
|
|
935
|
-
target.trackers.set(mutableState.key, this);
|
|
936
|
-
}
|
|
937
932
|
initializeState(mutableState, store) {
|
|
938
933
|
var _a;
|
|
939
934
|
const latestUpdateStateKey = `*${mutableState.key}`;
|
|
@@ -963,32 +958,41 @@ var Tracker = class {
|
|
|
963
958
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
964
959
|
`tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
|
|
965
960
|
(update) => {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
961
|
+
if (target.operation.open) {
|
|
962
|
+
const unsubscribe = target.subject.operationStatus.subscribe(
|
|
963
|
+
mutableState.key,
|
|
964
|
+
() => {
|
|
965
|
+
unsubscribe();
|
|
966
|
+
setState(latestUpdateState, update, target);
|
|
967
|
+
}
|
|
968
|
+
);
|
|
969
|
+
} else {
|
|
970
|
+
setState(mutableState, (current) => current, target);
|
|
971
|
+
setState(latestUpdateState, update, target);
|
|
972
|
+
}
|
|
973
973
|
}
|
|
974
974
|
);
|
|
975
|
-
subscribeToState(
|
|
975
|
+
this.unsubscribeFromState = subscribeToState(
|
|
976
976
|
mutableState,
|
|
977
977
|
(update) => {
|
|
978
|
-
var _a;
|
|
979
978
|
if (update.newValue !== update.oldValue) {
|
|
980
|
-
|
|
979
|
+
this.unsubscribeFromInnerValue();
|
|
981
980
|
const target2 = newest(store);
|
|
982
981
|
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
983
982
|
`tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
|
|
984
983
|
(update2) => {
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
984
|
+
if (target2.operation.open) {
|
|
985
|
+
const unsubscribe = target2.subject.operationStatus.subscribe(
|
|
986
|
+
mutableState.key,
|
|
987
|
+
() => {
|
|
988
|
+
unsubscribe();
|
|
989
|
+
setState(latestUpdateState, update2, target2);
|
|
990
|
+
}
|
|
991
|
+
);
|
|
992
|
+
} else {
|
|
993
|
+
setState(mutableState, (current) => current, target2);
|
|
994
|
+
setState(latestUpdateState, update2, target2);
|
|
995
|
+
}
|
|
992
996
|
}
|
|
993
997
|
);
|
|
994
998
|
}
|
|
@@ -1051,6 +1055,19 @@ var Tracker = class {
|
|
|
1051
1055
|
store
|
|
1052
1056
|
);
|
|
1053
1057
|
}
|
|
1058
|
+
constructor(mutableState, store) {
|
|
1059
|
+
this.mutableState = mutableState;
|
|
1060
|
+
const target = newest(store);
|
|
1061
|
+
this.latestUpdateState = this.initializeState(mutableState, target);
|
|
1062
|
+
this.observeCore(mutableState, this.latestUpdateState, target);
|
|
1063
|
+
this.updateCore(mutableState, this.latestUpdateState, target);
|
|
1064
|
+
target.trackers.set(mutableState.key, this);
|
|
1065
|
+
this.dispose = () => {
|
|
1066
|
+
this.unsubscribeFromInnerValue();
|
|
1067
|
+
this.unsubscribeFromState();
|
|
1068
|
+
target.trackers.delete(mutableState.key);
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1054
1071
|
};
|
|
1055
1072
|
|
|
1056
1073
|
// internal/src/mutable/create-mutable-atom.ts
|
|
@@ -1938,6 +1955,7 @@ var applyTransaction = (output, store) => {
|
|
|
1938
1955
|
const atom = child.atoms.get(mutableKey);
|
|
1939
1956
|
atom == null ? void 0 : atom.install(parent);
|
|
1940
1957
|
}
|
|
1958
|
+
tracker.dispose();
|
|
1941
1959
|
}
|
|
1942
1960
|
for (const atom of child.atoms.values()) {
|
|
1943
1961
|
if (!parent.atoms.has(atom.key)) {
|
|
@@ -2054,6 +2072,6 @@ function createTransaction(options, store) {
|
|
|
2054
2072
|
// internal/src/transaction/index.ts
|
|
2055
2073
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
2056
2074
|
|
|
2057
|
-
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, deleteAtom2 as deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver,
|
|
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, deleteAtom2 as 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 };
|
|
2058
2076
|
//# sourceMappingURL=out.js.map
|
|
2059
2077
|
//# sourceMappingURL=index.js.map
|