atom.io 0.29.4 → 0.30.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/dist/{chunk-TCINPEYE.js → chunk-7PUUHSXC.js} +314 -104
- package/dist/chunk-ZKG6ZA4I.js +20 -0
- package/dist/index.d.ts +23 -6
- package/dist/index.js +3 -17
- package/internal/dist/index.d.ts +15 -7
- package/internal/dist/index.js +2 -1
- package/internal/src/atom/dispose-atom.ts +4 -8
- package/internal/src/index.ts +1 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +71 -27
- package/internal/src/molecule/create-molecule-family.ts +2 -2
- package/internal/src/molecule/dispose-molecule.ts +4 -2
- package/internal/src/molecule/make-molecule-in-store.ts +8 -8
- package/internal/src/molecule/molecule-internal.ts +11 -7
- package/internal/src/store/store.ts +6 -2
- package/internal/src/timeline/create-timeline.ts +99 -71
- package/internal/src/utility-types.ts +9 -2
- package/json/dist/index.d.ts +3 -3
- package/json/dist/index.js +2 -1
- package/json/src/entries.ts +3 -3
- package/package.json +13 -13
- package/react-devtools/dist/index.js +9 -5
- package/react-devtools/src/TimelineIndex.tsx +4 -1
- package/react-devtools/src/Updates.tsx +18 -3
- package/realtime-testing/dist/index.d.ts +2 -2
- package/realtime-testing/dist/index.js +6 -6
- package/realtime-testing/src/setup-realtime-test.tsx +8 -9
- package/src/allocate.ts +278 -0
- package/src/molecule.ts +4 -2
- package/src/transaction.ts +22 -4
package/internal/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as atom_io from 'atom.io';
|
|
2
|
-
import { MutableAtomFamilyToken, MutableAtomToken, RegularAtomFamilyToken, RegularAtomToken, AtomFamilyToken, AtomToken, WritableSelectorFamilyToken, WritableSelectorToken, ReadonlySelectorFamilyToken, ReadonlySelectorToken, SelectorFamilyToken, SelectorToken, WritableFamilyToken, WritableToken, ReadableFamilyToken, ReadableToken, MoleculeConstructor, MoleculeFamilyToken, MoleculeKey, TransactionToken, TransactionUpdate, TransactionOptions, ActorToolkit, MoleculeFamily, MoleculeToken, MoleculeFamilyOptions, StateCreation, StateDisposal, MoleculeParams, TimelineManageable, StateUpdate, TokenType, FamilyMetadata, MoleculeCreation, MoleculeDisposal, TimelineUpdate, TimelineOptions, TimelineToken, AtomIOLogger, Logger, MutableAtomOptions, MutableAtomFamilyOptions, RegularAtomOptions, RegularAtomFamilyOptions, ReadonlySelectorFamilyOptions, WritableSelectorFamilyOptions, KeyedStateUpdate, ReadonlySelectorOptions, WritableSelectorOptions, SetterToolkit, UpdateHandler, TransactionUpdateHandler } from 'atom.io';
|
|
2
|
+
import { MutableAtomFamilyToken, MutableAtomToken, RegularAtomFamilyToken, RegularAtomToken, AtomFamilyToken, AtomToken, WritableSelectorFamilyToken, WritableSelectorToken, ReadonlySelectorFamilyToken, ReadonlySelectorToken, SelectorFamilyToken, SelectorToken, WritableFamilyToken, WritableToken, ReadableFamilyToken, ReadableToken, MoleculeConstructor, MoleculeFamilyToken, MoleculeKey, TransactionToken, TransactionUpdate, TransactionOptions, ActorToolkit, MoleculeFamily, MoleculeToken, MoleculeFamilyOptions, StateCreation, StateDisposal, MoleculeParams, TimelineManageable, StateUpdate, TokenType, FamilyMetadata, MoleculeCreation, MoleculeDisposal, TimelineUpdate, TimelineOptions, TimelineToken, MoleculeCreationModern, MoleculeDisposalModern, AtomIOLogger, Logger, MutableAtomOptions, MutableAtomFamilyOptions, RegularAtomOptions, RegularAtomFamilyOptions, ReadonlySelectorFamilyOptions, WritableSelectorFamilyOptions, KeyedStateUpdate, ReadonlySelectorOptions, WritableSelectorOptions, SetterToolkit, UpdateHandler, TransactionUpdateHandler } from 'atom.io';
|
|
3
3
|
import { Json, Canonical, JsonInterface } from 'atom.io/json';
|
|
4
4
|
import { Join } from 'atom.io/data';
|
|
5
5
|
import { Refinement } from 'atom.io/introspection';
|
|
@@ -94,7 +94,13 @@ type Flat<R extends {
|
|
|
94
94
|
}> = {
|
|
95
95
|
[K in keyof R]: R[K];
|
|
96
96
|
};
|
|
97
|
-
type
|
|
97
|
+
type Count<N extends number, A extends any[] = []> = [
|
|
98
|
+
...A,
|
|
99
|
+
any
|
|
100
|
+
][`length`] extends N ? A[`length`] : A[`length`] | Count<N, [...A, any]>;
|
|
101
|
+
type Each<E extends any[]> = {
|
|
102
|
+
[P in Count<E[`length`]>]: E[P];
|
|
103
|
+
};
|
|
98
104
|
|
|
99
105
|
declare const abortTransaction: (store: Store) => void;
|
|
100
106
|
|
|
@@ -198,13 +204,15 @@ declare class Molecule<M extends MoleculeConstructor> implements MoleculeToken<M
|
|
|
198
204
|
readonly type = "molecule";
|
|
199
205
|
stringKey: string;
|
|
200
206
|
family?: MoleculeFamilyToken<M>;
|
|
207
|
+
_dependsOn: `all` | `any`;
|
|
208
|
+
get dependsOn(): `all` | `any`;
|
|
201
209
|
readonly subject: Subject<StateCreation<any> | StateDisposal<any>>;
|
|
202
210
|
tokens: Map<string, ReadableToken<any>>;
|
|
203
211
|
above: Map<string, Molecule<any>>;
|
|
204
212
|
below: Map<string, Molecule<any>>;
|
|
205
213
|
joins: Map<string, Join<any, any, any, any>>;
|
|
206
214
|
instance: InstanceType<M>;
|
|
207
|
-
constructor(ctx: Molecule<any>
|
|
215
|
+
constructor(ctx: Molecule<any>[] | undefined, key: MoleculeKey<M>, family?: MoleculeFamilyToken<M>);
|
|
208
216
|
}
|
|
209
217
|
|
|
210
218
|
declare function growMoleculeInStore<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical>(molecule: Molecule<any>, family: MutableAtomFamilyToken<T, J, K>, store: Store): MutableAtomToken<T, J>;
|
|
@@ -316,7 +324,7 @@ declare class Store implements Lineage {
|
|
|
316
324
|
}>;
|
|
317
325
|
molecules: Map<string, Molecule<any>>;
|
|
318
326
|
moleculeFamilies: Map<string, Flat<atom_io.MoleculeFamilyToken<any> & {
|
|
319
|
-
subject: Subject<atom_io.
|
|
327
|
+
subject: Subject<atom_io.MoleculeCreationClassic<any> | atom_io.MoleculeDisposalClassic>;
|
|
320
328
|
dependsOn: `all` | `any`;
|
|
321
329
|
new: any;
|
|
322
330
|
}>>;
|
|
@@ -331,9 +339,9 @@ declare class Store implements Lineage {
|
|
|
331
339
|
transactionCreation: Subject<TransactionToken<Func>>;
|
|
332
340
|
transactionApplying: StatefulSubject<TransactionProgress<Func> | null>;
|
|
333
341
|
operationClose: Subject<OperationProgress>;
|
|
334
|
-
moleculeCreationStart: Subject<MoleculeToken<any
|
|
342
|
+
moleculeCreationStart: Subject<MoleculeToken<any> | MoleculeCreationModern>;
|
|
335
343
|
moleculeCreationDone: Subject<MoleculeToken<any>>;
|
|
336
|
-
moleculeDisposal: Subject<MoleculeToken<any
|
|
344
|
+
moleculeDisposal: Subject<MoleculeToken<any> | MoleculeDisposalModern>;
|
|
337
345
|
};
|
|
338
346
|
operation: OperationProgress;
|
|
339
347
|
config: {
|
|
@@ -664,4 +672,4 @@ type SelectorFamily<T, K extends Canonical> = ReadonlySelectorFamily<T, K> | Wri
|
|
|
664
672
|
type WritableFamily<T, K extends Canonical> = AtomFamily<T, K> | WritableSelectorFamily<T, K>;
|
|
665
673
|
type ReadableFamily<T, K extends Canonical> = AtomFamily<T, K> | SelectorFamily<T, K>;
|
|
666
674
|
|
|
667
|
-
export { type Atom, type AtomFamily, type AtomIOState, type AtomIOToken, type AtomKey, type BaseExternalStoreConfiguration, type ChildStore, type Empty, type EnvironmentData, type ExternalStoreConfiguration, type ExternalStoreWithContentConfiguration, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, type Flat, type Func, Future, IMPLICIT, Junction, type JunctionAdvancedConfiguration, type JunctionEntries, type JunctionJSON, type JunctionSchema, LazyMap, type Lineage, type Modify, Molecule, type MutableAtom, type MutableAtomFamily, NotFoundError, type OperationProgress, type
|
|
675
|
+
export { type Atom, type AtomFamily, type AtomIOState, type AtomIOToken, type AtomKey, type BaseExternalStoreConfiguration, type ChildStore, type Count, type Each, type Empty, type EnvironmentData, type ExternalStoreConfiguration, type ExternalStoreWithContentConfiguration, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, type Flat, type Func, Future, IMPLICIT, Junction, type JunctionAdvancedConfiguration, type JunctionEntries, type JunctionJSON, type JunctionSchema, LazyMap, type Lineage, type Modify, Molecule, type MutableAtom, type MutableAtomFamily, NotFoundError, type OperationProgress, type ReadableFamily, type ReadableState, type ReadonlySelector, type ReadonlySelectorFamily, type ReadonlySelectorKey, type RegularAtom, type RegularAtomFamily, type RootStore, type Selector, type SelectorFamily, type SelectorKey, type Signal, type StateKey, StatefulSubject, Store, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineMoleculeCreation, type TimelineMoleculeDisposal, type TimelineSelectorUpdate, type TimelineStateCreation, type TimelineStateDisposal, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionEpoch, type TransactionPhase, type TransactionProgress, type Transceiver, type TransceiverMode, type Withdrawable, type WritableFamily, type WritableSelector, type WritableSelectorFamily, type WritableState, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, counterfeit, createAtomFamily, createMoleculeFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deposit, disposeAtom, disposeFromStore, disposeMolecule, disposeSelector, eldest, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, growMoleculeInStore, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|
package/internal/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Junction, LazyMap, Molecule, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, counterfeit, createAtomFamily, createMoleculeFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deposit, disposeAtom, disposeFromStore, disposeMolecule, disposeSelector, eldest, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, growMoleculeInStore, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw } from '../../dist/chunk-
|
|
1
|
+
export { FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Junction, LazyMap, Molecule, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, counterfeit, createAtomFamily, createMoleculeFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deposit, disposeAtom, disposeFromStore, disposeMolecule, disposeSelector, eldest, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, growMoleculeInStore, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw } from '../../dist/chunk-7PUUHSXC.js';
|
|
2
|
+
import '../../dist/chunk-ZKG6ZA4I.js';
|
|
2
3
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { AtomToken } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import type { Store } from ".."
|
|
4
|
-
import {
|
|
5
|
-
disposeSelector,
|
|
6
|
-
getUpdateToken,
|
|
7
|
-
isChildStore,
|
|
8
|
-
newest,
|
|
9
|
-
withdraw,
|
|
10
|
-
} from ".."
|
|
4
|
+
import { getUpdateToken, isChildStore, newest, withdraw } from ".."
|
|
11
5
|
|
|
12
6
|
export function disposeAtom(atomToken: AtomToken<unknown>, store: Store): void {
|
|
13
7
|
const target = newest(store)
|
|
@@ -24,6 +18,7 @@ export function disposeAtom(atomToken: AtomToken<unknown>, store: Store): void {
|
|
|
24
18
|
token: atomToken,
|
|
25
19
|
value: lastValue,
|
|
26
20
|
})
|
|
21
|
+
|
|
27
22
|
const molecule = target.molecules.get(atom.family.subKey)
|
|
28
23
|
if (molecule) {
|
|
29
24
|
molecule.tokens.delete(key)
|
|
@@ -32,7 +27,8 @@ export function disposeAtom(atomToken: AtomToken<unknown>, store: Store): void {
|
|
|
32
27
|
target.valueMap.delete(key)
|
|
33
28
|
target.selectorAtoms.delete(key)
|
|
34
29
|
target.atomsThatAreDefault.delete(key)
|
|
35
|
-
|
|
30
|
+
store.timelineTopics.delete(key)
|
|
31
|
+
|
|
36
32
|
if (atomToken.type === `mutable_atom`) {
|
|
37
33
|
const updateToken = getUpdateToken(atomToken)
|
|
38
34
|
disposeAtom(updateToken, store)
|
package/internal/src/index.ts
CHANGED
|
@@ -8,10 +8,11 @@ import type {
|
|
|
8
8
|
import { parseJson, stringifyJson } from "atom.io/json"
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
allocateIntoStore,
|
|
12
|
+
deallocateFromStore,
|
|
13
|
+
} from "~/packages/atom.io/src/allocate"
|
|
14
|
+
|
|
15
|
+
import { disposeFromStore, findInStore } from "../families"
|
|
15
16
|
import { growMoleculeInStore, makeMoleculeInStore } from "../molecule"
|
|
16
17
|
import { type Store, withdraw } from "../store"
|
|
17
18
|
|
|
@@ -70,16 +71,30 @@ export function ingestMoleculeCreationEvent(
|
|
|
70
71
|
): void {
|
|
71
72
|
switch (applying) {
|
|
72
73
|
case `newValue`:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
switch (update.subType) {
|
|
75
|
+
case `classic`:
|
|
76
|
+
makeMoleculeInStore(
|
|
77
|
+
store,
|
|
78
|
+
update.context,
|
|
79
|
+
update.family,
|
|
80
|
+
update.token.key,
|
|
81
|
+
...update.params,
|
|
82
|
+
)
|
|
83
|
+
break
|
|
84
|
+
case `modern`:
|
|
85
|
+
allocateIntoStore<any, any, any>(store, update.provenance, update.key)
|
|
86
|
+
break
|
|
87
|
+
}
|
|
80
88
|
break
|
|
81
89
|
case `oldValue`:
|
|
82
|
-
|
|
90
|
+
switch (update.subType) {
|
|
91
|
+
case `classic`:
|
|
92
|
+
disposeFromStore(store, update.token)
|
|
93
|
+
break
|
|
94
|
+
case `modern`:
|
|
95
|
+
deallocateFromStore<any, any, any>(store, update.key)
|
|
96
|
+
break
|
|
97
|
+
}
|
|
83
98
|
break
|
|
84
99
|
}
|
|
85
100
|
}
|
|
@@ -90,25 +105,54 @@ export function ingestMoleculeDisposalEvent(
|
|
|
90
105
|
): void {
|
|
91
106
|
switch (applying) {
|
|
92
107
|
case `newValue`:
|
|
93
|
-
|
|
108
|
+
switch (update.subType) {
|
|
109
|
+
case `classic`:
|
|
110
|
+
disposeFromStore(store, update.token)
|
|
111
|
+
break
|
|
112
|
+
case `modern`:
|
|
113
|
+
deallocateFromStore<any, any, any>(store, update.key)
|
|
114
|
+
break
|
|
115
|
+
}
|
|
94
116
|
break
|
|
95
117
|
case `oldValue`:
|
|
96
118
|
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
119
|
+
// TODO: Handle classic vs modern molecules
|
|
120
|
+
switch (update.subType) {
|
|
121
|
+
case `classic`:
|
|
122
|
+
{
|
|
123
|
+
const moleculeToken = makeMoleculeInStore(
|
|
124
|
+
store,
|
|
125
|
+
update.context,
|
|
126
|
+
update.family,
|
|
127
|
+
update.token.key,
|
|
128
|
+
)
|
|
129
|
+
for (const [familyKey, value] of update.values) {
|
|
130
|
+
const memberKey = `${familyKey}(${stringifyJson(moleculeToken.key)})`
|
|
131
|
+
const molecule = withdraw(moleculeToken, store)
|
|
132
|
+
const alreadyCreated = molecule.tokens.has(memberKey)
|
|
133
|
+
const family = store.families.get(familyKey)
|
|
134
|
+
if (family && !alreadyCreated) {
|
|
135
|
+
growMoleculeInStore(molecule, family, store)
|
|
136
|
+
}
|
|
137
|
+
store.valueMap.set(memberKey, value)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
break
|
|
141
|
+
case `modern`: {
|
|
142
|
+
allocateIntoStore<any, any, any>(
|
|
143
|
+
store,
|
|
144
|
+
update.provenance,
|
|
145
|
+
update.key,
|
|
146
|
+
)
|
|
147
|
+
for (const [familyKey, value] of update.values) {
|
|
148
|
+
const family = store.families.get(familyKey)
|
|
149
|
+
if (family) {
|
|
150
|
+
findInStore(store, family, update.key)
|
|
151
|
+
const memberKey = `${familyKey}(${stringifyJson(update.key)})`
|
|
152
|
+
store.valueMap.set(memberKey, value)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
110
155
|
}
|
|
111
|
-
store.valueMap.set(memberKey, value)
|
|
112
156
|
}
|
|
113
157
|
}
|
|
114
158
|
break
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
MoleculeConstructor,
|
|
3
|
-
|
|
3
|
+
MoleculeCreationClassic,
|
|
4
4
|
MoleculeFamily,
|
|
5
5
|
MoleculeFamilyOptions,
|
|
6
6
|
MoleculeFamilyToken,
|
|
@@ -13,7 +13,7 @@ export function createMoleculeFamily<M extends MoleculeConstructor>(
|
|
|
13
13
|
store: Store,
|
|
14
14
|
options: MoleculeFamilyOptions<M>,
|
|
15
15
|
): MoleculeFamilyToken<M> {
|
|
16
|
-
const subject = new Subject<
|
|
16
|
+
const subject = new Subject<MoleculeCreationClassic<M>>()
|
|
17
17
|
|
|
18
18
|
const token = {
|
|
19
19
|
type: `molecule_family`,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
MoleculeConstructor,
|
|
3
3
|
MoleculeDisposal,
|
|
4
|
+
MoleculeDisposalClassic,
|
|
4
5
|
MoleculeToken,
|
|
5
6
|
} from "atom.io"
|
|
6
7
|
|
|
@@ -36,8 +37,9 @@ export function disposeMolecule<M extends MoleculeConstructor>(
|
|
|
36
37
|
|
|
37
38
|
if (family) {
|
|
38
39
|
const Formula = withdraw(family, store)
|
|
39
|
-
const disposalEvent:
|
|
40
|
+
const disposalEvent: MoleculeDisposalClassic = {
|
|
40
41
|
type: `molecule_disposal`,
|
|
42
|
+
subType: `classic`,
|
|
41
43
|
token,
|
|
42
44
|
family,
|
|
43
45
|
context,
|
|
@@ -50,7 +52,7 @@ export function disposeMolecule<M extends MoleculeConstructor>(
|
|
|
50
52
|
disposeFromStore(store, state)
|
|
51
53
|
}
|
|
52
54
|
for (const child of molecule.below.values()) {
|
|
53
|
-
if (child.
|
|
55
|
+
if (child.dependsOn === `all`) {
|
|
54
56
|
disposeMolecule(child, store)
|
|
55
57
|
} else {
|
|
56
58
|
child.above.delete(molecule.stringKey)
|
|
@@ -2,7 +2,7 @@ import type {
|
|
|
2
2
|
CtorToolkit,
|
|
3
3
|
getState,
|
|
4
4
|
MoleculeConstructor,
|
|
5
|
-
|
|
5
|
+
MoleculeCreationClassic,
|
|
6
6
|
MoleculeFamilyToken,
|
|
7
7
|
MoleculeKey,
|
|
8
8
|
MoleculeParams,
|
|
@@ -93,12 +93,11 @@ export function makeMoleculeInStore<M extends MoleculeConstructor>(
|
|
|
93
93
|
const unsubFromFamily = family.subject.subscribe(
|
|
94
94
|
`join:${token.key}-${stringKey}`,
|
|
95
95
|
(event) => {
|
|
96
|
-
if (
|
|
97
|
-
event.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
join.molecules.delete(stringKey)
|
|
96
|
+
if (event.type === `molecule_disposal`) {
|
|
97
|
+
if (stringifyJson(event.token.key) === stringKey) {
|
|
98
|
+
unsubFromFamily()
|
|
99
|
+
join.molecules.delete(stringKey)
|
|
100
|
+
}
|
|
102
101
|
}
|
|
103
102
|
},
|
|
104
103
|
)
|
|
@@ -168,11 +167,12 @@ export function makeMoleculeInStore<M extends MoleculeConstructor>(
|
|
|
168
167
|
|
|
169
168
|
const update = {
|
|
170
169
|
type: `molecule_creation`,
|
|
170
|
+
subType: `classic`,
|
|
171
171
|
token,
|
|
172
172
|
family: familyToken,
|
|
173
173
|
context: contextArray,
|
|
174
174
|
params,
|
|
175
|
-
} satisfies
|
|
175
|
+
} satisfies MoleculeCreationClassic<M>
|
|
176
176
|
|
|
177
177
|
if (isRootStore(target)) {
|
|
178
178
|
family.subject.next(update)
|
|
@@ -18,6 +18,13 @@ export class Molecule<M extends MoleculeConstructor>
|
|
|
18
18
|
public readonly type = `molecule`
|
|
19
19
|
public stringKey: string
|
|
20
20
|
public family?: MoleculeFamilyToken<M>
|
|
21
|
+
public _dependsOn: `all` | `any`
|
|
22
|
+
public get dependsOn(): `all` | `any` {
|
|
23
|
+
if (this.family) {
|
|
24
|
+
return this.family.dependsOn
|
|
25
|
+
}
|
|
26
|
+
return this._dependsOn
|
|
27
|
+
}
|
|
21
28
|
public readonly subject = new Subject<
|
|
22
29
|
StateCreation<any> | StateDisposal<any>
|
|
23
30
|
>()
|
|
@@ -27,21 +34,18 @@ export class Molecule<M extends MoleculeConstructor>
|
|
|
27
34
|
public joins = new Map<string, Join<any, any, any, any>>()
|
|
28
35
|
public instance: InstanceType<M>
|
|
29
36
|
public constructor(
|
|
30
|
-
ctx: Molecule<any>
|
|
37
|
+
ctx: Molecule<any>[] | undefined,
|
|
31
38
|
public readonly key: MoleculeKey<M>,
|
|
32
39
|
family?: MoleculeFamilyToken<M>,
|
|
33
40
|
) {
|
|
34
41
|
this.stringKey = stringifyJson(key)
|
|
35
42
|
if (family) {
|
|
36
43
|
this.family = family
|
|
44
|
+
this._dependsOn = family.dependsOn
|
|
37
45
|
}
|
|
38
46
|
if (ctx) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.above.set(molecule.stringKey, molecule)
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
this.above.set(ctx.stringKey, ctx)
|
|
47
|
+
for (const molecule of ctx) {
|
|
48
|
+
this.above.set(molecule.stringKey, molecule)
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AtomToken,
|
|
3
3
|
Logger,
|
|
4
|
+
MoleculeCreationModern,
|
|
5
|
+
MoleculeDisposalModern,
|
|
4
6
|
MoleculeFamily,
|
|
5
7
|
MoleculeToken,
|
|
6
8
|
ReadonlySelectorToken,
|
|
@@ -115,9 +117,11 @@ export class Store implements Lineage {
|
|
|
115
117
|
null,
|
|
116
118
|
),
|
|
117
119
|
operationClose: new Subject<OperationProgress>(),
|
|
118
|
-
moleculeCreationStart: new Subject<
|
|
120
|
+
moleculeCreationStart: new Subject<
|
|
121
|
+
MoleculeCreationModern | MoleculeToken<any>
|
|
122
|
+
>(),
|
|
119
123
|
moleculeCreationDone: new Subject<MoleculeToken<any>>(),
|
|
120
|
-
moleculeDisposal: new Subject<MoleculeToken<any>>(),
|
|
124
|
+
moleculeDisposal: new Subject<MoleculeDisposalModern | MoleculeToken<any>>(),
|
|
121
125
|
}
|
|
122
126
|
public operation: OperationProgress = { open: false }
|
|
123
127
|
|
|
@@ -25,6 +25,7 @@ import { newest } from "../lineage"
|
|
|
25
25
|
import { getUpdateToken } from "../mutable"
|
|
26
26
|
import { type Store, withdraw } from "../store"
|
|
27
27
|
import { Subject } from "../subject"
|
|
28
|
+
import { isChildStore } from "../transaction"
|
|
28
29
|
import type { Flat, Func } from "../utility-types"
|
|
29
30
|
|
|
30
31
|
export type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = Flat<
|
|
@@ -371,74 +372,81 @@ function addMoleculeFamilyToTimeline(
|
|
|
371
372
|
`got a molecule creation or disposal`,
|
|
372
373
|
creationOrDisposal,
|
|
373
374
|
)
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
375
|
+
if (creationOrDisposal.subType === `classic`) {
|
|
376
|
+
switch (creationOrDisposal.type) {
|
|
377
|
+
case `molecule_creation`:
|
|
378
|
+
{
|
|
379
|
+
store.timelineTopics.set(
|
|
380
|
+
{
|
|
381
|
+
topicKey: creationOrDisposal.token.key,
|
|
382
|
+
timelineKey: tl.key,
|
|
383
|
+
},
|
|
384
|
+
{ topicType: `molecule` },
|
|
385
|
+
)
|
|
386
|
+
const txUpdateInProgress =
|
|
387
|
+
newest(store).on.transactionApplying.state?.update
|
|
388
|
+
if (txUpdateInProgress) {
|
|
389
|
+
joinTransaction(tl, txUpdateInProgress, store)
|
|
390
|
+
} else if (tl.timeTraveling === null) {
|
|
391
|
+
const event = Object.assign(creationOrDisposal, {
|
|
392
|
+
timestamp: Date.now(),
|
|
393
|
+
})
|
|
394
|
+
tl.history.push(event)
|
|
395
|
+
tl.at = tl.history.length
|
|
396
|
+
tl.subject.next(event)
|
|
397
|
+
}
|
|
398
|
+
const molecule = withdraw(creationOrDisposal.token, store)
|
|
397
399
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
400
|
+
for (const token of molecule.tokens.values()) {
|
|
401
|
+
switch (token.type) {
|
|
402
|
+
case `atom`:
|
|
403
|
+
case `mutable_atom`:
|
|
404
|
+
addAtomToTimeline(token, tl, store)
|
|
405
|
+
break
|
|
406
|
+
}
|
|
404
407
|
}
|
|
408
|
+
tl.subscriptions.set(
|
|
409
|
+
molecule.key,
|
|
410
|
+
molecule.subject.subscribe(
|
|
411
|
+
`timeline:${tl.key}`,
|
|
412
|
+
(stateCreationOrDisposal) => {
|
|
413
|
+
handleStateLifecycleEvent(
|
|
414
|
+
stateCreationOrDisposal,
|
|
415
|
+
tl,
|
|
416
|
+
store,
|
|
417
|
+
)
|
|
418
|
+
},
|
|
419
|
+
),
|
|
420
|
+
)
|
|
405
421
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
(
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
)
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
const moleculeKey = creationOrDisposal.token.key
|
|
432
|
-
tl.subscriptions.get(moleculeKey)?.()
|
|
433
|
-
tl.subscriptions.delete(moleculeKey)
|
|
434
|
-
for (const [familyKey] of creationOrDisposal.values) {
|
|
435
|
-
const stateKey = `${familyKey}(${stringifyJson(moleculeKey)})`
|
|
436
|
-
tl.subscriptions.get(stateKey)?.()
|
|
437
|
-
tl.subscriptions.delete(stateKey)
|
|
438
|
-
store.timelineTopics.delete(stateKey)
|
|
422
|
+
break
|
|
423
|
+
case `molecule_disposal`:
|
|
424
|
+
{
|
|
425
|
+
const txUpdateInProgress =
|
|
426
|
+
newest(store).on.transactionApplying.state?.update
|
|
427
|
+
if (txUpdateInProgress) {
|
|
428
|
+
joinTransaction(tl, txUpdateInProgress, store)
|
|
429
|
+
} else if (tl.timeTraveling === null) {
|
|
430
|
+
const event = Object.assign(creationOrDisposal, {
|
|
431
|
+
timestamp: Date.now(),
|
|
432
|
+
})
|
|
433
|
+
tl.history.push(event)
|
|
434
|
+
tl.at = tl.history.length
|
|
435
|
+
tl.subject.next(event)
|
|
436
|
+
}
|
|
437
|
+
const moleculeKey = stringifyJson(creationOrDisposal.token.key)
|
|
438
|
+
|
|
439
|
+
tl.subscriptions.get(moleculeKey)?.()
|
|
440
|
+
tl.subscriptions.delete(moleculeKey)
|
|
441
|
+
for (const [familyKey] of creationOrDisposal.values) {
|
|
442
|
+
const stateKey = `${familyKey}(${stringifyJson(moleculeKey)})`
|
|
443
|
+
tl.subscriptions.get(stateKey)?.()
|
|
444
|
+
tl.subscriptions.delete(stateKey)
|
|
445
|
+
store.timelineTopics.delete(stateKey)
|
|
446
|
+
}
|
|
439
447
|
}
|
|
440
|
-
|
|
441
|
-
|
|
448
|
+
break
|
|
449
|
+
}
|
|
442
450
|
}
|
|
443
451
|
}),
|
|
444
452
|
)
|
|
@@ -506,17 +514,32 @@ function filterTransactionUpdates(
|
|
|
506
514
|
}
|
|
507
515
|
|
|
508
516
|
let key: string
|
|
517
|
+
let familyKey: string | undefined
|
|
509
518
|
switch (updateFromTx.type) {
|
|
510
519
|
case `state_creation`:
|
|
511
520
|
case `state_disposal`:
|
|
521
|
+
key = updateFromTx.token.key
|
|
522
|
+
familyKey = updateFromTx.token.family?.key
|
|
523
|
+
break
|
|
512
524
|
case `molecule_creation`:
|
|
513
525
|
case `molecule_disposal`:
|
|
514
|
-
|
|
526
|
+
switch (updateFromTx.subType) {
|
|
527
|
+
case `classic`:
|
|
528
|
+
key = updateFromTx.token.key
|
|
529
|
+
break
|
|
530
|
+
case `modern`:
|
|
531
|
+
return true // always include
|
|
532
|
+
}
|
|
515
533
|
break
|
|
516
534
|
default:
|
|
517
535
|
key = updateFromTx.key
|
|
536
|
+
familyKey = updateFromTx.family?.key
|
|
518
537
|
break
|
|
519
538
|
}
|
|
539
|
+
timelineTopics.has(key)
|
|
540
|
+
if (familyKey && timelineTopics.has(familyKey)) {
|
|
541
|
+
return true
|
|
542
|
+
}
|
|
520
543
|
return timelineTopics.has(key)
|
|
521
544
|
})
|
|
522
545
|
.map((updateFromTx) => {
|
|
@@ -543,13 +566,18 @@ function handleStateLifecycleEvent(
|
|
|
543
566
|
timestamp,
|
|
544
567
|
}) as TimelineUpdate<any>
|
|
545
568
|
if (!tl.timeTraveling) {
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
548
|
-
|
|
569
|
+
const target = newest(store)
|
|
570
|
+
if (isChildStore(target)) {
|
|
571
|
+
// we don't want to update the true timeline while we are in a transaction
|
|
549
572
|
} else {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
573
|
+
const txUpdateInProgress = target.on.transactionApplying.state
|
|
574
|
+
if (txUpdateInProgress) {
|
|
575
|
+
joinTransaction(tl, txUpdateInProgress.update, store)
|
|
576
|
+
} else {
|
|
577
|
+
tl.history.push(timelineEvent)
|
|
578
|
+
tl.at = tl.history.length
|
|
579
|
+
tl.subject.next(timelineEvent)
|
|
580
|
+
}
|
|
553
581
|
}
|
|
554
582
|
}
|
|
555
583
|
switch (event.type) {
|
|
@@ -4,6 +4,13 @@ export type Flat<R extends { [K in PropertyKey]: any }> = {
|
|
|
4
4
|
[K in keyof R]: R[K]
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export type
|
|
7
|
+
export type Count<N extends number, A extends any[] = []> = [
|
|
8
|
+
...A,
|
|
9
|
+
any,
|
|
10
|
+
][`length`] extends N
|
|
8
11
|
? A[`length`]
|
|
9
|
-
: A[`length`] |
|
|
12
|
+
: A[`length`] | Count<N, [...A, any]>
|
|
13
|
+
|
|
14
|
+
export type Each<E extends any[]> = {
|
|
15
|
+
[P in Count<E[`length`]>]: E[P]
|
|
16
|
+
}
|
package/json/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Count, Flat, Store, Transceiver } from 'atom.io/internal';
|
|
2
2
|
import * as AtomIO from 'atom.io';
|
|
3
3
|
|
|
4
4
|
type Entries<K extends PropertyKey = keyof any, V = any> = [K, V][];
|
|
5
5
|
type KeyOfEntries<E extends Entries> = E extends [infer K, any][] ? K : never;
|
|
6
6
|
type ValueOfEntry<E extends Entries, K extends KeyOfEntries<E>> = {
|
|
7
|
-
[P in
|
|
8
|
-
}[
|
|
7
|
+
[P in Count<E[`length`]>]: E[P] extends [K, infer V] ? V : never;
|
|
8
|
+
}[Count<E[`length`]>];
|
|
9
9
|
type FromEntries<E extends Entries> = Flat<{
|
|
10
10
|
[K in KeyOfEntries<E>]: ValueOfEntry<E, K>;
|
|
11
11
|
}>;
|
package/json/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { createWritableSelectorFamily } from '../../dist/chunk-
|
|
1
|
+
import { createWritableSelectorFamily } from '../../dist/chunk-7PUUHSXC.js';
|
|
2
|
+
import '../../dist/chunk-ZKG6ZA4I.js';
|
|
2
3
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
3
4
|
import { createStandaloneSelector, IMPLICIT, growMoleculeInStore, initFamilyMemberInStore, withdraw, seekInStore } from 'atom.io/internal';
|
|
4
5
|
|