atom.io 0.30.7 → 0.31.1

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 (92) 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-Y5MBNTVU.js} +582 -762
  5. package/dist/index.d.ts +254 -173
  6. package/dist/index.js +91 -14
  7. package/ephemeral/dist/index.d.ts +35 -25
  8. package/ephemeral/src/find-state.ts +35 -25
  9. package/eslint-plugin/dist/index.d.ts +22 -3
  10. package/eslint-plugin/dist/index.js +7 -7
  11. package/immortal/dist/index.d.ts +1 -2
  12. package/immortal/dist/index.js +0 -3
  13. package/immortal/src/seek-state.ts +2 -14
  14. package/internal/dist/index.d.ts +57 -88
  15. package/internal/dist/index.js +1 -2
  16. package/internal/src/atom/dispose-atom.ts +31 -15
  17. package/internal/src/families/dispose-from-store.ts +15 -44
  18. package/internal/src/families/find-in-store.ts +9 -7
  19. package/internal/src/families/init-family-member.ts +1 -1
  20. package/internal/src/families/seek-in-store.ts +2 -14
  21. package/internal/src/get-state/get-from-store.ts +13 -79
  22. package/internal/src/get-trace.ts +7 -0
  23. package/internal/src/index.ts +17 -8
  24. package/internal/src/ingest-updates/ingest-creation-disposal.ts +65 -73
  25. package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
  26. package/internal/src/install-into-store.ts +48 -0
  27. package/internal/src/junction.ts +52 -12
  28. package/internal/src/lineage.ts +0 -7
  29. package/internal/src/molecule.ts +306 -0
  30. package/internal/src/mutable/transceiver.ts +5 -5
  31. package/internal/src/not-found-error.ts +8 -30
  32. package/internal/src/pretty-print.ts +1 -16
  33. package/internal/src/selector/dispose-selector.ts +3 -5
  34. package/internal/src/selector/register-selector.ts +3 -34
  35. package/internal/src/set-state/set-into-store.ts +3 -2
  36. package/internal/src/store/counterfeit.ts +11 -25
  37. package/internal/src/store/deposit.ts +10 -42
  38. package/internal/src/store/store.ts +51 -12
  39. package/internal/src/store/withdraw.ts +18 -60
  40. package/internal/src/timeline/create-timeline.ts +133 -237
  41. package/internal/src/timeline/time-travel.ts +1 -8
  42. package/internal/src/transaction/build-transaction.ts +10 -5
  43. package/internal/src/transaction/index.ts +1 -1
  44. package/internal/src/utility-types.ts +2 -0
  45. package/introspection/dist/index.d.ts +2 -3
  46. package/introspection/dist/index.js +9 -9
  47. package/introspection/src/refinery.ts +1 -3
  48. package/json/dist/index.js +8 -40
  49. package/json/src/index.ts +2 -0
  50. package/json/src/select-json-family.ts +7 -44
  51. package/package.json +33 -28
  52. package/react/dist/index.js +2 -10
  53. package/react/src/parse-state-overloads.ts +3 -11
  54. package/react-devtools/dist/index.js +13 -13
  55. package/react-devtools/src/Updates.tsx +2 -0
  56. package/realtime-client/dist/index.d.ts +20 -12
  57. package/realtime-client/dist/index.js +241 -244
  58. package/realtime-client/src/continuity/index.ts +3 -0
  59. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
  60. package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
  61. package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
  62. package/realtime-client/src/index.ts +1 -0
  63. package/realtime-client/src/sync-continuity.ts +18 -262
  64. package/realtime-react/dist/index.js +2 -2
  65. package/realtime-server/dist/index.d.ts +1 -1
  66. package/realtime-server/dist/index.js +2 -2
  67. package/realtime-server/src/index.ts +1 -1
  68. package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
  69. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
  70. package/realtime-testing/dist/index.js +5 -7
  71. package/realtime-testing/src/setup-realtime-test.tsx +5 -6
  72. package/src/atom.ts +53 -29
  73. package/src/dispose-state.ts +17 -23
  74. package/src/get-state.ts +19 -21
  75. package/src/index.ts +73 -3
  76. package/src/realm.ts +169 -0
  77. package/src/selector.ts +20 -0
  78. package/src/set-state.ts +16 -8
  79. package/src/silo.ts +9 -14
  80. package/src/timeline.ts +2 -3
  81. package/src/transaction.ts +25 -38
  82. package/transceivers/set-rtx/dist/index.js +4 -1
  83. package/transceivers/set-rtx/src/set-rtx.ts +4 -1
  84. package/dist/chunk-ADMEAXYU.js +0 -167
  85. package/internal/src/molecule/create-molecule-family.ts +0 -30
  86. package/internal/src/molecule/dispose-molecule.ts +0 -79
  87. package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
  88. package/internal/src/molecule/index.ts +0 -5
  89. package/internal/src/molecule/make-molecule-in-store.ts +0 -191
  90. package/internal/src/molecule/molecule-internal.ts +0 -52
  91. package/src/allocate.ts +0 -277
  92. package/src/molecule.ts +0 -138
