atom.io 0.9.9 → 0.9.10
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/internal/dist/index.d.mts +23 -7
- package/internal/dist/index.d.ts +23 -7
- package/internal/dist/index.js +223 -228
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +219 -227
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/atom/is-default.ts +2 -2
- package/internal/src/caching.ts +6 -4
- package/internal/src/index.ts +1 -0
- package/internal/src/keys.ts +30 -0
- package/internal/src/selector/get-selector-dependency-keys.ts +20 -0
- package/internal/src/selector/index.ts +1 -1
- package/internal/src/selector/trace-selector-atoms.ts +26 -26
- package/internal/src/selector/update-selector-atoms.ts +4 -4
- package/internal/src/store/index.ts +0 -1
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +4 -5
- package/package.json +2 -2
- package/internal/src/selector/lookup-selector-sources.ts +0 -20
- package/internal/src/store/lookup.ts +0 -26
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transactors, FamilyMetadata, SelectorOptions, SelectorToken, ReadonlySelectorOptions, ReadonlySelectorToken, StateToken, ƒn, TransactionUpdate, TransactionOptions, TransactionToken, AtomToken, MutableAtomOptions, MutableAtomToken, MutableAtomFamilyOptions, MutableAtomFamily, AtomFamily, StateUpdate, TimelineUpdate, TimelineOptions, TimelineToken, ReadonlySelectorFamily, SelectorFamily, Logger, AtomOptions, AtomFamilyOptions, ReadonlySelectorFamilyOptions, SelectorFamilyOptions } from 'atom.io';
|
|
2
2
|
import { Json } from 'atom.io/json';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type AtomKey<T> = string & {
|
|
5
|
+
__atomKey?: never;
|
|
6
|
+
__brand?: T;
|
|
7
|
+
};
|
|
8
|
+
type SelectorKey<T> = string & {
|
|
9
|
+
__selectorKey?: never;
|
|
10
|
+
__brand?: T;
|
|
11
|
+
};
|
|
12
|
+
type ReadonlySelectorKey<T> = string & {
|
|
13
|
+
__readonlySelectorKey?: never;
|
|
14
|
+
__brand?: T;
|
|
15
|
+
};
|
|
16
|
+
declare const isAtomKey: (key: string, store: Store) => key is AtomKey<unknown>;
|
|
17
|
+
declare const isSelectorKey: (key: string, store: Store) => key is SelectorKey<unknown>;
|
|
18
|
+
declare const isReadonlySelectorKey: (key: string, store: Store) => key is ReadonlySelectorKey<unknown>;
|
|
19
|
+
type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>;
|
|
20
|
+
declare const isStateKey: (key: string, store: Store) => key is StateKey<unknown>;
|
|
21
|
+
|
|
22
|
+
declare const getSelectorDependencyKeys: (key: string, store: Store) => (AtomKey<unknown> | ReadonlySelectorKey<unknown> | SelectorKey<unknown>)[];
|
|
5
23
|
|
|
6
24
|
declare const registerSelector: (selectorKey: string, store?: Store) => Transactors;
|
|
7
25
|
|
|
@@ -39,8 +57,8 @@ type ReadonlySelector<T> = {
|
|
|
39
57
|
declare function createSelector<T>(options: SelectorOptions<T>, family?: FamilyMetadata, store?: Store): SelectorToken<T>;
|
|
40
58
|
declare function createSelector<T>(options: ReadonlySelectorOptions<T>, family?: FamilyMetadata, store?: Store): ReadonlySelectorToken<T>;
|
|
41
59
|
|
|
42
|
-
declare const traceSelectorAtoms: (selectorKey: string,
|
|
43
|
-
declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) =>
|
|
60
|
+
declare const traceSelectorAtoms: (selectorKey: string, directDependencyKey: StateKey<unknown>, store: Store) => AtomKey<unknown>[];
|
|
61
|
+
declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) => AtomKey<unknown>[];
|
|
44
62
|
|
|
45
63
|
declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>, store: Store) => void;
|
|
46
64
|
|
|
@@ -283,8 +301,6 @@ declare const IMPLICIT: {
|
|
|
283
301
|
};
|
|
284
302
|
declare const clearStore: (store?: Store) => void;
|
|
285
303
|
|
|
286
|
-
declare function lookup(key: string, store: Store): AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>;
|
|
287
|
-
|
|
288
304
|
declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | undefined;
|
|
289
305
|
declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T> | undefined;
|
|
290
306
|
declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T> | undefined;
|
|
@@ -357,4 +373,4 @@ declare const setState__INTERNAL: <T>(state: Atom<T> | Selector<T>, value: T | (
|
|
|
357
373
|
|
|
358
374
|
declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
|
|
359
375
|
|
|
360
|
-
export { type Atom, FamilyTracker, type Fated, Future, IMPLICIT, type Loadable, type Modify, type MutableAtom, type OperationProgress, type ReadonlySelector, type Selector, type Signal, Store, type StoreCore, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionIdle, type TransactionPhase, type TransactionStatus, type TransactionUpdateInProgress, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault,
|
|
376
|
+
export { type Atom, type AtomKey, FamilyTracker, type Fated, Future, IMPLICIT, type Loadable, type Modify, type MutableAtom, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, Store, type StoreCore, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionIdle, type TransactionPhase, type TransactionStatus, type TransactionUpdateInProgress, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getSelectorDependencyKeys, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomKey, isAtomMutable, isAtomTokenMutable, isDone, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
package/internal/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transactors, FamilyMetadata, SelectorOptions, SelectorToken, ReadonlySelectorOptions, ReadonlySelectorToken, StateToken, ƒn, TransactionUpdate, TransactionOptions, TransactionToken, AtomToken, MutableAtomOptions, MutableAtomToken, MutableAtomFamilyOptions, MutableAtomFamily, AtomFamily, StateUpdate, TimelineUpdate, TimelineOptions, TimelineToken, ReadonlySelectorFamily, SelectorFamily, Logger, AtomOptions, AtomFamilyOptions, ReadonlySelectorFamilyOptions, SelectorFamilyOptions } from 'atom.io';
|
|
2
2
|
import { Json } from 'atom.io/json';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type AtomKey<T> = string & {
|
|
5
|
+
__atomKey?: never;
|
|
6
|
+
__brand?: T;
|
|
7
|
+
};
|
|
8
|
+
type SelectorKey<T> = string & {
|
|
9
|
+
__selectorKey?: never;
|
|
10
|
+
__brand?: T;
|
|
11
|
+
};
|
|
12
|
+
type ReadonlySelectorKey<T> = string & {
|
|
13
|
+
__readonlySelectorKey?: never;
|
|
14
|
+
__brand?: T;
|
|
15
|
+
};
|
|
16
|
+
declare const isAtomKey: (key: string, store: Store) => key is AtomKey<unknown>;
|
|
17
|
+
declare const isSelectorKey: (key: string, store: Store) => key is SelectorKey<unknown>;
|
|
18
|
+
declare const isReadonlySelectorKey: (key: string, store: Store) => key is ReadonlySelectorKey<unknown>;
|
|
19
|
+
type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>;
|
|
20
|
+
declare const isStateKey: (key: string, store: Store) => key is StateKey<unknown>;
|
|
21
|
+
|
|
22
|
+
declare const getSelectorDependencyKeys: (key: string, store: Store) => (AtomKey<unknown> | ReadonlySelectorKey<unknown> | SelectorKey<unknown>)[];
|
|
5
23
|
|
|
6
24
|
declare const registerSelector: (selectorKey: string, store?: Store) => Transactors;
|
|
7
25
|
|
|
@@ -39,8 +57,8 @@ type ReadonlySelector<T> = {
|
|
|
39
57
|
declare function createSelector<T>(options: SelectorOptions<T>, family?: FamilyMetadata, store?: Store): SelectorToken<T>;
|
|
40
58
|
declare function createSelector<T>(options: ReadonlySelectorOptions<T>, family?: FamilyMetadata, store?: Store): ReadonlySelectorToken<T>;
|
|
41
59
|
|
|
42
|
-
declare const traceSelectorAtoms: (selectorKey: string,
|
|
43
|
-
declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) =>
|
|
60
|
+
declare const traceSelectorAtoms: (selectorKey: string, directDependencyKey: StateKey<unknown>, store: Store) => AtomKey<unknown>[];
|
|
61
|
+
declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) => AtomKey<unknown>[];
|
|
44
62
|
|
|
45
63
|
declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>, store: Store) => void;
|
|
46
64
|
|
|
@@ -283,8 +301,6 @@ declare const IMPLICIT: {
|
|
|
283
301
|
};
|
|
284
302
|
declare const clearStore: (store?: Store) => void;
|
|
285
303
|
|
|
286
|
-
declare function lookup(key: string, store: Store): AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>;
|
|
287
|
-
|
|
288
304
|
declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | undefined;
|
|
289
305
|
declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T> | undefined;
|
|
290
306
|
declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T> | undefined;
|
|
@@ -357,4 +373,4 @@ declare const setState__INTERNAL: <T>(state: Atom<T> | Selector<T>, value: T | (
|
|
|
357
373
|
|
|
358
374
|
declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
|
|
359
375
|
|
|
360
|
-
export { type Atom, FamilyTracker, type Fated, Future, IMPLICIT, type Loadable, type Modify, type MutableAtom, type OperationProgress, type ReadonlySelector, type Selector, type Signal, Store, type StoreCore, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionIdle, type TransactionPhase, type TransactionStatus, type TransactionUpdateInProgress, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault,
|
|
376
|
+
export { type Atom, type AtomKey, FamilyTracker, type Fated, Future, IMPLICIT, type Loadable, type Modify, type MutableAtom, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, Store, type StoreCore, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionIdle, type TransactionPhase, type TransactionStatus, type TransactionUpdateInProgress, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getSelectorDependencyKeys, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomKey, isAtomMutable, isAtomTokenMutable, isDone, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
package/internal/dist/index.js
CHANGED
|
@@ -54,94 +54,6 @@ function deposit(state) {
|
|
|
54
54
|
return token;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
// src/subject.ts
|
|
58
|
-
var Subject = class {
|
|
59
|
-
constructor() {
|
|
60
|
-
this.subscribers = /* @__PURE__ */ new Map();
|
|
61
|
-
}
|
|
62
|
-
subscribe(key, subscriber) {
|
|
63
|
-
this.subscribers.set(key, subscriber);
|
|
64
|
-
const unsubscribe = () => this.unsubscribe(key);
|
|
65
|
-
return unsubscribe;
|
|
66
|
-
}
|
|
67
|
-
unsubscribe(key) {
|
|
68
|
-
this.subscribers.delete(key);
|
|
69
|
-
}
|
|
70
|
-
next(value) {
|
|
71
|
-
for (const subscriber of this.subscribers.values()) {
|
|
72
|
-
subscriber(value);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/transaction/abort-transaction.ts
|
|
78
|
-
var abortTransaction = (store) => {
|
|
79
|
-
var _a, _b;
|
|
80
|
-
if (store.transactionStatus.phase === `idle`) {
|
|
81
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
82
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
83
|
-
);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
store.transactionStatus = { phase: `idle` };
|
|
87
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(`\u{1FA82}`, `transaction fail`);
|
|
88
|
-
};
|
|
89
|
-
var applyTransaction = (output, store) => {
|
|
90
|
-
var _a, _b, _c, _d, _e;
|
|
91
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
92
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
93
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
94
|
-
);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
store.transactionStatus.phase = `applying`;
|
|
98
|
-
store.transactionStatus.output = output;
|
|
99
|
-
const { atomUpdates } = store.transactionStatus;
|
|
100
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
101
|
-
`\u{1F6C3} applying transaction "${store.transactionStatus.key}" with ${atomUpdates.length} updates.`
|
|
102
|
-
);
|
|
103
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(`\u{1F6C3} the updates are:`, atomUpdates);
|
|
104
|
-
for (const { key, newValue } of atomUpdates) {
|
|
105
|
-
const token = { key, type: `atom` };
|
|
106
|
-
if (!store.valueMap.has(token.key)) {
|
|
107
|
-
if (token.family) {
|
|
108
|
-
const family = store.families.get(token.family.key);
|
|
109
|
-
if (family) {
|
|
110
|
-
family(token.family.subKey);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
const newAtom = store.transactionStatus.core.atoms.get(token.key);
|
|
114
|
-
if (!newAtom) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
`Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
store.atoms.set(newAtom.key, newAtom);
|
|
120
|
-
store.valueMap.set(newAtom.key, newAtom.default);
|
|
121
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
atom_io.setState(token, newValue, store);
|
|
125
|
-
}
|
|
126
|
-
const myTransaction = withdraw(
|
|
127
|
-
{ key: store.transactionStatus.key, type: `transaction` },
|
|
128
|
-
store
|
|
129
|
-
);
|
|
130
|
-
if (myTransaction === void 0) {
|
|
131
|
-
throw new Error(
|
|
132
|
-
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
myTransaction.subject.next({
|
|
136
|
-
key: store.transactionStatus.key,
|
|
137
|
-
atomUpdates,
|
|
138
|
-
output,
|
|
139
|
-
params: store.transactionStatus.params
|
|
140
|
-
});
|
|
141
|
-
store.transactionStatus = { phase: `idle` };
|
|
142
|
-
(_e = store.config.logger) == null ? void 0 : _e.info(`\u{1F6EC}`, `transaction "${myTransaction.key}" applied`);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
57
|
// ../../rel8/junction/src/junction.ts
|
|
146
58
|
var Junction = class {
|
|
147
59
|
constructor(data, config) {
|
|
@@ -340,6 +252,180 @@ var Junction = class {
|
|
|
340
252
|
}
|
|
341
253
|
};
|
|
342
254
|
|
|
255
|
+
// src/subject.ts
|
|
256
|
+
var Subject = class {
|
|
257
|
+
constructor() {
|
|
258
|
+
this.subscribers = /* @__PURE__ */ new Map();
|
|
259
|
+
}
|
|
260
|
+
subscribe(key, subscriber) {
|
|
261
|
+
this.subscribers.set(key, subscriber);
|
|
262
|
+
const unsubscribe = () => this.unsubscribe(key);
|
|
263
|
+
return unsubscribe;
|
|
264
|
+
}
|
|
265
|
+
unsubscribe(key) {
|
|
266
|
+
this.subscribers.delete(key);
|
|
267
|
+
}
|
|
268
|
+
next(value) {
|
|
269
|
+
for (const subscriber of this.subscribers.values()) {
|
|
270
|
+
subscriber(value);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// src/store/store.ts
|
|
276
|
+
var Store = class {
|
|
277
|
+
constructor(name, store = null) {
|
|
278
|
+
this.valueMap = /* @__PURE__ */ new Map();
|
|
279
|
+
this.atoms = /* @__PURE__ */ new Map();
|
|
280
|
+
this.selectors = /* @__PURE__ */ new Map();
|
|
281
|
+
this.readonlySelectors = /* @__PURE__ */ new Map();
|
|
282
|
+
this.trackers = /* @__PURE__ */ new Map();
|
|
283
|
+
this.families = /* @__PURE__ */ new Map();
|
|
284
|
+
this.timelines = /* @__PURE__ */ new Map();
|
|
285
|
+
this.transactions = /* @__PURE__ */ new Map();
|
|
286
|
+
this.atomsThatAreDefault = /* @__PURE__ */ new Set();
|
|
287
|
+
this.timelineAtoms = new Junction({
|
|
288
|
+
between: [`timelineKey`, `atomKey`],
|
|
289
|
+
cardinality: `1:n`
|
|
290
|
+
});
|
|
291
|
+
this.selectorAtoms = new Junction({
|
|
292
|
+
between: [`selectorKey`, `atomKey`],
|
|
293
|
+
cardinality: `n:n`
|
|
294
|
+
});
|
|
295
|
+
this.selectorGraph = new Junction(
|
|
296
|
+
{
|
|
297
|
+
between: [`upstreamSelectorKey`, `downstreamSelectorKey`],
|
|
298
|
+
cardinality: `n:n`
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
makeContentKey: (...keys) => keys.sort().join(`:`)
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
this.subject = {
|
|
305
|
+
atomCreation: new Subject(),
|
|
306
|
+
selectorCreation: new Subject(),
|
|
307
|
+
transactionCreation: new Subject(),
|
|
308
|
+
timelineCreation: new Subject(),
|
|
309
|
+
operationStatus: new Subject()
|
|
310
|
+
};
|
|
311
|
+
this.operation = { open: false };
|
|
312
|
+
this.transactionStatus = { phase: `idle` };
|
|
313
|
+
this.config = {
|
|
314
|
+
name: `IMPLICIT_STORE`,
|
|
315
|
+
logger: __spreadProps(__spreadValues({}, console), { info: () => void 0 }),
|
|
316
|
+
logger__INTERNAL: console
|
|
317
|
+
};
|
|
318
|
+
var _a;
|
|
319
|
+
if (store !== null) {
|
|
320
|
+
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
321
|
+
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
322
|
+
this.transactionStatus = __spreadValues({}, store == null ? void 0 : store.transactionStatus);
|
|
323
|
+
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
324
|
+
logger__INTERNAL: console,
|
|
325
|
+
logger: __spreadValues(__spreadProps(__spreadValues({}, console), {
|
|
326
|
+
info: () => void 0
|
|
327
|
+
}), (_a = store == null ? void 0 : store.config) == null ? void 0 : _a.logger),
|
|
328
|
+
name
|
|
329
|
+
});
|
|
330
|
+
for (const [, atom] of store.atoms) {
|
|
331
|
+
atom.install(this);
|
|
332
|
+
}
|
|
333
|
+
for (const [, selector] of store.readonlySelectors) {
|
|
334
|
+
selector.install(this);
|
|
335
|
+
}
|
|
336
|
+
for (const [, selector] of store.selectors) {
|
|
337
|
+
selector.install(this);
|
|
338
|
+
}
|
|
339
|
+
for (const [, tx] of store.transactions) {
|
|
340
|
+
tx.install(this);
|
|
341
|
+
}
|
|
342
|
+
for (const [, timeline] of store.timelines) {
|
|
343
|
+
timeline.install(this);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
var IMPLICIT = {
|
|
349
|
+
STORE_INTERNAL: void 0,
|
|
350
|
+
get STORE() {
|
|
351
|
+
var _a;
|
|
352
|
+
return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
var clearStore = (store = IMPLICIT.STORE) => {
|
|
356
|
+
const { config } = store;
|
|
357
|
+
Object.assign(store, new Store(config.name));
|
|
358
|
+
store.config = config;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// src/transaction/abort-transaction.ts
|
|
362
|
+
var abortTransaction = (store) => {
|
|
363
|
+
var _a, _b;
|
|
364
|
+
if (store.transactionStatus.phase === `idle`) {
|
|
365
|
+
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
366
|
+
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
367
|
+
);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
store.transactionStatus = { phase: `idle` };
|
|
371
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(`\u{1FA82}`, `transaction fail`);
|
|
372
|
+
};
|
|
373
|
+
var applyTransaction = (output, store) => {
|
|
374
|
+
var _a, _b, _c, _d, _e;
|
|
375
|
+
if (store.transactionStatus.phase !== `building`) {
|
|
376
|
+
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
377
|
+
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
378
|
+
);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
store.transactionStatus.phase = `applying`;
|
|
382
|
+
store.transactionStatus.output = output;
|
|
383
|
+
const { atomUpdates } = store.transactionStatus;
|
|
384
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
385
|
+
`\u{1F6C3} applying transaction "${store.transactionStatus.key}" with ${atomUpdates.length} updates.`
|
|
386
|
+
);
|
|
387
|
+
(_c = store.config.logger) == null ? void 0 : _c.info(`\u{1F6C3} the updates are:`, atomUpdates);
|
|
388
|
+
for (const { key, newValue } of atomUpdates) {
|
|
389
|
+
const token = { key, type: `atom` };
|
|
390
|
+
if (!store.valueMap.has(token.key)) {
|
|
391
|
+
if (token.family) {
|
|
392
|
+
const family = store.families.get(token.family.key);
|
|
393
|
+
if (family) {
|
|
394
|
+
family(token.family.subKey);
|
|
395
|
+
}
|
|
396
|
+
} else {
|
|
397
|
+
const newAtom = store.transactionStatus.core.atoms.get(token.key);
|
|
398
|
+
if (!newAtom) {
|
|
399
|
+
throw new Error(
|
|
400
|
+
`Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
store.atoms.set(newAtom.key, newAtom);
|
|
404
|
+
store.valueMap.set(newAtom.key, newAtom.default);
|
|
405
|
+
(_d = store.config.logger) == null ? void 0 : _d.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
atom_io.setState(token, newValue, store);
|
|
409
|
+
}
|
|
410
|
+
const myTransaction = withdraw(
|
|
411
|
+
{ key: store.transactionStatus.key, type: `transaction` },
|
|
412
|
+
store
|
|
413
|
+
);
|
|
414
|
+
if (myTransaction === void 0) {
|
|
415
|
+
throw new Error(
|
|
416
|
+
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
myTransaction.subject.next({
|
|
420
|
+
key: store.transactionStatus.key,
|
|
421
|
+
atomUpdates,
|
|
422
|
+
output,
|
|
423
|
+
params: store.transactionStatus.params
|
|
424
|
+
});
|
|
425
|
+
store.transactionStatus = { phase: `idle` };
|
|
426
|
+
(_e = store.config.logger) == null ? void 0 : _e.info(`\u{1F6EC}`, `transaction "${myTransaction.key}" applied`);
|
|
427
|
+
};
|
|
428
|
+
|
|
343
429
|
// src/transaction/build-transaction.ts
|
|
344
430
|
var buildTransaction = (key, params, store) => {
|
|
345
431
|
var _a;
|
|
@@ -443,107 +529,6 @@ var undoTransactionUpdate = (update, store) => {
|
|
|
443
529
|
// src/transaction/index.ts
|
|
444
530
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
445
531
|
|
|
446
|
-
// src/store/lookup.ts
|
|
447
|
-
function lookup(key, store) {
|
|
448
|
-
var _a;
|
|
449
|
-
const core = target(store);
|
|
450
|
-
let type = core.atoms.has(key) ? `atom` : core.selectors.has(key) ? `selector` : core.readonlySelectors.has(key) ? `readonly_selector` : ``;
|
|
451
|
-
if (!type) {
|
|
452
|
-
const errorId = Math.random().toString(36);
|
|
453
|
-
type = `\u{1F6A8} This state could not be found by lookup! Check the console for "${errorId}"`;
|
|
454
|
-
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
455
|
-
`${errorId}: Key "${key}" does not exist in the store.`
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
return { key, type };
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// src/store/store.ts
|
|
462
|
-
var Store = class {
|
|
463
|
-
constructor(name, store = null) {
|
|
464
|
-
this.valueMap = /* @__PURE__ */ new Map();
|
|
465
|
-
this.atoms = /* @__PURE__ */ new Map();
|
|
466
|
-
this.selectors = /* @__PURE__ */ new Map();
|
|
467
|
-
this.readonlySelectors = /* @__PURE__ */ new Map();
|
|
468
|
-
this.trackers = /* @__PURE__ */ new Map();
|
|
469
|
-
this.families = /* @__PURE__ */ new Map();
|
|
470
|
-
this.timelines = /* @__PURE__ */ new Map();
|
|
471
|
-
this.transactions = /* @__PURE__ */ new Map();
|
|
472
|
-
this.atomsThatAreDefault = /* @__PURE__ */ new Set();
|
|
473
|
-
this.timelineAtoms = new Junction({
|
|
474
|
-
between: [`timelineKey`, `atomKey`],
|
|
475
|
-
cardinality: `1:n`
|
|
476
|
-
});
|
|
477
|
-
this.selectorAtoms = new Junction({
|
|
478
|
-
between: [`selectorKey`, `atomKey`],
|
|
479
|
-
cardinality: `n:n`
|
|
480
|
-
});
|
|
481
|
-
this.selectorGraph = new Junction(
|
|
482
|
-
{
|
|
483
|
-
between: [`upstreamSelectorKey`, `downstreamSelectorKey`],
|
|
484
|
-
cardinality: `n:n`
|
|
485
|
-
},
|
|
486
|
-
{
|
|
487
|
-
makeContentKey: (...keys) => keys.sort().join(`:`)
|
|
488
|
-
}
|
|
489
|
-
);
|
|
490
|
-
this.subject = {
|
|
491
|
-
atomCreation: new Subject(),
|
|
492
|
-
selectorCreation: new Subject(),
|
|
493
|
-
transactionCreation: new Subject(),
|
|
494
|
-
timelineCreation: new Subject(),
|
|
495
|
-
operationStatus: new Subject()
|
|
496
|
-
};
|
|
497
|
-
this.operation = { open: false };
|
|
498
|
-
this.transactionStatus = { phase: `idle` };
|
|
499
|
-
this.config = {
|
|
500
|
-
name: `IMPLICIT_STORE`,
|
|
501
|
-
logger: __spreadProps(__spreadValues({}, console), { info: () => void 0 }),
|
|
502
|
-
logger__INTERNAL: console
|
|
503
|
-
};
|
|
504
|
-
var _a;
|
|
505
|
-
if (store !== null) {
|
|
506
|
-
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
507
|
-
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
508
|
-
this.transactionStatus = __spreadValues({}, store == null ? void 0 : store.transactionStatus);
|
|
509
|
-
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
510
|
-
logger__INTERNAL: console,
|
|
511
|
-
logger: __spreadValues(__spreadProps(__spreadValues({}, console), {
|
|
512
|
-
info: () => void 0
|
|
513
|
-
}), (_a = store == null ? void 0 : store.config) == null ? void 0 : _a.logger),
|
|
514
|
-
name
|
|
515
|
-
});
|
|
516
|
-
for (const [, atom] of store.atoms) {
|
|
517
|
-
atom.install(this);
|
|
518
|
-
}
|
|
519
|
-
for (const [, selector] of store.readonlySelectors) {
|
|
520
|
-
selector.install(this);
|
|
521
|
-
}
|
|
522
|
-
for (const [, selector] of store.selectors) {
|
|
523
|
-
selector.install(this);
|
|
524
|
-
}
|
|
525
|
-
for (const [, tx] of store.transactions) {
|
|
526
|
-
tx.install(this);
|
|
527
|
-
}
|
|
528
|
-
for (const [, timeline] of store.timelines) {
|
|
529
|
-
timeline.install(this);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
var IMPLICIT = {
|
|
535
|
-
STORE_INTERNAL: void 0,
|
|
536
|
-
get STORE() {
|
|
537
|
-
var _a;
|
|
538
|
-
return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
var clearStore = (store = IMPLICIT.STORE) => {
|
|
542
|
-
const { config } = store;
|
|
543
|
-
Object.assign(store, new Store(config.name));
|
|
544
|
-
store.config = config;
|
|
545
|
-
};
|
|
546
|
-
|
|
547
532
|
// src/timeline/add-atom-to-timeline.ts
|
|
548
533
|
var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
549
534
|
const atom = withdraw(atomToken, store);
|
|
@@ -936,10 +921,12 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
936
921
|
subject.next({ newValue: value2, oldValue: value2 });
|
|
937
922
|
}).catch((error) => {
|
|
938
923
|
var _a;
|
|
939
|
-
(
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
924
|
+
if (error !== `canceled`) {
|
|
925
|
+
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
926
|
+
`Promised value for "${key}" rejected:`,
|
|
927
|
+
error
|
|
928
|
+
);
|
|
929
|
+
}
|
|
943
930
|
});
|
|
944
931
|
} else {
|
|
945
932
|
target(store).valueMap.set(key, value);
|
|
@@ -1134,9 +1121,15 @@ function createAtomFamily(options, store = IMPLICIT.STORE) {
|
|
|
1134
1121
|
return atomFamily;
|
|
1135
1122
|
}
|
|
1136
1123
|
|
|
1137
|
-
// src/
|
|
1138
|
-
var
|
|
1139
|
-
|
|
1124
|
+
// src/keys.ts
|
|
1125
|
+
var isAtomKey = (key, store) => target(store).atoms.has(key);
|
|
1126
|
+
var isSelectorKey = (key, store) => target(store).selectors.has(key);
|
|
1127
|
+
var isReadonlySelectorKey = (key, store) => target(store).readonlySelectors.has(key);
|
|
1128
|
+
var isStateKey = (key, store) => isAtomKey(key, store) || isSelectorKey(key, store) || isReadonlySelectorKey(key, store);
|
|
1129
|
+
|
|
1130
|
+
// src/selector/get-selector-dependency-keys.ts
|
|
1131
|
+
var getSelectorDependencyKeys = (key, store) => {
|
|
1132
|
+
const sources = target(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(source, store));
|
|
1140
1133
|
return sources;
|
|
1141
1134
|
};
|
|
1142
1135
|
|
|
@@ -1381,36 +1374,35 @@ var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
|
|
|
1381
1374
|
};
|
|
1382
1375
|
|
|
1383
1376
|
// src/selector/trace-selector-atoms.ts
|
|
1384
|
-
var traceSelectorAtoms = (selectorKey,
|
|
1385
|
-
|
|
1386
|
-
const
|
|
1387
|
-
|
|
1377
|
+
var traceSelectorAtoms = (selectorKey, directDependencyKey, store) => {
|
|
1378
|
+
const rootKeys = [];
|
|
1379
|
+
const indirectDependencyKeys = getSelectorDependencyKeys(
|
|
1380
|
+
directDependencyKey,
|
|
1381
|
+
store
|
|
1382
|
+
);
|
|
1388
1383
|
let depth = 0;
|
|
1389
|
-
while (
|
|
1390
|
-
const
|
|
1384
|
+
while (indirectDependencyKeys.length > 0) {
|
|
1385
|
+
const indirectDependencyKey = indirectDependencyKeys.shift();
|
|
1391
1386
|
++depth;
|
|
1392
|
-
if (depth > 999) {
|
|
1393
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
1394
|
-
`Maximum selector dependency depth exceeded 999 in selector "${selectorKey}".`
|
|
1395
|
-
);
|
|
1396
|
-
}
|
|
1397
1387
|
if (depth > 99999) {
|
|
1398
1388
|
throw new Error(
|
|
1399
|
-
`Maximum selector dependency depth exceeded in selector "${selectorKey}".`
|
|
1389
|
+
`Maximum selector dependency depth exceeded (> 99999) in selector "${selectorKey}". This is likely due to a circular dependency.`
|
|
1400
1390
|
);
|
|
1401
1391
|
}
|
|
1402
|
-
if (
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1392
|
+
if (!isAtomKey(indirectDependencyKey, store)) {
|
|
1393
|
+
indirectDependencyKeys.push(
|
|
1394
|
+
...getSelectorDependencyKeys(indirectDependencyKey, store)
|
|
1395
|
+
);
|
|
1396
|
+
} else if (!rootKeys.includes(indirectDependencyKey)) {
|
|
1397
|
+
rootKeys.push(indirectDependencyKey);
|
|
1406
1398
|
}
|
|
1407
1399
|
}
|
|
1408
|
-
return
|
|
1400
|
+
return rootKeys;
|
|
1409
1401
|
};
|
|
1410
1402
|
var traceAllSelectorAtoms = (selectorKey, store) => {
|
|
1411
|
-
const
|
|
1412
|
-
return
|
|
1413
|
-
(
|
|
1403
|
+
const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store);
|
|
1404
|
+
return directDependencyKeys.flatMap(
|
|
1405
|
+
(depKey) => isAtomKey(depKey, store) ? depKey : traceSelectorAtoms(selectorKey, depKey, store)
|
|
1414
1406
|
);
|
|
1415
1407
|
};
|
|
1416
1408
|
|
|
@@ -1428,15 +1420,15 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
1428
1420
|
);
|
|
1429
1421
|
return;
|
|
1430
1422
|
}
|
|
1431
|
-
const
|
|
1423
|
+
const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
|
|
1432
1424
|
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1433
1425
|
` || adding roots for "${selectorKey}":`,
|
|
1434
|
-
|
|
1426
|
+
rootKeys.map((r) => r)
|
|
1435
1427
|
);
|
|
1436
|
-
for (const
|
|
1428
|
+
for (const atomKey of rootKeys) {
|
|
1437
1429
|
core.selectorAtoms = core.selectorAtoms.set({
|
|
1438
1430
|
selectorKey,
|
|
1439
|
-
atomKey
|
|
1431
|
+
atomKey
|
|
1440
1432
|
});
|
|
1441
1433
|
}
|
|
1442
1434
|
};
|
|
@@ -1753,8 +1745,8 @@ var markAtomAsNotDefault = (key, store = IMPLICIT.STORE) => {
|
|
|
1753
1745
|
core.atomsThatAreDefault.delete(key);
|
|
1754
1746
|
};
|
|
1755
1747
|
var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
1756
|
-
const
|
|
1757
|
-
return
|
|
1748
|
+
const rootKeys = traceAllSelectorAtoms(key, store);
|
|
1749
|
+
return rootKeys.every((rootKey) => isAtomDefault(rootKey, store));
|
|
1758
1750
|
};
|
|
1759
1751
|
|
|
1760
1752
|
// src/atom/create-atom.ts
|
|
@@ -1827,11 +1819,11 @@ var recallState = (state, store = IMPLICIT.STORE) => {
|
|
|
1827
1819
|
|
|
1828
1820
|
// src/subscribe/subscribe-to-root-atoms.ts
|
|
1829
1821
|
var subscribeToRootAtoms = (state, store) => {
|
|
1830
|
-
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((
|
|
1831
|
-
const atom =
|
|
1822
|
+
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
|
|
1823
|
+
const atom = store.atoms.get(atomKey);
|
|
1832
1824
|
if (atom === void 0) {
|
|
1833
1825
|
throw new Error(
|
|
1834
|
-
`Atom "${
|
|
1826
|
+
`Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1835
1827
|
);
|
|
1836
1828
|
}
|
|
1837
1829
|
return atom.subject.subscribe(
|
|
@@ -1839,7 +1831,7 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1839
1831
|
(atomChange) => {
|
|
1840
1832
|
var _a, _b;
|
|
1841
1833
|
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1842
|
-
`\u{1F4E2} selector "${state.key}" saw root "${
|
|
1834
|
+
`\u{1F4E2} selector "${state.key}" saw root "${atomKey}" go (`,
|
|
1843
1835
|
atomChange.oldValue,
|
|
1844
1836
|
`->`,
|
|
1845
1837
|
atomChange.newValue,
|
|
@@ -1887,17 +1879,20 @@ exports.deleteAtom = deleteAtom;
|
|
|
1887
1879
|
exports.deposit = deposit;
|
|
1888
1880
|
exports.evictCachedValue = evictCachedValue;
|
|
1889
1881
|
exports.getJsonToken = getJsonToken;
|
|
1882
|
+
exports.getSelectorDependencyKeys = getSelectorDependencyKeys;
|
|
1890
1883
|
exports.getState__INTERNAL = getState__INTERNAL;
|
|
1891
1884
|
exports.getUpdateToken = getUpdateToken;
|
|
1892
1885
|
exports.isAtomDefault = isAtomDefault;
|
|
1886
|
+
exports.isAtomKey = isAtomKey;
|
|
1893
1887
|
exports.isAtomMutable = isAtomMutable;
|
|
1894
1888
|
exports.isAtomTokenMutable = isAtomTokenMutable;
|
|
1895
1889
|
exports.isDone = isDone;
|
|
1890
|
+
exports.isReadonlySelectorKey = isReadonlySelectorKey;
|
|
1896
1891
|
exports.isSelectorDefault = isSelectorDefault;
|
|
1892
|
+
exports.isSelectorKey = isSelectorKey;
|
|
1893
|
+
exports.isStateKey = isStateKey;
|
|
1897
1894
|
exports.isTransceiver = isTransceiver;
|
|
1898
1895
|
exports.isValueCached = isValueCached;
|
|
1899
|
-
exports.lookup = lookup;
|
|
1900
|
-
exports.lookupSelectorSources = lookupSelectorSources;
|
|
1901
1896
|
exports.markAtomAsDefault = markAtomAsDefault;
|
|
1902
1897
|
exports.markAtomAsNotDefault = markAtomAsNotDefault;
|
|
1903
1898
|
exports.markDone = markDone;
|