atom.io 0.20.2 → 0.21.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.
- package/data/dist/index.cjs +1 -1
- package/data/dist/index.js +1 -1
- package/data/src/join.ts +2 -2
- package/dist/{chunk-SMZRGPN6.js → chunk-KGZGBCYS.js} +2 -2
- package/dist/chunk-PNIHPILQ.js +8 -0
- package/dist/{chunk-2AIFLP2B.js → chunk-RT43TVKP.js} +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -7
- package/internal/dist/index.cjs +45 -33
- package/internal/dist/index.d.ts +12 -8
- package/internal/dist/index.js +44 -32
- package/internal/src/atom/create-regular-atom.ts +1 -1
- package/internal/src/atom/dispose-atom.ts +42 -0
- package/internal/src/atom/index.ts +1 -1
- package/internal/src/operation.ts +5 -4
- package/internal/src/selector/{delete-selector.ts → dispose-selector.ts} +3 -2
- package/internal/src/selector/index.ts +1 -1
- package/internal/src/set-state/set-into-store.ts +9 -3
- package/internal/src/store/deposit.ts +5 -0
- package/internal/src/store/store.ts +5 -1
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
- package/internal/src/subscribe/subscribe-to-state.ts +1 -1
- package/introspection/dist/index.cjs +250 -106
- package/introspection/dist/index.d.ts +43 -6
- package/introspection/dist/index.js +225 -83
- package/introspection/src/attach-atom-index.ts +68 -47
- package/introspection/src/attach-selector-index.ts +76 -59
- package/introspection/src/auditor.ts +135 -0
- package/introspection/src/index.ts +8 -18
- package/package.json +14 -14
- package/react-devtools/dist/index.cjs +3 -3
- package/react-devtools/dist/index.d.ts +5 -5
- package/react-devtools/dist/index.js +4 -4
- package/react-devtools/src/StateIndex.tsx +8 -27
- package/realtime-client/dist/index.cjs +1 -1
- package/realtime-client/dist/index.js +1 -1
- package/realtime-client/src/sync-continuity.ts +2 -2
- package/realtime-react/dist/index.cjs +1 -1
- package/realtime-react/dist/index.js +1 -1
- package/realtime-server/dist/index.cjs +2 -2
- package/realtime-server/dist/index.js +1 -1
- package/realtime-testing/dist/index.cjs +4 -4
- package/realtime-testing/dist/index.js +1 -1
- package/src/dispose.ts +3 -3
- package/src/logger.ts +4 -2
- package/internal/src/atom/delete-atom.ts +0 -40
package/data/dist/index.cjs
CHANGED
|
@@ -443,7 +443,7 @@ var Join = class _Join {
|
|
|
443
443
|
set(find(contentAtoms, key), content);
|
|
444
444
|
};
|
|
445
445
|
const deleteContent = ({ find }, key) => {
|
|
446
|
-
atom_io.
|
|
446
|
+
atom_io.disposeState(find(contentAtoms, key));
|
|
447
447
|
};
|
|
448
448
|
const externalStoreWithContentConfiguration = {
|
|
449
449
|
getContent: (contentKey) => {
|
package/data/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Join, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join } from '../../dist/chunk-
|
|
1
|
+
export { Join, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join } from '../../dist/chunk-KGZGBCYS.js';
|
|
2
2
|
import '../../dist/chunk-FTONNX2R.js';
|
|
3
3
|
import '../../dist/chunk-F2X4B4VY.js';
|
|
4
4
|
import { createStandaloneSelector, findInStore, IMPLICIT, createRegularAtom, createRegularAtomFamily, createSelectorFamily } from 'atom.io/internal';
|
package/data/src/join.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
Transactors,
|
|
11
11
|
Write,
|
|
12
12
|
} from "atom.io"
|
|
13
|
-
import {
|
|
13
|
+
import { disposeState, findState, getState, setState } from "atom.io"
|
|
14
14
|
import type { Store } from "atom.io/internal"
|
|
15
15
|
import {
|
|
16
16
|
createMutableAtomFamily,
|
|
@@ -343,7 +343,7 @@ export class Join<
|
|
|
343
343
|
set(find(contentAtoms, key), content)
|
|
344
344
|
}
|
|
345
345
|
const deleteContent: Write<(key: string) => void> = ({ find }, key) => {
|
|
346
|
-
|
|
346
|
+
disposeState(find(contentAtoms, key))
|
|
347
347
|
}
|
|
348
348
|
const externalStoreWithContentConfiguration = {
|
|
349
349
|
getContent: (contentKey: string) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Junction } from './chunk-FTONNX2R.js';
|
|
2
|
-
import {
|
|
2
|
+
import { disposeState } from 'atom.io';
|
|
3
3
|
import { getFromStore, setIntoStore, findInStore, createMutableAtomFamily, createRegularAtomFamily, IMPLICIT, newest, isChildStore, createSelectorFamily, getJsonFamily } from 'atom.io/internal';
|
|
4
4
|
import { SetRTX } from 'atom.io/transceivers/set-rtx';
|
|
5
5
|
|
|
@@ -166,7 +166,7 @@ var Join = class _Join {
|
|
|
166
166
|
set(find(contentAtoms, key), content);
|
|
167
167
|
};
|
|
168
168
|
const deleteContent = ({ find }, key) => {
|
|
169
|
-
|
|
169
|
+
disposeState(find(contentAtoms, key));
|
|
170
170
|
};
|
|
171
171
|
const externalStoreWithContentConfiguration = {
|
|
172
172
|
getContent: (contentKey) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFromStore, assignTransactionToContinuity, subscribeToTransaction, setIntoStore,
|
|
1
|
+
import { getFromStore, assignTransactionToContinuity, subscribeToTransaction, setIntoStore, disposeAtom, setEpochNumberOfContinuity, getEpochNumberOfContinuity, isRootStore, ingestTransactionUpdate, getJsonToken, actUponStore } from 'atom.io/internal';
|
|
2
2
|
import { optimisticUpdateQueue, confirmedUpdateQueue } from 'atom.io/realtime-client';
|
|
3
3
|
|
|
4
4
|
// realtime-client/src/sync-continuity.ts
|
|
@@ -313,7 +313,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
313
313
|
`conceal:${continuityKey}`,
|
|
314
314
|
(concealed) => {
|
|
315
315
|
for (const token of concealed) {
|
|
316
|
-
|
|
316
|
+
disposeAtom(token, store);
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
);
|
package/dist/index.cjs
CHANGED
|
@@ -29,15 +29,15 @@ function atom(options) {
|
|
|
29
29
|
function atomFamily(options) {
|
|
30
30
|
return Internal.createAtomFamily(options, Internal.IMPLICIT.STORE);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function disposeState(token, store = Internal__namespace.IMPLICIT.STORE) {
|
|
33
33
|
switch (token.type) {
|
|
34
34
|
case `atom`:
|
|
35
35
|
case `mutable_atom`:
|
|
36
|
-
Internal__namespace.
|
|
36
|
+
Internal__namespace.disposeAtom(token, store);
|
|
37
37
|
break;
|
|
38
38
|
case `selector`:
|
|
39
39
|
case `readonly_selector`:
|
|
40
|
-
Internal__namespace.
|
|
40
|
+
Internal__namespace.disposeSelector(token, store);
|
|
41
41
|
break;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -170,7 +170,7 @@ exports.Silo = Silo;
|
|
|
170
170
|
exports.atom = atom;
|
|
171
171
|
exports.atomFamily = atomFamily;
|
|
172
172
|
exports.belongsTo = belongsTo;
|
|
173
|
-
exports.
|
|
173
|
+
exports.disposeState = disposeState;
|
|
174
174
|
exports.findState = findState;
|
|
175
175
|
exports.getState = getState;
|
|
176
176
|
exports.isToken = isToken;
|
package/dist/index.d.ts
CHANGED
|
@@ -153,7 +153,7 @@ type SelectorFamilyToken<T, K extends Json.Serializable> = ReadonlySelectorFamil
|
|
|
153
153
|
declare function selectorFamily<T, K extends Json.Serializable>(options: WritableSelectorFamilyOptions<T, K>): WritableSelectorFamilyTokenWithCall<T, K>;
|
|
154
154
|
declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamilyTokenWithCall<T, K>;
|
|
155
155
|
|
|
156
|
-
declare function
|
|
156
|
+
declare function disposeState(token: ReadableToken<any>, store?: Internal.Store): void;
|
|
157
157
|
|
|
158
158
|
declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable, Key extends K>(token: MutableAtomFamilyToken$1<T, J, K>, key: Key): MutableAtomToken$1<T, J>;
|
|
159
159
|
declare function findState<T, K extends Json.Serializable, Key extends K>(token: RegularAtomFamilyToken$1<T, K>, key: Key): RegularAtomToken$1<T>;
|
|
@@ -174,9 +174,11 @@ declare const LoggerIconDictionary: {
|
|
|
174
174
|
readonly "\u23F9\uFE0F": "Time-travel complete";
|
|
175
175
|
readonly "\u2705": "Realtime transaction success";
|
|
176
176
|
readonly "\u2728": "Computation complete";
|
|
177
|
-
readonly "\u2757": "Must wait to proceed with attempted action";
|
|
178
177
|
readonly "\u274C": "Conflict prevents attempted action";
|
|
179
178
|
readonly "\u2B55": "Operation start";
|
|
179
|
+
readonly "\uD83D\uDD34": "Operation complete";
|
|
180
|
+
readonly "\u2757": "Operation blocked";
|
|
181
|
+
readonly "\uD83D\uDFE2": "Operation unblocked";
|
|
180
182
|
readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
|
|
181
183
|
readonly "\uD83D\uDC40": "Subscription added";
|
|
182
184
|
readonly "\uD83D\uDC4B": "Greeting";
|
|
@@ -195,7 +197,6 @@ declare const LoggerIconDictionary: {
|
|
|
195
197
|
readonly "\uD83D\uDD25": "Delete state";
|
|
196
198
|
readonly "\uD83D\uDD27": "Create mutable atom";
|
|
197
199
|
readonly "\uD83D\uDD28": "Create immutable atom";
|
|
198
|
-
readonly "\uD83D\uDD34": "Operation complete";
|
|
199
200
|
readonly "\uD83D\uDDD1": "Evict cached value";
|
|
200
201
|
readonly "\uD83D\uDE48": "Subscription canceled";
|
|
201
202
|
readonly "\uD83D\uDE80": "Performance measure";
|
|
@@ -335,4 +336,4 @@ type FamilyMetadata = {
|
|
|
335
336
|
subKey: string;
|
|
336
337
|
};
|
|
337
338
|
|
|
338
|
-
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomToken, type Effectors, type FamilyMetadata, type Func, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomFamilyTokenWithCall, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorFamilyTokenWithCall, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomFamilyTokenWithCall, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorFamilyTokenWithCall, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo,
|
|
339
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomToken, type Effectors, type FamilyMetadata, type Func, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomFamilyTokenWithCall, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorFamilyTokenWithCall, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomFamilyTokenWithCall, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorFamilyTokenWithCall, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, findState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { getState } from './chunk-PNIHPILQ.js';
|
|
1
2
|
import './chunk-F2X4B4VY.js';
|
|
2
3
|
import * as Internal from 'atom.io/internal';
|
|
3
4
|
import { createStandaloneAtom, IMPLICIT, createAtomFamily, findInStore, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, getFromStore, setIntoStore, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary, actUponStore } from 'atom.io/internal';
|
|
@@ -8,15 +9,15 @@ function atom(options) {
|
|
|
8
9
|
function atomFamily(options) {
|
|
9
10
|
return createAtomFamily(options, IMPLICIT.STORE);
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
+
function disposeState(token, store = Internal.IMPLICIT.STORE) {
|
|
12
13
|
switch (token.type) {
|
|
13
14
|
case `atom`:
|
|
14
15
|
case `mutable_atom`:
|
|
15
|
-
Internal.
|
|
16
|
+
Internal.disposeAtom(token, store);
|
|
16
17
|
break;
|
|
17
18
|
case `selector`:
|
|
18
19
|
case `readonly_selector`:
|
|
19
|
-
Internal.
|
|
20
|
+
Internal.disposeSelector(token, store);
|
|
20
21
|
break;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -24,9 +25,6 @@ function findState(token, key) {
|
|
|
24
25
|
const state = findInStore(token, key, IMPLICIT.STORE);
|
|
25
26
|
return state;
|
|
26
27
|
}
|
|
27
|
-
function getState(token) {
|
|
28
|
-
return Internal.getFromStore(token, Internal.IMPLICIT.STORE);
|
|
29
|
-
}
|
|
30
28
|
|
|
31
29
|
// src/logger.ts
|
|
32
30
|
var LOG_LEVELS = [`info`, `warn`, `error`];
|
|
@@ -143,4 +141,4 @@ function belongsTo(family, unknownToken) {
|
|
|
143
141
|
return family.key === ((_a = unknownToken.family) == null ? void 0 : _a.key);
|
|
144
142
|
}
|
|
145
143
|
|
|
146
|
-
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo,
|
|
144
|
+
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, findState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
package/internal/dist/index.cjs
CHANGED
|
@@ -436,9 +436,11 @@ var Store = class {
|
|
|
436
436
|
);
|
|
437
437
|
this.on = {
|
|
438
438
|
atomCreation: new Subject(),
|
|
439
|
+
atomDisposal: new Subject(),
|
|
439
440
|
selectorCreation: new Subject(),
|
|
440
|
-
|
|
441
|
+
selectorDisposal: new Subject(),
|
|
441
442
|
timelineCreation: new Subject(),
|
|
443
|
+
transactionCreation: new Subject(),
|
|
442
444
|
transactionApplying: new StatefulSubject(
|
|
443
445
|
null
|
|
444
446
|
),
|
|
@@ -774,13 +776,14 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
|
|
|
774
776
|
// internal/src/operation.ts
|
|
775
777
|
var openOperation = (token, store) => {
|
|
776
778
|
if (store.operation.open) {
|
|
777
|
-
|
|
779
|
+
const rejectionTime = performance.now();
|
|
780
|
+
store.logger.info(
|
|
778
781
|
`\u2757`,
|
|
779
782
|
token.type,
|
|
780
783
|
token.key,
|
|
781
|
-
`
|
|
784
|
+
`deferring setState at T-${rejectionTime} until setState for "${store.operation.token.key}" is done`
|
|
782
785
|
);
|
|
783
|
-
return
|
|
786
|
+
return rejectionTime;
|
|
784
787
|
}
|
|
785
788
|
store.operation = {
|
|
786
789
|
open: true,
|
|
@@ -989,12 +992,18 @@ var setAtomOrSelector = (state, value, store) => {
|
|
|
989
992
|
|
|
990
993
|
// internal/src/set-state/set-into-store.ts
|
|
991
994
|
function setIntoStore(token, value, store) {
|
|
992
|
-
const
|
|
993
|
-
if (
|
|
995
|
+
const rejectionTime = openOperation(token, store);
|
|
996
|
+
if (rejectionTime) {
|
|
994
997
|
const unsubscribe = store.on.operationClose.subscribe(
|
|
995
|
-
`waiting to set "${token.key}"`,
|
|
998
|
+
`waiting to set "${token.key}" at T-${rejectionTime}`,
|
|
996
999
|
() => {
|
|
997
1000
|
unsubscribe();
|
|
1001
|
+
store.logger.info(
|
|
1002
|
+
`\u{1F7E2}`,
|
|
1003
|
+
token.type,
|
|
1004
|
+
token.key,
|
|
1005
|
+
`resuming deferred setState from T-${rejectionTime}`
|
|
1006
|
+
);
|
|
998
1007
|
setIntoStore(token, value, store);
|
|
999
1008
|
}
|
|
1000
1009
|
);
|
|
@@ -1213,8 +1222,8 @@ function createStandaloneSelector(options, store) {
|
|
|
1213
1222
|
return createReadonlySelector(options, void 0, store);
|
|
1214
1223
|
}
|
|
1215
1224
|
|
|
1216
|
-
// internal/src/selector/
|
|
1217
|
-
function
|
|
1225
|
+
// internal/src/selector/dispose-selector.ts
|
|
1226
|
+
function disposeSelector(selectorToken, store) {
|
|
1218
1227
|
const target = newest(store);
|
|
1219
1228
|
const { key } = selectorToken;
|
|
1220
1229
|
switch (selectorToken.type) {
|
|
@@ -1235,11 +1244,12 @@ function deleteSelector(selectorToken, store) {
|
|
|
1235
1244
|
);
|
|
1236
1245
|
for (const downstreamToken of downstreamTokens) {
|
|
1237
1246
|
if (downstreamToken) {
|
|
1238
|
-
|
|
1247
|
+
disposeSelector(downstreamToken, store);
|
|
1239
1248
|
}
|
|
1240
1249
|
}
|
|
1241
1250
|
target.selectorGraph.delete(key);
|
|
1242
1251
|
store.logger.info(`\u{1F525}`, selectorToken.type, key, `deleted`);
|
|
1252
|
+
store.on.selectorDisposal.next(selectorToken);
|
|
1243
1253
|
}
|
|
1244
1254
|
|
|
1245
1255
|
// internal/src/subscribe/recall-state.ts
|
|
@@ -1307,8 +1317,8 @@ function subscribeToState(token, handleUpdate, key, store) {
|
|
|
1307
1317
|
updateHandler = (update) => {
|
|
1308
1318
|
if (dependencyUnsubFunctions) {
|
|
1309
1319
|
dependencyUnsubFunctions.length = 0;
|
|
1320
|
+
dependencyUnsubFunctions.push(...subscribeToRootAtoms(state, store));
|
|
1310
1321
|
}
|
|
1311
|
-
dependencyUnsubFunctions = subscribeToRootAtoms(state, store);
|
|
1312
1322
|
handleUpdate(update);
|
|
1313
1323
|
};
|
|
1314
1324
|
}
|
|
@@ -1868,8 +1878,8 @@ function createStandaloneAtom(options, store) {
|
|
|
1868
1878
|
return createRegularAtom(options, void 0, store);
|
|
1869
1879
|
}
|
|
1870
1880
|
|
|
1871
|
-
// internal/src/atom/
|
|
1872
|
-
function
|
|
1881
|
+
// internal/src/atom/dispose-atom.ts
|
|
1882
|
+
function disposeAtom(atomToken, store) {
|
|
1873
1883
|
var _a, _b;
|
|
1874
1884
|
const target = newest(store);
|
|
1875
1885
|
const { key } = atomToken;
|
|
@@ -1881,27 +1891,29 @@ function deleteAtom(atomToken, store) {
|
|
|
1881
1891
|
key,
|
|
1882
1892
|
`Tried to delete atom, but it does not exist in the store.`
|
|
1883
1893
|
);
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
+
} else {
|
|
1895
|
+
(_a = atom.cleanup) == null ? void 0 : _a.call(atom);
|
|
1896
|
+
target.atoms.delete(key);
|
|
1897
|
+
target.valueMap.delete(key);
|
|
1898
|
+
const selectorKeys = target.selectorAtoms.getRelatedKeys(key);
|
|
1899
|
+
if (selectorKeys) {
|
|
1900
|
+
for (const selectorKey of selectorKeys) {
|
|
1901
|
+
const token = (_b = target.selectors.get(selectorKey)) != null ? _b : target.readonlySelectors.get(selectorKey);
|
|
1902
|
+
if (token) {
|
|
1903
|
+
disposeSelector(token, store);
|
|
1904
|
+
}
|
|
1894
1905
|
}
|
|
1895
1906
|
}
|
|
1907
|
+
target.selectorAtoms.delete(key);
|
|
1908
|
+
target.atomsThatAreDefault.delete(key);
|
|
1909
|
+
target.timelineAtoms.delete(key);
|
|
1910
|
+
if (atomToken.type === `mutable_atom`) {
|
|
1911
|
+
const updateToken = getUpdateToken(atomToken);
|
|
1912
|
+
disposeAtom(updateToken, store);
|
|
1913
|
+
}
|
|
1914
|
+
store.logger.info(`\u{1F525}`, `atom`, key, `deleted`);
|
|
1915
|
+
store.on.atomDisposal.next(atomToken);
|
|
1896
1916
|
}
|
|
1897
|
-
target.selectorAtoms.delete(key);
|
|
1898
|
-
target.atomsThatAreDefault.delete(key);
|
|
1899
|
-
target.timelineAtoms.delete(key);
|
|
1900
|
-
if (atomToken.type === `mutable_atom`) {
|
|
1901
|
-
const updateToken = getUpdateToken(atomToken);
|
|
1902
|
-
deleteAtom(updateToken, store);
|
|
1903
|
-
}
|
|
1904
|
-
store.logger.info(`\u{1F525}`, `atom`, key, `deleted`);
|
|
1905
1917
|
}
|
|
1906
1918
|
|
|
1907
1919
|
// internal/src/get-environment-data.ts
|
|
@@ -2590,9 +2602,9 @@ exports.createStandaloneSelector = createStandaloneSelector;
|
|
|
2590
2602
|
exports.createTimeline = createTimeline;
|
|
2591
2603
|
exports.createTransaction = createTransaction;
|
|
2592
2604
|
exports.createWritableSelector = createWritableSelector;
|
|
2593
|
-
exports.deleteAtom = deleteAtom;
|
|
2594
|
-
exports.deleteSelector = deleteSelector;
|
|
2595
2605
|
exports.deposit = deposit;
|
|
2606
|
+
exports.disposeAtom = disposeAtom;
|
|
2607
|
+
exports.disposeSelector = disposeSelector;
|
|
2596
2608
|
exports.evictCachedValue = evictCachedValue;
|
|
2597
2609
|
exports.findInStore = findInStore;
|
|
2598
2610
|
exports.getContinuityKey = getContinuityKey;
|
package/internal/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Func, TransactionToken, TransactionUpdate, TransactionOptions, TransactorsWithRunAndEnv, RegularAtomToken, MutableAtomToken, WritableSelectorToken, ReadonlySelectorToken, WritableToken, ReadableToken, TimelineManageable, StateUpdate, TokenType, FamilyMetadata, TimelineUpdate, TimelineOptions, TimelineToken,
|
|
1
|
+
import { Func, TransactionToken, TransactionUpdate, TransactionOptions, TransactorsWithRunAndEnv, RegularAtomToken, MutableAtomToken, AtomToken, WritableSelectorToken, ReadonlySelectorToken, SelectorToken, WritableToken, ReadableToken, TimelineManageable, StateUpdate, TokenType, FamilyMetadata, TimelineUpdate, TimelineOptions, TimelineToken, WritableSelectorFamily, MutableAtomFamily, RegularAtomFamily, ReadonlySelectorFamily, AtomIOLogger, Logger, AtomFamily, SelectorFamily, RegularAtomFamilyToken, MutableAtomFamilyToken, AtomFamilyToken, ReadonlySelectorFamilyToken, WritableSelectorFamilyToken, SelectorFamilyToken, MutableAtomOptions, MutableAtomFamilyOptions, RegularAtomOptions, RegularAtomFamilyOptions, ReadonlySelectorFamilyOptions, WritableSelectorFamilyOptions, WritableFamilyToken, ReadableFamilyToken, KeyedStateUpdate, ReadonlySelectorOptions, WritableSelectorOptions, Transactors, UpdateHandler, TransactionUpdateHandler } from 'atom.io';
|
|
2
2
|
import { Json, JsonInterface } from 'atom.io/json';
|
|
3
3
|
|
|
4
4
|
type primitive = boolean | number | string | null;
|
|
@@ -141,8 +141,10 @@ type TransactionEpoch = {
|
|
|
141
141
|
|
|
142
142
|
declare function deposit<T>(state: RegularAtom<T>): RegularAtomToken<T>;
|
|
143
143
|
declare function deposit<T extends Transceiver<any>>(state: MutableAtom<T, any>): MutableAtomToken<T, any>;
|
|
144
|
+
declare function deposit<T>(state: Atom<T>): AtomToken<T>;
|
|
144
145
|
declare function deposit<T>(state: WritableSelector<T>): WritableSelectorToken<T>;
|
|
145
146
|
declare function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>;
|
|
147
|
+
declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
|
|
146
148
|
declare function deposit<T>(state: WritableState<T>): WritableToken<T>;
|
|
147
149
|
declare function deposit<T extends Func>(state: Transaction<T>): TransactionToken<T>;
|
|
148
150
|
declare function deposit<T>(state: ReadableState<T>): ReadableToken<T>;
|
|
@@ -162,7 +164,7 @@ type OperationProgress = {
|
|
|
162
164
|
time: number;
|
|
163
165
|
token: WritableToken<any>;
|
|
164
166
|
};
|
|
165
|
-
declare const openOperation: (token: WritableToken<any>, store: Store) =>
|
|
167
|
+
declare const openOperation: (token: WritableToken<any>, store: Store) => number | undefined;
|
|
166
168
|
declare const closeOperation: (store: Store) => void;
|
|
167
169
|
declare const isDone: (key: string, store: Store) => boolean;
|
|
168
170
|
declare const markDone: (key: string, store: Store) => void;
|
|
@@ -221,9 +223,11 @@ declare class Store implements Lineage {
|
|
|
221
223
|
}>;
|
|
222
224
|
on: {
|
|
223
225
|
atomCreation: Subject<AtomToken<unknown>>;
|
|
226
|
+
atomDisposal: Subject<AtomToken<unknown>>;
|
|
224
227
|
selectorCreation: Subject<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
|
|
225
|
-
|
|
228
|
+
selectorDisposal: Subject<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
|
|
226
229
|
timelineCreation: Subject<TimelineToken<unknown>>;
|
|
230
|
+
transactionCreation: Subject<TransactionToken<Func>>;
|
|
227
231
|
transactionApplying: StatefulSubject<TransactionProgress<Func> | null>;
|
|
228
232
|
operationClose: Subject<OperationProgress>;
|
|
229
233
|
};
|
|
@@ -317,12 +321,12 @@ declare class FamilyTracker<Core extends Transceiver<any>, FamilyMemberKey exten
|
|
|
317
321
|
|
|
318
322
|
declare function arbitrary(random?: () => number): string;
|
|
319
323
|
|
|
320
|
-
declare function createRegularAtom<T>(options:
|
|
324
|
+
declare function createRegularAtom<T>(options: RegularAtomOptions<T>, family: FamilyMetadata | undefined, store: Store): RegularAtomToken<T>;
|
|
321
325
|
|
|
322
326
|
declare function createStandaloneAtom<T>(options: RegularAtomOptions<T>, store: Store): RegularAtomToken<T>;
|
|
323
327
|
declare function createStandaloneAtom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>, store: Store): MutableAtomToken<T, J>;
|
|
324
328
|
|
|
325
|
-
declare function
|
|
329
|
+
declare function disposeAtom(atomToken: AtomToken<unknown>, store: Store): void;
|
|
326
330
|
|
|
327
331
|
declare const isAtomDefault: (key: string, store: Store) => boolean;
|
|
328
332
|
declare const markAtomAsDefault: (key: string, store: Store) => void;
|
|
@@ -429,7 +433,7 @@ declare function createStandaloneSelector<T>(options: ReadonlySelectorOptions<T>
|
|
|
429
433
|
|
|
430
434
|
declare const createWritableSelector: <T>(options: WritableSelectorOptions<T>, family: FamilyMetadata | undefined, store: Store) => WritableSelectorToken<T>;
|
|
431
435
|
|
|
432
|
-
declare function
|
|
436
|
+
declare function disposeSelector(selectorToken: ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>, store: Store): void;
|
|
433
437
|
|
|
434
438
|
declare const getSelectorDependencyKeys: (key: string, store: Store) => (AtomKey<unknown> | ReadonlySelectorKey<unknown> | SelectorKey<unknown>)[];
|
|
435
439
|
|
|
@@ -447,7 +451,7 @@ declare const setAtomOrSelector: <T>(state: WritableState<T>, value: T | ((oldVa
|
|
|
447
451
|
|
|
448
452
|
declare function setIntoStore<T, New extends T>(token: WritableToken<T>, value: New | ((oldValue: T) => New), store: Store): void;
|
|
449
453
|
|
|
450
|
-
declare const subscribeToRootAtoms: <T>(selector: Selector<T>, store: Store) => (() => void)[]
|
|
454
|
+
declare const subscribeToRootAtoms: <T>(selector: Selector<T>, store: Store) => (() => void)[];
|
|
451
455
|
|
|
452
456
|
declare function subscribeToState<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key: string, store: Store): () => void;
|
|
453
457
|
|
|
@@ -488,4 +492,4 @@ type Selector<T> = ReadonlySelector<T> | WritableSelector<T>;
|
|
|
488
492
|
type WritableState<T> = Atom<T> | WritableSelector<T>;
|
|
489
493
|
type ReadableState<T> = Atom<T> | Selector<T>;
|
|
490
494
|
|
|
491
|
-
export { type Atom, type AtomIOState, type AtomKey, type ChildStore, type EnvironmentData, FamilyTracker, Future, IMPLICIT, LazyMap, type Lineage, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadableState, type ReadonlySelector, type ReadonlySelectorKey, type RegularAtom, type RootStore, 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 TransactionEpoch, type TransactionPhase, type TransactionProgress, type Transceiver, type TransceiverMode, type Withdrawable, type WritableSelector, type WritableState, abortTransaction, actUponStore, addAtomToTimeline, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector,
|
|
495
|
+
export { type Atom, type AtomIOState, type AtomKey, type ChildStore, type EnvironmentData, FamilyTracker, Future, IMPLICIT, LazyMap, type Lineage, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadableState, type ReadonlySelector, type ReadonlySelectorKey, type RegularAtom, type RootStore, 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 TransactionEpoch, type TransactionPhase, type TransactionProgress, type Transceiver, type TransceiverMode, type Withdrawable, type WritableSelector, type WritableState, abortTransaction, actUponStore, addAtomToTimeline, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deposit, disposeAtom, disposeSelector, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, ingestAtomUpdate, ingestSelectorUpdate, ingestTransactionUpdate, isAtomDefault, isAtomKey, isChildStore, isDone, isMutable, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawOrCreate };
|
package/internal/dist/index.js
CHANGED
|
@@ -158,9 +158,11 @@ var Store = class {
|
|
|
158
158
|
);
|
|
159
159
|
this.on = {
|
|
160
160
|
atomCreation: new Subject(),
|
|
161
|
+
atomDisposal: new Subject(),
|
|
161
162
|
selectorCreation: new Subject(),
|
|
162
|
-
|
|
163
|
+
selectorDisposal: new Subject(),
|
|
163
164
|
timelineCreation: new Subject(),
|
|
165
|
+
transactionCreation: new Subject(),
|
|
164
166
|
transactionApplying: new StatefulSubject(
|
|
165
167
|
null
|
|
166
168
|
),
|
|
@@ -496,13 +498,14 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
|
|
|
496
498
|
// internal/src/operation.ts
|
|
497
499
|
var openOperation = (token, store) => {
|
|
498
500
|
if (store.operation.open) {
|
|
499
|
-
|
|
501
|
+
const rejectionTime = performance.now();
|
|
502
|
+
store.logger.info(
|
|
500
503
|
`\u2757`,
|
|
501
504
|
token.type,
|
|
502
505
|
token.key,
|
|
503
|
-
`
|
|
506
|
+
`deferring setState at T-${rejectionTime} until setState for "${store.operation.token.key}" is done`
|
|
504
507
|
);
|
|
505
|
-
return
|
|
508
|
+
return rejectionTime;
|
|
506
509
|
}
|
|
507
510
|
store.operation = {
|
|
508
511
|
open: true,
|
|
@@ -711,12 +714,18 @@ var setAtomOrSelector = (state, value, store) => {
|
|
|
711
714
|
|
|
712
715
|
// internal/src/set-state/set-into-store.ts
|
|
713
716
|
function setIntoStore(token, value, store) {
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
717
|
+
const rejectionTime = openOperation(token, store);
|
|
718
|
+
if (rejectionTime) {
|
|
716
719
|
const unsubscribe = store.on.operationClose.subscribe(
|
|
717
|
-
`waiting to set "${token.key}"`,
|
|
720
|
+
`waiting to set "${token.key}" at T-${rejectionTime}`,
|
|
718
721
|
() => {
|
|
719
722
|
unsubscribe();
|
|
723
|
+
store.logger.info(
|
|
724
|
+
`\u{1F7E2}`,
|
|
725
|
+
token.type,
|
|
726
|
+
token.key,
|
|
727
|
+
`resuming deferred setState from T-${rejectionTime}`
|
|
728
|
+
);
|
|
720
729
|
setIntoStore(token, value, store);
|
|
721
730
|
}
|
|
722
731
|
);
|
|
@@ -935,8 +944,8 @@ function createStandaloneSelector(options, store) {
|
|
|
935
944
|
return createReadonlySelector(options, void 0, store);
|
|
936
945
|
}
|
|
937
946
|
|
|
938
|
-
// internal/src/selector/
|
|
939
|
-
function
|
|
947
|
+
// internal/src/selector/dispose-selector.ts
|
|
948
|
+
function disposeSelector(selectorToken, store) {
|
|
940
949
|
const target = newest(store);
|
|
941
950
|
const { key } = selectorToken;
|
|
942
951
|
switch (selectorToken.type) {
|
|
@@ -957,11 +966,12 @@ function deleteSelector(selectorToken, store) {
|
|
|
957
966
|
);
|
|
958
967
|
for (const downstreamToken of downstreamTokens) {
|
|
959
968
|
if (downstreamToken) {
|
|
960
|
-
|
|
969
|
+
disposeSelector(downstreamToken, store);
|
|
961
970
|
}
|
|
962
971
|
}
|
|
963
972
|
target.selectorGraph.delete(key);
|
|
964
973
|
store.logger.info(`\u{1F525}`, selectorToken.type, key, `deleted`);
|
|
974
|
+
store.on.selectorDisposal.next(selectorToken);
|
|
965
975
|
}
|
|
966
976
|
|
|
967
977
|
// internal/src/subscribe/recall-state.ts
|
|
@@ -1029,8 +1039,8 @@ function subscribeToState(token, handleUpdate, key, store) {
|
|
|
1029
1039
|
updateHandler = (update) => {
|
|
1030
1040
|
if (dependencyUnsubFunctions) {
|
|
1031
1041
|
dependencyUnsubFunctions.length = 0;
|
|
1042
|
+
dependencyUnsubFunctions.push(...subscribeToRootAtoms(state, store));
|
|
1032
1043
|
}
|
|
1033
|
-
dependencyUnsubFunctions = subscribeToRootAtoms(state, store);
|
|
1034
1044
|
handleUpdate(update);
|
|
1035
1045
|
};
|
|
1036
1046
|
}
|
|
@@ -1590,8 +1600,8 @@ function createStandaloneAtom(options, store) {
|
|
|
1590
1600
|
return createRegularAtom(options, void 0, store);
|
|
1591
1601
|
}
|
|
1592
1602
|
|
|
1593
|
-
// internal/src/atom/
|
|
1594
|
-
function
|
|
1603
|
+
// internal/src/atom/dispose-atom.ts
|
|
1604
|
+
function disposeAtom(atomToken, store) {
|
|
1595
1605
|
var _a, _b;
|
|
1596
1606
|
const target = newest(store);
|
|
1597
1607
|
const { key } = atomToken;
|
|
@@ -1603,27 +1613,29 @@ function deleteAtom(atomToken, store) {
|
|
|
1603
1613
|
key,
|
|
1604
1614
|
`Tried to delete atom, but it does not exist in the store.`
|
|
1605
1615
|
);
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
+
} else {
|
|
1617
|
+
(_a = atom.cleanup) == null ? void 0 : _a.call(atom);
|
|
1618
|
+
target.atoms.delete(key);
|
|
1619
|
+
target.valueMap.delete(key);
|
|
1620
|
+
const selectorKeys = target.selectorAtoms.getRelatedKeys(key);
|
|
1621
|
+
if (selectorKeys) {
|
|
1622
|
+
for (const selectorKey of selectorKeys) {
|
|
1623
|
+
const token = (_b = target.selectors.get(selectorKey)) != null ? _b : target.readonlySelectors.get(selectorKey);
|
|
1624
|
+
if (token) {
|
|
1625
|
+
disposeSelector(token, store);
|
|
1626
|
+
}
|
|
1616
1627
|
}
|
|
1617
1628
|
}
|
|
1629
|
+
target.selectorAtoms.delete(key);
|
|
1630
|
+
target.atomsThatAreDefault.delete(key);
|
|
1631
|
+
target.timelineAtoms.delete(key);
|
|
1632
|
+
if (atomToken.type === `mutable_atom`) {
|
|
1633
|
+
const updateToken = getUpdateToken(atomToken);
|
|
1634
|
+
disposeAtom(updateToken, store);
|
|
1635
|
+
}
|
|
1636
|
+
store.logger.info(`\u{1F525}`, `atom`, key, `deleted`);
|
|
1637
|
+
store.on.atomDisposal.next(atomToken);
|
|
1618
1638
|
}
|
|
1619
|
-
target.selectorAtoms.delete(key);
|
|
1620
|
-
target.atomsThatAreDefault.delete(key);
|
|
1621
|
-
target.timelineAtoms.delete(key);
|
|
1622
|
-
if (atomToken.type === `mutable_atom`) {
|
|
1623
|
-
const updateToken = getUpdateToken(atomToken);
|
|
1624
|
-
deleteAtom(updateToken, store);
|
|
1625
|
-
}
|
|
1626
|
-
store.logger.info(`\u{1F525}`, `atom`, key, `deleted`);
|
|
1627
1639
|
}
|
|
1628
1640
|
|
|
1629
1641
|
// internal/src/get-environment-data.ts
|
|
@@ -2278,4 +2290,4 @@ function getEpochNumberOfAction(transactionKey, store) {
|
|
|
2278
2290
|
// internal/src/transaction/index.ts
|
|
2279
2291
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
2280
2292
|
|
|
2281
|
-
export { FamilyTracker, Future, IMPLICIT, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, addAtomToTimeline, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector,
|
|
2293
|
+
export { FamilyTracker, Future, IMPLICIT, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, addAtomToTimeline, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deposit, disposeAtom, disposeSelector, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, ingestAtomUpdate, ingestSelectorUpdate, ingestTransactionUpdate, isAtomDefault, isAtomKey, isChildStore, isDone, isMutable, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawOrCreate };
|
|
@@ -16,7 +16,7 @@ import { subscribeToState } from "../subscribe"
|
|
|
16
16
|
import { markAtomAsDefault } from "./is-default"
|
|
17
17
|
|
|
18
18
|
export function createRegularAtom<T>(
|
|
19
|
-
options:
|
|
19
|
+
options: RegularAtomOptions<T>,
|
|
20
20
|
family: FamilyMetadata | undefined,
|
|
21
21
|
store: Store,
|
|
22
22
|
): RegularAtomToken<T> {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AtomToken } from "atom.io"
|
|
2
|
+
|
|
3
|
+
import type { Store } from ".."
|
|
4
|
+
import { disposeSelector, getUpdateToken, newest } from ".."
|
|
5
|
+
|
|
6
|
+
export function disposeAtom(atomToken: AtomToken<unknown>, store: Store): void {
|
|
7
|
+
const target = newest(store)
|
|
8
|
+
const { key } = atomToken
|
|
9
|
+
const atom = target.atoms.get(key)
|
|
10
|
+
if (!atom) {
|
|
11
|
+
store.logger.error(
|
|
12
|
+
`❌`,
|
|
13
|
+
`atom`,
|
|
14
|
+
key,
|
|
15
|
+
`Tried to delete atom, but it does not exist in the store.`,
|
|
16
|
+
)
|
|
17
|
+
} else {
|
|
18
|
+
atom.cleanup?.()
|
|
19
|
+
target.atoms.delete(key)
|
|
20
|
+
target.valueMap.delete(key)
|
|
21
|
+
const selectorKeys = target.selectorAtoms.getRelatedKeys(key)
|
|
22
|
+
if (selectorKeys) {
|
|
23
|
+
for (const selectorKey of selectorKeys) {
|
|
24
|
+
const token =
|
|
25
|
+
target.selectors.get(selectorKey) ??
|
|
26
|
+
target.readonlySelectors.get(selectorKey)
|
|
27
|
+
if (token) {
|
|
28
|
+
disposeSelector(token, store)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
target.selectorAtoms.delete(key)
|
|
33
|
+
target.atomsThatAreDefault.delete(key)
|
|
34
|
+
target.timelineAtoms.delete(key)
|
|
35
|
+
if (atomToken.type === `mutable_atom`) {
|
|
36
|
+
const updateToken = getUpdateToken(atomToken)
|
|
37
|
+
disposeAtom(updateToken, store)
|
|
38
|
+
}
|
|
39
|
+
store.logger.info(`🔥`, `atom`, key, `deleted`)
|
|
40
|
+
store.on.atomDisposal.next(atomToken)
|
|
41
|
+
}
|
|
42
|
+
}
|