atom.io 0.30.6 → 0.31.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.d.ts +20 -18
- package/data/dist/index.js +104 -172
- package/data/src/join.ts +138 -210
- package/dist/{chunk-LSCRHXLI.js → chunk-42UH5F5Q.js} +385 -773
- package/dist/chunk-ICGFFQ3H.js +272 -0
- package/dist/index.d.ts +52 -103
- package/dist/index.js +3 -11
- package/eslint-plugin/dist/index.d.ts +22 -3
- package/eslint-plugin/dist/index.js +7 -7
- package/immortal/dist/index.d.ts +1 -2
- package/immortal/dist/index.js +0 -3
- package/immortal/src/seek-state.ts +2 -14
- package/internal/dist/index.d.ts +59 -95
- package/internal/dist/index.js +2 -2
- package/internal/src/atom/dispose-atom.ts +31 -15
- package/internal/src/families/dispose-from-store.ts +15 -44
- package/internal/src/families/find-in-store.ts +15 -8
- package/internal/src/families/init-family-member.ts +1 -1
- package/internal/src/families/seek-in-store.ts +2 -14
- package/internal/src/get-state/get-from-store.ts +13 -79
- package/internal/src/get-trace.ts +7 -0
- package/internal/src/index.ts +2 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +63 -70
- package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
- package/internal/src/junction.ts +52 -12
- package/internal/src/lineage.ts +0 -7
- package/internal/src/molecule.ts +7 -0
- package/internal/src/mutable/transceiver.ts +5 -5
- package/internal/src/pretty-print.ts +0 -4
- package/internal/src/selector/dispose-selector.ts +3 -5
- package/internal/src/selector/register-selector.ts +2 -26
- package/internal/src/set-state/set-into-store.ts +3 -2
- package/internal/src/store/counterfeit.ts +11 -25
- package/internal/src/store/deposit.ts +5 -39
- package/internal/src/store/index.ts +1 -0
- package/internal/src/store/store.ts +51 -12
- package/internal/src/store/withdraw.ts +3 -26
- package/internal/src/timeline/create-timeline.ts +133 -237
- package/internal/src/timeline/time-travel.ts +1 -8
- package/internal/src/transaction/build-transaction.ts +10 -5
- package/internal/src/transaction/index.ts +1 -1
- package/internal/src/utility-types.ts +2 -0
- package/introspection/dist/index.d.ts +2 -3
- package/introspection/dist/index.js +9 -9
- package/introspection/src/refinery.ts +1 -3
- package/json/dist/index.js +9 -40
- package/json/src/index.ts +2 -0
- package/json/src/select-json-family.ts +7 -44
- package/package.json +34 -29
- package/react/dist/index.js +2 -10
- package/react/src/parse-state-overloads.ts +3 -11
- package/react-devtools/dist/index.js +13 -13
- package/react-devtools/src/Updates.tsx +2 -0
- package/realtime-client/dist/index.d.ts +20 -12
- package/realtime-client/dist/index.js +241 -244
- package/realtime-client/src/continuity/index.ts +3 -0
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
- package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
- package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
- package/realtime-client/src/index.ts +1 -0
- package/realtime-client/src/sync-continuity.ts +18 -262
- package/realtime-react/dist/index.js +2 -2
- package/realtime-server/dist/index.d.ts +1 -1
- package/realtime-server/dist/index.js +2 -2
- package/realtime-server/src/index.ts +1 -1
- package/realtime-testing/dist/index.js +2 -3
- package/realtime-testing/src/setup-realtime-test.tsx +1 -2
- package/src/allocate.ts +311 -145
- package/src/dispose-state.ts +5 -21
- package/src/get-state.ts +3 -21
- package/src/molecule.ts +11 -133
- package/src/silo.ts +1 -12
- package/src/timeline.ts +2 -3
- package/src/transaction.ts +25 -38
- package/dist/chunk-ADMEAXYU.js +0 -167
- package/internal/src/molecule/create-molecule-family.ts +0 -30
- package/internal/src/molecule/dispose-molecule.ts +0 -79
- package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
- package/internal/src/molecule/index.ts +0 -5
- package/internal/src/molecule/make-molecule-in-store.ts +0 -191
- package/internal/src/molecule/molecule-internal.ts +0 -52
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AtomFamilyToken,
|
|
3
3
|
AtomToken,
|
|
4
|
-
MoleculeConstructor,
|
|
5
|
-
MoleculeFamily,
|
|
6
|
-
MoleculeFamilyToken,
|
|
7
|
-
MoleculeToken,
|
|
8
4
|
MutableAtomFamilyToken,
|
|
9
5
|
MutableAtomToken,
|
|
10
6
|
ReadableFamilyToken,
|
|
@@ -27,7 +23,6 @@ import type {
|
|
|
27
23
|
Atom,
|
|
28
24
|
AtomFamily,
|
|
29
25
|
Func,
|
|
30
|
-
Molecule,
|
|
31
26
|
MutableAtom,
|
|
32
27
|
MutableAtomFamily,
|
|
33
28
|
ReadableFamily,
|
|
@@ -82,48 +77,19 @@ export function deposit<T>(
|
|
|
82
77
|
state: ReadableFamily<T, any>,
|
|
83
78
|
): ReadableFamilyToken<T, any>
|
|
84
79
|
|
|
85
|
-
export function deposit<M extends MoleculeConstructor>(
|
|
86
|
-
state: MoleculeFamily<M>,
|
|
87
|
-
): MoleculeFamilyToken<M>
|
|
88
|
-
export function deposit<M extends MoleculeConstructor>(
|
|
89
|
-
state: Molecule<M>,
|
|
90
|
-
): MoleculeToken<M>
|
|
91
|
-
|
|
92
80
|
export function deposit<T extends Func>(
|
|
93
81
|
state: Transaction<T>,
|
|
94
82
|
): TransactionToken<T>
|
|
95
83
|
|
|
96
|
-
export function deposit(
|
|
97
|
-
state: Molecule<any> | ReadableState<any>,
|
|
98
|
-
): MoleculeToken<any> | ReadableToken<any>
|
|
84
|
+
export function deposit(state: ReadableState<any>): ReadableToken<any>
|
|
99
85
|
|
|
100
86
|
export function deposit(
|
|
101
|
-
state:
|
|
102
|
-
|
|
103
|
-
| MoleculeFamily<any>
|
|
104
|
-
| ReadableFamily<any, any>
|
|
105
|
-
| ReadableState<any>
|
|
106
|
-
| Transaction<Func>,
|
|
107
|
-
):
|
|
108
|
-
| MoleculeFamilyToken<any>
|
|
109
|
-
| MoleculeToken<any>
|
|
110
|
-
| ReadableFamilyToken<any, any>
|
|
111
|
-
| ReadableToken<any>
|
|
112
|
-
| TransactionToken<Func>
|
|
87
|
+
state: ReadableFamily<any, any> | ReadableState<any> | Transaction<Func>,
|
|
88
|
+
): ReadableFamilyToken<any, any> | ReadableToken<any> | TransactionToken<Func>
|
|
113
89
|
|
|
114
90
|
export function deposit(
|
|
115
|
-
state:
|
|
116
|
-
|
|
117
|
-
| MoleculeFamily<any>
|
|
118
|
-
| ReadableFamily<any, any>
|
|
119
|
-
| ReadableState<any>
|
|
120
|
-
| Transaction<Func>,
|
|
121
|
-
):
|
|
122
|
-
| MoleculeFamilyToken<any>
|
|
123
|
-
| MoleculeToken<any>
|
|
124
|
-
| ReadableFamilyToken<any, any>
|
|
125
|
-
| ReadableToken<any>
|
|
126
|
-
| TransactionToken<Func> {
|
|
91
|
+
state: ReadableFamily<any, any> | ReadableState<any> | Transaction<Func>,
|
|
92
|
+
): ReadableFamilyToken<any, any> | ReadableToken<any> | TransactionToken<Func> {
|
|
127
93
|
const token = {
|
|
128
94
|
key: state.key,
|
|
129
95
|
type: state.type,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AtomToken,
|
|
3
3
|
Logger,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
MoleculeFamily,
|
|
7
|
-
MoleculeToken,
|
|
4
|
+
MoleculeCreation,
|
|
5
|
+
MoleculeDisposal,
|
|
8
6
|
ReadonlySelectorToken,
|
|
9
7
|
TimelineToken,
|
|
10
8
|
TransactionToken,
|
|
11
9
|
WritableSelectorToken,
|
|
12
10
|
} from "atom.io"
|
|
13
11
|
import { AtomIOLogger } from "atom.io"
|
|
12
|
+
import type { Join } from "atom.io/data"
|
|
13
|
+
import type { Canonical, stringified } from "atom.io/json"
|
|
14
14
|
|
|
15
15
|
import type {
|
|
16
16
|
Atom,
|
|
@@ -77,6 +77,7 @@ export class Store implements Lineage {
|
|
|
77
77
|
| RegularAtomFamily<any, any>
|
|
78
78
|
| WritableSelectorFamily<any, any>
|
|
79
79
|
>()
|
|
80
|
+
public joins = new Map<string, Join<any, any, any, any, any, any>>()
|
|
80
81
|
|
|
81
82
|
public transactions = new Map<string, Transaction<Func>>()
|
|
82
83
|
public transactionMeta: TransactionEpoch | TransactionProgress<Func> = {
|
|
@@ -101,9 +102,50 @@ export class Store implements Lineage {
|
|
|
101
102
|
|
|
102
103
|
public disposalTraces = new CircularBuffer<{ key: string; trace: string }>(100)
|
|
103
104
|
|
|
104
|
-
public molecules = new Map<string, Molecule<
|
|
105
|
-
public
|
|
106
|
-
|
|
105
|
+
public molecules = new Map<string, Molecule<Canonical>>()
|
|
106
|
+
public moleculeJoins = new Junction<
|
|
107
|
+
`moleculeKey`,
|
|
108
|
+
stringified<Canonical>,
|
|
109
|
+
`joinKey`,
|
|
110
|
+
string
|
|
111
|
+
>(
|
|
112
|
+
{
|
|
113
|
+
between: [`moleculeKey`, `joinKey`],
|
|
114
|
+
cardinality: `n:n`,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
makeContentKey: (...keys) => keys.sort().join(`:`),
|
|
118
|
+
},
|
|
119
|
+
)
|
|
120
|
+
public moleculeGraph = new Junction<
|
|
121
|
+
`upstreamMoleculeKey`,
|
|
122
|
+
stringified<Canonical> | `root`,
|
|
123
|
+
`downstreamMoleculeKey`,
|
|
124
|
+
stringified<Canonical>,
|
|
125
|
+
{ source: stringified<Canonical> }
|
|
126
|
+
>(
|
|
127
|
+
{
|
|
128
|
+
between: [`upstreamMoleculeKey`, `downstreamMoleculeKey`],
|
|
129
|
+
cardinality: `n:n`,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
makeContentKey: (...keys) => keys.sort().join(`:`),
|
|
133
|
+
},
|
|
134
|
+
)
|
|
135
|
+
public moleculeData = new Junction<
|
|
136
|
+
`moleculeKey`,
|
|
137
|
+
stringified<Canonical>,
|
|
138
|
+
`stateFamilyKey`,
|
|
139
|
+
string
|
|
140
|
+
>(
|
|
141
|
+
{
|
|
142
|
+
between: [`moleculeKey`, `stateFamilyKey`],
|
|
143
|
+
cardinality: `n:n`,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
makeContentKey: (...keys) => keys.sort().join(`:`),
|
|
147
|
+
},
|
|
148
|
+
)
|
|
107
149
|
public miscResources = new Map<string, Disposable>()
|
|
108
150
|
|
|
109
151
|
public on = {
|
|
@@ -121,11 +163,8 @@ export class Store implements Lineage {
|
|
|
121
163
|
null,
|
|
122
164
|
),
|
|
123
165
|
operationClose: new Subject<OperationProgress>(),
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
>(),
|
|
127
|
-
moleculeCreationDone: new Subject<MoleculeToken<any>>(),
|
|
128
|
-
moleculeDisposal: new Subject<MoleculeDisposalModern | MoleculeToken<any>>(),
|
|
166
|
+
moleculeCreation: new Subject<MoleculeCreation>(),
|
|
167
|
+
moleculeDisposal: new Subject<MoleculeDisposal>(),
|
|
129
168
|
}
|
|
130
169
|
public operation: OperationProgress = { open: false }
|
|
131
170
|
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AtomFamilyToken,
|
|
3
3
|
AtomToken,
|
|
4
|
-
MoleculeConstructor,
|
|
5
|
-
MoleculeFamily,
|
|
6
|
-
MoleculeFamilyToken,
|
|
7
|
-
MoleculeToken,
|
|
8
4
|
MutableAtomFamilyToken,
|
|
9
5
|
MutableAtomToken,
|
|
10
6
|
ReadableFamilyToken,
|
|
@@ -24,7 +20,6 @@ import type {
|
|
|
24
20
|
WritableToken,
|
|
25
21
|
} from "atom.io"
|
|
26
22
|
import type { Canonical, Json } from "atom.io/json"
|
|
27
|
-
import { stringifyJson } from "atom.io/json"
|
|
28
23
|
|
|
29
24
|
import type {
|
|
30
25
|
Atom,
|
|
@@ -56,7 +51,6 @@ export type Withdrawable =
|
|
|
56
51
|
| Atom<any>
|
|
57
52
|
| AtomFamily<any, any>
|
|
58
53
|
| Molecule<any>
|
|
59
|
-
| MoleculeFamily<any>
|
|
60
54
|
| MutableAtom<any, any>
|
|
61
55
|
| MutableAtomFamily<any, any, any>
|
|
62
56
|
| ReadableFamily<any, any>
|
|
@@ -138,15 +132,6 @@ export function withdraw<T, K extends Canonical>(
|
|
|
138
132
|
store: Store,
|
|
139
133
|
): WritableFamily<T, any>
|
|
140
134
|
|
|
141
|
-
export function withdraw<M extends MoleculeConstructor>(
|
|
142
|
-
token: MoleculeToken<M>,
|
|
143
|
-
store: Store,
|
|
144
|
-
): Molecule<M>
|
|
145
|
-
export function withdraw<M extends MoleculeConstructor>(
|
|
146
|
-
token: MoleculeFamilyToken<M>,
|
|
147
|
-
store: Store,
|
|
148
|
-
): MoleculeFamily<M>
|
|
149
|
-
|
|
150
135
|
export function withdraw<T extends Func>(
|
|
151
136
|
token: TransactionToken<T>,
|
|
152
137
|
store: Store,
|
|
@@ -156,15 +141,13 @@ export function withdraw<T>(
|
|
|
156
141
|
store: Store,
|
|
157
142
|
): Timeline<T extends TimelineManageable ? T : never>
|
|
158
143
|
|
|
159
|
-
export function withdraw<T
|
|
160
|
-
token:
|
|
144
|
+
export function withdraw<T>(
|
|
145
|
+
token: ReadableToken<T>,
|
|
161
146
|
store: Store,
|
|
162
|
-
):
|
|
147
|
+
): ReadableState<T>
|
|
163
148
|
|
|
164
149
|
export function withdraw(
|
|
165
150
|
token:
|
|
166
|
-
| MoleculeFamilyToken<any>
|
|
167
|
-
| MoleculeToken<any>
|
|
168
151
|
| MutableAtomFamilyToken<any, any, any>
|
|
169
152
|
| MutableAtomToken<any, any>
|
|
170
153
|
| RegularAtomFamilyToken<any, any>
|
|
@@ -201,12 +184,6 @@ export function withdraw(
|
|
|
201
184
|
case `transaction`:
|
|
202
185
|
withdrawn = target.transactions.get(token.key)
|
|
203
186
|
break
|
|
204
|
-
case `molecule`:
|
|
205
|
-
withdrawn = target.molecules.get(stringifyJson(token.key))
|
|
206
|
-
break
|
|
207
|
-
case `molecule_family`:
|
|
208
|
-
withdrawn = target.moleculeFamilies.get(token.key)
|
|
209
|
-
break
|
|
210
187
|
}
|
|
211
188
|
if (withdrawn) {
|
|
212
189
|
return withdrawn
|
|
@@ -2,10 +2,8 @@ import type {
|
|
|
2
2
|
AtomFamilyToken,
|
|
3
3
|
AtomToken,
|
|
4
4
|
FamilyMetadata,
|
|
5
|
-
MoleculeConstructor,
|
|
6
5
|
MoleculeCreation,
|
|
7
6
|
MoleculeDisposal,
|
|
8
|
-
MoleculeFamilyToken,
|
|
9
7
|
ReadableToken,
|
|
10
8
|
StateCreation,
|
|
11
9
|
StateDisposal,
|
|
@@ -55,8 +53,8 @@ export type TimelineStateCreation<T extends ReadableToken<any>> = Flat<
|
|
|
55
53
|
export type TimelineStateDisposal<T extends ReadableToken<any>> = Flat<
|
|
56
54
|
StateDisposal<T> & { timestamp: number }
|
|
57
55
|
>
|
|
58
|
-
export type TimelineMoleculeCreation
|
|
59
|
-
MoleculeCreation
|
|
56
|
+
export type TimelineMoleculeCreation = Flat<
|
|
57
|
+
MoleculeCreation & { timestamp: number }
|
|
60
58
|
>
|
|
61
59
|
export type TimelineMoleculeDisposal = Flat<
|
|
62
60
|
MoleculeDisposal & { timestamp: number }
|
|
@@ -157,24 +155,24 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
|
|
|
157
155
|
}
|
|
158
156
|
break
|
|
159
157
|
|
|
160
|
-
case `molecule_family`:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
158
|
+
// case `molecule_family`:
|
|
159
|
+
// {
|
|
160
|
+
// const familyToken: MoleculeFamilyToken<any> = initialTopic
|
|
161
|
+
// const familyKey = familyToken.key
|
|
162
|
+
// const existingTimelineKey =
|
|
163
|
+
// target.timelineTopics.getRelatedKey(familyKey)
|
|
164
|
+
// if (existingTimelineKey) {
|
|
165
|
+
// store.logger.error(
|
|
166
|
+
// `❌`,
|
|
167
|
+
// `timeline`,
|
|
168
|
+
// options.key,
|
|
169
|
+
// `Failed to add molecule family "${familyKey}" because it already belongs to timeline "${existingTimelineKey}"`,
|
|
170
|
+
// )
|
|
171
|
+
// continue
|
|
172
|
+
// }
|
|
173
|
+
// addMoleculeFamilyToTimeline(familyToken, tl, store)
|
|
174
|
+
// }
|
|
175
|
+
// break
|
|
178
176
|
}
|
|
179
177
|
}
|
|
180
178
|
|
|
@@ -205,126 +203,129 @@ function addAtomToTimeline(
|
|
|
205
203
|
|
|
206
204
|
tl.subscriptions.set(
|
|
207
205
|
atom.key,
|
|
208
|
-
atom.subject.subscribe(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
store.logger.info(
|
|
222
|
-
`⏳`,
|
|
223
|
-
`timeline`,
|
|
224
|
-
tl.key,
|
|
225
|
-
`atom`,
|
|
226
|
-
atomToken.key,
|
|
227
|
-
`went`,
|
|
228
|
-
update.oldValue,
|
|
229
|
-
`->`,
|
|
230
|
-
update.newValue,
|
|
231
|
-
txUpdateInProgress
|
|
232
|
-
? `in transaction "${txUpdateInProgress.key}"`
|
|
233
|
-
: currentSelectorKey
|
|
234
|
-
? `in selector "${currentSelectorKey}"`
|
|
235
|
-
: ``,
|
|
236
|
-
)
|
|
237
|
-
if (tl.timeTraveling === null) {
|
|
238
|
-
if (txUpdateInProgress) {
|
|
239
|
-
joinTransaction(tl, txUpdateInProgress, store)
|
|
240
|
-
} else if (currentSelectorKey && currentSelectorTime) {
|
|
241
|
-
let latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)
|
|
242
|
-
|
|
243
|
-
if (currentSelectorTime !== tl.selectorTime) {
|
|
244
|
-
latestUpdate = {
|
|
245
|
-
type: `selector_update`,
|
|
246
|
-
timestamp: currentSelectorTime,
|
|
247
|
-
key: currentSelectorKey,
|
|
248
|
-
atomUpdates: [],
|
|
249
|
-
}
|
|
250
|
-
latestUpdate.atomUpdates.push({
|
|
251
|
-
key: atom.key,
|
|
252
|
-
type: `atom_update`,
|
|
253
|
-
...update,
|
|
254
|
-
})
|
|
255
|
-
if (tl.at !== tl.history.length) {
|
|
256
|
-
tl.history.splice(tl.at)
|
|
257
|
-
}
|
|
206
|
+
atom.subject.subscribe(
|
|
207
|
+
`timeline`,
|
|
208
|
+
function timelineCapturesAtomUpdate(update) {
|
|
209
|
+
const target = newest(store)
|
|
210
|
+
const currentSelectorKey =
|
|
211
|
+
store.operation.open && store.operation.token.type === `selector`
|
|
212
|
+
? store.operation.token.key
|
|
213
|
+
: null
|
|
214
|
+
const currentSelectorTime =
|
|
215
|
+
store.operation.open && store.operation.token.type === `selector`
|
|
216
|
+
? store.operation.time
|
|
217
|
+
: null
|
|
258
218
|
|
|
259
|
-
|
|
219
|
+
const txUpdateInProgress = target.on.transactionApplying.state?.update
|
|
260
220
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
221
|
+
store.logger.info(
|
|
222
|
+
`⏳`,
|
|
223
|
+
`timeline`,
|
|
224
|
+
tl.key,
|
|
225
|
+
`atom`,
|
|
226
|
+
atomToken.key,
|
|
227
|
+
`went`,
|
|
228
|
+
update.oldValue,
|
|
229
|
+
`->`,
|
|
230
|
+
update.newValue,
|
|
231
|
+
txUpdateInProgress
|
|
232
|
+
? `in transaction "${txUpdateInProgress.key}"`
|
|
233
|
+
: currentSelectorKey
|
|
234
|
+
? `in selector "${currentSelectorKey}"`
|
|
235
|
+
: ``,
|
|
236
|
+
)
|
|
237
|
+
if (tl.timeTraveling === null) {
|
|
238
|
+
if (txUpdateInProgress) {
|
|
239
|
+
joinTransaction(tl, txUpdateInProgress, store)
|
|
240
|
+
} else if (currentSelectorKey && currentSelectorTime) {
|
|
241
|
+
let latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)
|
|
268
242
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
243
|
+
if (currentSelectorTime !== tl.selectorTime) {
|
|
244
|
+
latestUpdate = {
|
|
245
|
+
type: `selector_update`,
|
|
246
|
+
timestamp: currentSelectorTime,
|
|
247
|
+
key: currentSelectorKey,
|
|
248
|
+
atomUpdates: [],
|
|
249
|
+
}
|
|
273
250
|
latestUpdate.atomUpdates.push({
|
|
274
251
|
key: atom.key,
|
|
275
252
|
type: `atom_update`,
|
|
276
253
|
...update,
|
|
277
254
|
})
|
|
255
|
+
if (tl.at !== tl.history.length) {
|
|
256
|
+
tl.history.splice(tl.at)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
tl.history.push(latestUpdate)
|
|
260
|
+
|
|
278
261
|
store.logger.info(
|
|
279
262
|
`⌛`,
|
|
280
263
|
`timeline`,
|
|
281
264
|
tl.key,
|
|
282
|
-
`
|
|
283
|
-
latestUpdate
|
|
265
|
+
`got a selector_update "${currentSelectorKey}" with`,
|
|
266
|
+
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),
|
|
284
267
|
)
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const willCaptureSelectorUpdate =
|
|
289
|
-
tl.shouldCapture?.(latestUpdate, tl) ?? true
|
|
290
|
-
if (willCaptureSelectorUpdate) {
|
|
291
|
-
tl.subject.next(latestUpdate)
|
|
268
|
+
|
|
269
|
+
tl.at = tl.history.length
|
|
270
|
+
tl.selectorTime = currentSelectorTime
|
|
292
271
|
} else {
|
|
293
|
-
|
|
272
|
+
if (latestUpdate?.type === `selector_update`) {
|
|
273
|
+
latestUpdate.atomUpdates.push({
|
|
274
|
+
key: atom.key,
|
|
275
|
+
type: `atom_update`,
|
|
276
|
+
...update,
|
|
277
|
+
})
|
|
278
|
+
store.logger.info(
|
|
279
|
+
`⌛`,
|
|
280
|
+
`timeline`,
|
|
281
|
+
tl.key,
|
|
282
|
+
`set selector_update "${currentSelectorKey}" to`,
|
|
283
|
+
latestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (latestUpdate) {
|
|
288
|
+
const willCaptureSelectorUpdate =
|
|
289
|
+
tl.shouldCapture?.(latestUpdate, tl) ?? true
|
|
290
|
+
if (willCaptureSelectorUpdate) {
|
|
291
|
+
tl.subject.next(latestUpdate)
|
|
292
|
+
} else {
|
|
293
|
+
tl.history.pop()
|
|
294
|
+
tl.at = tl.history.length
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
const timestamp = Date.now()
|
|
299
|
+
tl.selectorTime = null
|
|
300
|
+
if (tl.at !== tl.history.length) {
|
|
301
|
+
tl.history.splice(tl.at)
|
|
302
|
+
}
|
|
303
|
+
const atomUpdate: TimelineAtomUpdate<any> = {
|
|
304
|
+
type: `atom_update`,
|
|
305
|
+
timestamp,
|
|
306
|
+
key: atom.key,
|
|
307
|
+
oldValue: update.oldValue,
|
|
308
|
+
newValue: update.newValue,
|
|
309
|
+
}
|
|
310
|
+
if (atom.family) {
|
|
311
|
+
atomUpdate.family = atom.family
|
|
312
|
+
}
|
|
313
|
+
const willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true
|
|
314
|
+
store.logger.info(
|
|
315
|
+
`⌛`,
|
|
316
|
+
`timeline`,
|
|
317
|
+
tl.key,
|
|
318
|
+
`got an atom_update to "${atom.key}"`,
|
|
319
|
+
)
|
|
320
|
+
if (willCapture) {
|
|
321
|
+
tl.history.push(atomUpdate)
|
|
294
322
|
tl.at = tl.history.length
|
|
323
|
+
tl.subject.next(atomUpdate)
|
|
295
324
|
}
|
|
296
325
|
}
|
|
297
|
-
} else {
|
|
298
|
-
const timestamp = Date.now()
|
|
299
|
-
tl.selectorTime = null
|
|
300
|
-
if (tl.at !== tl.history.length) {
|
|
301
|
-
tl.history.splice(tl.at)
|
|
302
|
-
}
|
|
303
|
-
const atomUpdate: TimelineAtomUpdate<any> = {
|
|
304
|
-
type: `atom_update`,
|
|
305
|
-
timestamp,
|
|
306
|
-
key: atom.key,
|
|
307
|
-
oldValue: update.oldValue,
|
|
308
|
-
newValue: update.newValue,
|
|
309
|
-
}
|
|
310
|
-
if (atom.family) {
|
|
311
|
-
atomUpdate.family = atom.family
|
|
312
|
-
}
|
|
313
|
-
const willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true
|
|
314
|
-
store.logger.info(
|
|
315
|
-
`⌛`,
|
|
316
|
-
`timeline`,
|
|
317
|
-
tl.key,
|
|
318
|
-
`got an atom_update to "${atom.key}"`,
|
|
319
|
-
)
|
|
320
|
-
if (willCapture) {
|
|
321
|
-
tl.history.push(atomUpdate)
|
|
322
|
-
tl.at = tl.history.length
|
|
323
|
-
tl.subject.next(atomUpdate)
|
|
324
|
-
}
|
|
325
326
|
}
|
|
326
|
-
}
|
|
327
|
-
|
|
327
|
+
},
|
|
328
|
+
),
|
|
328
329
|
)
|
|
329
330
|
}
|
|
330
331
|
|
|
@@ -340,9 +341,12 @@ function addAtomFamilyToTimeline(
|
|
|
340
341
|
)
|
|
341
342
|
tl.subscriptions.set(
|
|
342
343
|
family.key,
|
|
343
|
-
family.subject.subscribe(
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
family.subject.subscribe(
|
|
345
|
+
`timeline`,
|
|
346
|
+
function timelineCapturesStateLifecycleEvent(creationOrDisposal) {
|
|
347
|
+
handleStateLifecycleEvent(creationOrDisposal, tl, store)
|
|
348
|
+
},
|
|
349
|
+
),
|
|
346
350
|
)
|
|
347
351
|
for (const atom of store.atoms.values()) {
|
|
348
352
|
if (atom.family?.key === family.key) {
|
|
@@ -351,108 +355,6 @@ function addAtomFamilyToTimeline(
|
|
|
351
355
|
}
|
|
352
356
|
}
|
|
353
357
|
|
|
354
|
-
function addMoleculeFamilyToTimeline(
|
|
355
|
-
familyToken: MoleculeFamilyToken<any>,
|
|
356
|
-
tl: Timeline<any>,
|
|
357
|
-
store: Store,
|
|
358
|
-
): void {
|
|
359
|
-
store.timelineTopics.set(
|
|
360
|
-
{ topicKey: familyToken.key, timelineKey: tl.key },
|
|
361
|
-
{ topicType: `molecule_family` },
|
|
362
|
-
)
|
|
363
|
-
const family = store.moleculeFamilies.get(familyToken.key)
|
|
364
|
-
if (family) {
|
|
365
|
-
tl.subscriptions.set(
|
|
366
|
-
familyToken.key,
|
|
367
|
-
family.subject.subscribe(`timeline:${tl.key}`, (creationOrDisposal) => {
|
|
368
|
-
store.logger.info(
|
|
369
|
-
`🐞`,
|
|
370
|
-
`timeline`,
|
|
371
|
-
tl.key,
|
|
372
|
-
`got a molecule creation or disposal`,
|
|
373
|
-
creationOrDisposal,
|
|
374
|
-
)
|
|
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)
|
|
399
|
-
|
|
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
|
-
}
|
|
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
|
-
)
|
|
421
|
-
}
|
|
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
|
-
}
|
|
447
|
-
}
|
|
448
|
-
break
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
}),
|
|
452
|
-
)
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
358
|
function joinTransaction(
|
|
457
359
|
tl: Timeline<any>,
|
|
458
360
|
txUpdateInProgress: TransactionUpdate<Func>,
|
|
@@ -523,14 +425,8 @@ function filterTransactionUpdates(
|
|
|
523
425
|
break
|
|
524
426
|
case `molecule_creation`:
|
|
525
427
|
case `molecule_disposal`:
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
key = updateFromTx.token.key
|
|
529
|
-
break
|
|
530
|
-
case `modern`:
|
|
531
|
-
return true // always include
|
|
532
|
-
}
|
|
533
|
-
break
|
|
428
|
+
case `molecule_transfer`:
|
|
429
|
+
return true // always include
|
|
534
430
|
default:
|
|
535
431
|
key = updateFromTx.key
|
|
536
432
|
familyKey = updateFromTx.family?.key
|
|
@@ -76,14 +76,7 @@ export const timeTravel = (
|
|
|
76
76
|
ingestDisposalEvent(update, applying, store)
|
|
77
77
|
break
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
ingestMoleculeCreationEvent(update, applying, store)
|
|
81
|
-
break
|
|
82
|
-
}
|
|
83
|
-
case `molecule_disposal`: {
|
|
84
|
-
ingestMoleculeDisposalEvent(update, applying, store)
|
|
85
|
-
break
|
|
86
|
-
}
|
|
79
|
+
// consider adding molecule events
|
|
87
80
|
}
|
|
88
81
|
|
|
89
82
|
if (action === `redo`) {
|