@@ -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,7 @@
1
1
  import type {
2
2
  AtomFamilyToken,
3
+ AtomIOToken,
3
4
  AtomToken,
4
- MoleculeConstructor,
5
- MoleculeFamily,
6
- MoleculeFamilyToken,
7
- MoleculeToken,
8
5
  MutableAtomFamilyToken,
9
6
  MutableAtomToken,
10
7
  ReadableFamilyToken,
@@ -24,13 +21,12 @@ import type {
24
21
  WritableToken,
25
22
  } from "atom.io"
26
23
  import type { Canonical, Json } from "atom.io/json"
27
- import { stringifyJson } from "atom.io/json"
28
24
 
29
25
  import type {
30
26
  Atom,
31
27
  AtomFamily,
28
+ AtomIOInternalResource,
32
29
  Func,
33
- Molecule,
34
30
  MutableAtom,
35
31
  MutableAtomFamily,
36
32
  ReadableFamily,
@@ -52,28 +48,6 @@ import type { Timeline } from "../timeline"
52
48
  import type { Transaction } from "../transaction"
53
49
  import type { Store } from "./store"
54
50
 
55
- export type Withdrawable =
56
- | Atom<any>
57
- | AtomFamily<any, any>
58
- | Molecule<any>
59
- | MoleculeFamily<any>
60
- | MutableAtom<any, any>
61
- | MutableAtomFamily<any, any, any>
62
- | ReadableFamily<any, any>
63
- | ReadableState<any>
64
- | ReadonlySelector<any>
65
- | ReadonlySelectorFamily<any, any>
66
- | RegularAtom<any>
67
- | RegularAtomFamily<any, any>
68
- | Selector<any>
69
- | SelectorFamily<any, any>
70
- | Timeline<any>
71
- | Transaction<any>
72
- | WritableFamily<any, any>
73
- | WritableSelector<any>
74
- | WritableSelectorFamily<any, any>
75
- | WritableState<any>
76
-
77
51
  export function withdraw<T>(
78
52
  token: RegularAtomToken<T>,
79
53
  store: Store,
@@ -138,15 +112,6 @@ export function withdraw<T, K extends Canonical>(
138
112
  store: Store,
139
113
  ): WritableFamily<T, any>
140
114
 
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
115
  export function withdraw<T extends Func>(
151
116
  token: TransactionToken<T>,
152
117
  store: Store,
@@ -156,26 +121,25 @@ export function withdraw<T>(
156
121
  store: Store,
157
122
  ): Timeline<T extends TimelineManageable ? T : never>
158
123
 
159
- export function withdraw<T, M extends MoleculeConstructor>(
160
- token: MoleculeToken<M> | ReadableToken<T>,
124
+ export function withdraw<T>(
125
+ token: WritableToken<T>,
161
126
  store: Store,
162
- ): Molecule<M> | ReadableState<T>
127
+ ): WritableState<T>
128
+ export function withdraw<T>(
129
+ token: ReadableToken<T>,
130
+ store: Store,
131
+ ): ReadableState<T>
132
+
133
+ export function withdraw(
134
+ token: AtomIOToken,
135
+ store: Store,
136
+ ): AtomIOInternalResource
163
137
 
164
138
  export function withdraw(
165
- token:
166
- | MoleculeFamilyToken<any>
167
- | MoleculeToken<any>
168
- | MutableAtomFamilyToken<any, any, any>
169
- | MutableAtomToken<any, any>
170
- | RegularAtomFamilyToken<any, any>
171
- | RegularAtomToken<any>
172
- | SelectorFamilyToken<any, any>
173
- | SelectorToken<any>
174
- | TimelineToken<any>
175
- | TransactionToken<any>,
176
- store: Store,
177
- ): Withdrawable {
178
- let withdrawn: Withdrawable | undefined
139
+ token: AtomIOToken,
140
+ store: Store,
141
+ ): AtomIOInternalResource {
142
+ let withdrawn: AtomIOInternalResource | undefined
179
143
  let target: Store | null = store
180
144
  while (target !== null) {
181
145
  switch (token.type) {
@@ -201,12 +165,6 @@ export function withdraw(
201
165
  case `transaction`:
202
166
  withdrawn = target.transactions.get(token.key)
203
167
  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
168
  }
211
169
  if (withdrawn) {
212
170
  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`) {