atom.io 0.30.7 → 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.
Files changed (80) hide show
  1. package/data/dist/index.d.ts +20 -18
  2. package/data/dist/index.js +104 -172
  3. package/data/src/join.ts +138 -210
  4. package/dist/{chunk-UDHCFTYT.js → chunk-42UH5F5Q.js} +356 -744
  5. package/dist/chunk-ICGFFQ3H.js +272 -0
  6. package/dist/index.d.ts +52 -103
  7. package/dist/index.js +3 -11
  8. package/eslint-plugin/dist/index.d.ts +22 -3
  9. package/eslint-plugin/dist/index.js +7 -7
  10. package/immortal/dist/index.d.ts +1 -2
  11. package/immortal/dist/index.js +0 -3
  12. package/immortal/src/seek-state.ts +2 -14
  13. package/internal/dist/index.d.ts +48 -84
  14. package/internal/dist/index.js +2 -2
  15. package/internal/src/atom/dispose-atom.ts +31 -15
  16. package/internal/src/families/dispose-from-store.ts +15 -44
  17. package/internal/src/families/find-in-store.ts +15 -8
  18. package/internal/src/families/init-family-member.ts +1 -1
  19. package/internal/src/families/seek-in-store.ts +2 -14
  20. package/internal/src/get-state/get-from-store.ts +13 -79
  21. package/internal/src/get-trace.ts +7 -0
  22. package/internal/src/index.ts +2 -1
  23. package/internal/src/ingest-updates/ingest-creation-disposal.ts +63 -70
  24. package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
  25. package/internal/src/junction.ts +52 -12
  26. package/internal/src/lineage.ts +0 -7
  27. package/internal/src/molecule.ts +7 -0
  28. package/internal/src/mutable/transceiver.ts +5 -5
  29. package/internal/src/pretty-print.ts +0 -4
  30. package/internal/src/selector/dispose-selector.ts +3 -5
  31. package/internal/src/selector/register-selector.ts +2 -26
  32. package/internal/src/set-state/set-into-store.ts +3 -2
  33. package/internal/src/store/counterfeit.ts +11 -25
  34. package/internal/src/store/deposit.ts +5 -39
  35. package/internal/src/store/store.ts +51 -12
  36. package/internal/src/store/withdraw.ts +3 -26
  37. package/internal/src/timeline/create-timeline.ts +133 -237
  38. package/internal/src/timeline/time-travel.ts +1 -8
  39. package/internal/src/transaction/build-transaction.ts +10 -5
  40. package/internal/src/transaction/index.ts +1 -1
  41. package/internal/src/utility-types.ts +2 -0
  42. package/introspection/dist/index.d.ts +2 -3
  43. package/introspection/dist/index.js +9 -9
  44. package/introspection/src/refinery.ts +1 -3
  45. package/json/dist/index.js +9 -40
  46. package/json/src/index.ts +2 -0
  47. package/json/src/select-json-family.ts +7 -44
  48. package/package.json +33 -28
  49. package/react/dist/index.js +2 -10
  50. package/react/src/parse-state-overloads.ts +3 -11
  51. package/react-devtools/dist/index.js +13 -13
  52. package/react-devtools/src/Updates.tsx +2 -0
  53. package/realtime-client/dist/index.d.ts +20 -12
  54. package/realtime-client/dist/index.js +241 -244
  55. package/realtime-client/src/continuity/index.ts +3 -0
  56. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
  57. package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
  58. package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
  59. package/realtime-client/src/index.ts +1 -0
  60. package/realtime-client/src/sync-continuity.ts +18 -262
  61. package/realtime-react/dist/index.js +2 -2
  62. package/realtime-server/dist/index.d.ts +1 -1
  63. package/realtime-server/dist/index.js +2 -2
  64. package/realtime-server/src/index.ts +1 -1
  65. package/realtime-testing/dist/index.js +2 -3
  66. package/realtime-testing/src/setup-realtime-test.tsx +1 -2
  67. package/src/allocate.ts +311 -145
  68. package/src/dispose-state.ts +5 -21
  69. package/src/get-state.ts +3 -21
  70. package/src/molecule.ts +11 -133
  71. package/src/silo.ts +1 -12
  72. package/src/timeline.ts +2 -3
  73. package/src/transaction.ts +25 -38
  74. package/dist/chunk-ADMEAXYU.js +0 -167
  75. package/internal/src/molecule/create-molecule-family.ts +0 -30
  76. package/internal/src/molecule/dispose-molecule.ts +0 -79
  77. package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
  78. package/internal/src/molecule/index.ts +0 -5
  79. package/internal/src/molecule/make-molecule-in-store.ts +0 -191
  80. 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
- | Molecule<any>
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
- | Molecule<any>
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
- MoleculeCreationModern,
5
- MoleculeDisposalModern,
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<any>>()
105
- public moleculeFamilies = new Map<string, MoleculeFamily<any>>()
106
- public moleculeInProgress: string | null = null
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
- moleculeCreationStart: new Subject<
125
- MoleculeCreationModern | MoleculeToken<any>
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, M extends MoleculeConstructor>(
160
- token: MoleculeToken<M> | ReadableToken<T>,
144
+ export function withdraw<T>(
145
+ token: ReadableToken<T>,
161
146
  store: Store,
162
- ): Molecule<M> | ReadableState<T>
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<M extends MoleculeConstructor> = Flat<
59
- MoleculeCreation<M> & { timestamp: number }
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
- const familyToken: MoleculeFamilyToken<any> = initialTopic
163
- const familyKey = familyToken.key
164
- const existingTimelineKey =
165
- target.timelineTopics.getRelatedKey(familyKey)
166
- if (existingTimelineKey) {
167
- store.logger.error(
168
- `❌`,
169
- `timeline`,
170
- options.key,
171
- `Failed to add molecule family "${familyKey}" because it already belongs to timeline "${existingTimelineKey}"`,
172
- )
173
- continue
174
- }
175
- addMoleculeFamilyToTimeline(familyToken, tl, store)
176
- }
177
- break
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(`timeline`, (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
218
-
219
- const txUpdateInProgress = target.on.transactionApplying.state?.update
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
- tl.history.push(latestUpdate)
219
+ const txUpdateInProgress = target.on.transactionApplying.state?.update
260
220
 
261
- store.logger.info(
262
- `⌛`,
263
- `timeline`,
264
- tl.key,
265
- `got a selector_update "${currentSelectorKey}" with`,
266
- latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),
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
- tl.at = tl.history.length
270
- tl.selectorTime = currentSelectorTime
271
- } else {
272
- if (latestUpdate?.type === `selector_update`) {
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
- `set selector_update "${currentSelectorKey}" to`,
283
- latestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),
265
+ `got a selector_update "${currentSelectorKey}" with`,
266
+ latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),
284
267
  )
285
- }
286
- }
287
- if (latestUpdate) {
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
- tl.history.pop()
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(`timeline`, (creationOrDisposal) => {
344
- handleStateLifecycleEvent(creationOrDisposal, tl, store)
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
- switch (updateFromTx.subType) {
527
- case `classic`:
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
- case `molecule_creation`: {
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`) {