atom.io 0.22.0 → 0.23.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.cjs +17 -1
- package/data/dist/index.js +1 -1
- package/data/src/join.ts +30 -1
- package/dist/chunk-6MLFYN32.js +18 -0
- package/dist/{chunk-JA4V7TJY.js → chunk-7DT3PVS3.js} +18 -2
- package/dist/chunk-OAYGID5B.js +27 -0
- package/dist/index.cjs +2 -11
- package/dist/index.d.ts +51 -23
- package/dist/index.js +2 -11
- package/eslint-plugin/dist/index.cjs +0 -1
- package/eslint-plugin/dist/index.js +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -1
- package/immortal/dist/index.cjs +180 -20
- package/immortal/dist/index.js +134 -19
- package/immortal/src/index.ts +1 -0
- package/immortal/src/make-molecule.ts +222 -0
- package/immortal/src/molecule.ts +49 -16
- package/immortal/src/seek-state.ts +15 -2
- package/internal/dist/index.cjs +1119 -754
- package/internal/dist/index.d.ts +109 -12
- package/internal/dist/index.js +1098 -760
- package/internal/src/atom/create-regular-atom.ts +0 -2
- package/internal/src/atom/create-standalone-atom.ts +6 -2
- package/internal/src/atom/dispose-atom.ts +22 -2
- package/internal/src/families/create-readonly-selector-family.ts +7 -2
- package/internal/src/families/create-regular-atom-family.ts +6 -2
- package/internal/src/families/create-writable-selector-family.ts +7 -2
- package/internal/src/families/dispose-from-store.ts +22 -0
- package/internal/src/families/find-in-store.ts +0 -1
- package/internal/src/families/index.ts +1 -0
- package/internal/src/families/init-family-member.ts +22 -1
- package/internal/src/families/seek-in-store.ts +23 -6
- package/internal/src/ingest-updates/index.ts +1 -0
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +104 -0
- package/internal/src/ingest-updates/ingest-transaction-update.ts +26 -4
- package/internal/src/mutable/create-mutable-atom-family.ts +6 -2
- package/internal/src/mutable/create-mutable-atom.ts +0 -2
- package/internal/src/mutable/get-json-token.ts +0 -1
- package/internal/src/mutable/tracker-family.ts +7 -7
- package/internal/src/not-found-error.ts +5 -0
- package/internal/src/selector/create-readonly-selector.ts +2 -3
- package/internal/src/selector/create-standalone-selector.ts +6 -2
- package/internal/src/selector/create-writable-selector.ts +2 -3
- package/internal/src/selector/dispose-selector.ts +32 -5
- package/internal/src/selector/register-selector.ts +2 -0
- package/internal/src/set-state/stow-update.ts +5 -1
- package/internal/src/store/deposit.ts +41 -7
- package/internal/src/store/store.ts +11 -0
- package/internal/src/store/withdraw.ts +28 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +206 -182
- package/internal/src/timeline/create-timeline.ts +181 -60
- package/internal/src/timeline/time-travel.ts +20 -0
- package/internal/src/transaction/apply-transaction.ts +2 -12
- package/internal/src/transaction/build-transaction.ts +11 -2
- package/introspection/dist/index.cjs +2 -1
- package/introspection/dist/index.js +2 -1
- package/introspection/src/attach-timeline-family.ts +1 -0
- package/json/dist/index.cjs +3 -3
- package/json/dist/index.js +6 -5
- package/json/src/select-json-family.ts +3 -4
- package/package.json +5 -5
- package/react-devtools/dist/index.cjs +58 -47
- package/react-devtools/dist/index.js +60 -48
- package/react-devtools/src/TimelineIndex.tsx +15 -13
- package/react-devtools/src/Updates.tsx +41 -32
- package/realtime-server/dist/index.cjs +21 -10
- package/realtime-server/dist/index.d.ts +1 -1
- package/realtime-server/dist/index.js +21 -11
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +21 -11
- package/realtime-testing/dist/index.cjs +1 -0
- package/realtime-testing/dist/index.js +1 -1
- package/src/atom.ts +9 -3
- package/src/dispose-state.ts +3 -12
- package/src/index.ts +4 -0
- package/src/selector.ts +3 -3
- package/src/subscribe.ts +8 -4
- package/src/timeline.ts +18 -1
- package/src/transaction.ts +56 -4
- package/dist/chunk-BF4MVQF6.js +0 -44
|
@@ -5,6 +5,7 @@ import type { seekState } from "atom.io/immortal"
|
|
|
5
5
|
import { findInStore, seekInStore } from "../families"
|
|
6
6
|
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
7
7
|
import { newest } from "../lineage"
|
|
8
|
+
import { getJsonToken } from "../mutable"
|
|
8
9
|
import { setAtomOrSelector } from "../set-state"
|
|
9
10
|
import type { Store } from "../store"
|
|
10
11
|
import { withdraw } from "../store"
|
|
@@ -47,4 +48,5 @@ export const registerSelector = (
|
|
|
47
48
|
},
|
|
48
49
|
find: ((token, key) => findInStore(token, key, store)) as typeof findState,
|
|
49
50
|
seek: ((token, key) => seekInStore(token, key, store)) as typeof seekState,
|
|
51
|
+
json: (token) => getJsonToken(token, store),
|
|
50
52
|
})
|
|
@@ -38,7 +38,11 @@ export const stowUpdate = <T>(
|
|
|
38
38
|
if (!shouldStow) {
|
|
39
39
|
return
|
|
40
40
|
}
|
|
41
|
-
const atomUpdate: KeyedStateUpdate<T> = {
|
|
41
|
+
const atomUpdate: KeyedStateUpdate<T> = {
|
|
42
|
+
type: `atom_update`,
|
|
43
|
+
key,
|
|
44
|
+
...update,
|
|
45
|
+
}
|
|
42
46
|
if (state.family) {
|
|
43
47
|
atomUpdate.family = state.family
|
|
44
48
|
}
|
|
@@ -10,6 +10,13 @@ import type {
|
|
|
10
10
|
WritableSelectorToken,
|
|
11
11
|
WritableToken,
|
|
12
12
|
} from "atom.io"
|
|
13
|
+
import type {
|
|
14
|
+
Molecule,
|
|
15
|
+
MoleculeFamily,
|
|
16
|
+
MoleculeFamilyToken,
|
|
17
|
+
MoleculeToken,
|
|
18
|
+
} from "atom.io/immortal"
|
|
19
|
+
import type { Json } from "atom.io/json"
|
|
13
20
|
|
|
14
21
|
import type {
|
|
15
22
|
Atom,
|
|
@@ -33,28 +40,55 @@ export function deposit<T>(state: WritableSelector<T>): WritableSelectorToken<T>
|
|
|
33
40
|
export function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>
|
|
34
41
|
export function deposit<T>(state: Selector<T>): SelectorToken<T>
|
|
35
42
|
export function deposit<T>(state: WritableState<T>): WritableToken<T>
|
|
43
|
+
export function deposit<
|
|
44
|
+
K extends Json.Serializable,
|
|
45
|
+
S extends { [key: string]: any },
|
|
46
|
+
P extends any[],
|
|
47
|
+
>(state: Molecule<K>): MoleculeToken<K, S, P>
|
|
48
|
+
export function deposit<
|
|
49
|
+
K extends Json.Serializable,
|
|
50
|
+
S extends { [key: string]: any },
|
|
51
|
+
P extends any[],
|
|
52
|
+
>(state: MoleculeFamily<K, S, P>): MoleculeFamilyToken<K, S, P>
|
|
36
53
|
export function deposit<T extends Func>(
|
|
37
54
|
state: Transaction<T>,
|
|
38
55
|
): TransactionToken<T>
|
|
39
56
|
export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
|
|
40
57
|
export function deposit<T>(
|
|
41
58
|
state:
|
|
59
|
+
| Molecule<any>
|
|
60
|
+
| MoleculeFamily<any, any, any>
|
|
61
|
+
| ReadableState<T>
|
|
42
62
|
| ReadonlySelector<T>
|
|
43
63
|
| RegularAtom<T>
|
|
44
64
|
| Transaction<T extends Func ? T : never>
|
|
45
65
|
| WritableSelector<T>
|
|
46
66
|
| (T extends Transceiver<any> ? MutableAtom<T, any> : never),
|
|
47
67
|
):
|
|
68
|
+
| MoleculeFamilyToken<any, any, any>
|
|
69
|
+
| MoleculeToken<any, any, any>
|
|
48
70
|
| MutableAtomToken<T extends Transceiver<any> ? T : never, any>
|
|
49
71
|
| RegularAtomToken<T>
|
|
50
72
|
| SelectorToken<T>
|
|
51
73
|
| TransactionToken<T extends Func ? T : never> {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
74
|
+
const { type } = state
|
|
75
|
+
switch (type) {
|
|
76
|
+
case `atom`:
|
|
77
|
+
case `molecule_family`:
|
|
78
|
+
case `mutable_atom`:
|
|
79
|
+
case `selector`:
|
|
80
|
+
case `readonly_selector`:
|
|
81
|
+
case `transaction`: {
|
|
82
|
+
const token = {
|
|
83
|
+
key: state.key,
|
|
84
|
+
type: state.type,
|
|
85
|
+
} as any
|
|
86
|
+
if (`family` in state) {
|
|
87
|
+
token.family = state.family
|
|
88
|
+
}
|
|
89
|
+
return token
|
|
90
|
+
}
|
|
91
|
+
case `molecule`:
|
|
92
|
+
return state.token
|
|
58
93
|
}
|
|
59
|
-
return token
|
|
60
94
|
}
|
|
@@ -2,6 +2,8 @@ import type {
|
|
|
2
2
|
AtomToken,
|
|
3
3
|
Func,
|
|
4
4
|
Logger,
|
|
5
|
+
MoleculeCreation,
|
|
6
|
+
MoleculeDisposal,
|
|
5
7
|
MutableAtomFamily,
|
|
6
8
|
ReadonlySelectorFamily,
|
|
7
9
|
ReadonlySelectorToken,
|
|
@@ -13,7 +15,12 @@ import type {
|
|
|
13
15
|
} from "atom.io"
|
|
14
16
|
import { AtomIOLogger } from "atom.io"
|
|
15
17
|
import type { Molecule } from "atom.io/immortal"
|
|
18
|
+
import type { Json } from "atom.io/json"
|
|
16
19
|
|
|
20
|
+
import type {
|
|
21
|
+
MoleculeFamily,
|
|
22
|
+
MoleculeToken,
|
|
23
|
+
} from "~/packages/atom.io/immortal/src/make-molecule"
|
|
17
24
|
import { Junction } from "~/packages/rel8/junction/src"
|
|
18
25
|
|
|
19
26
|
import type {
|
|
@@ -82,6 +89,7 @@ export class Store implements Lineage {
|
|
|
82
89
|
)
|
|
83
90
|
|
|
84
91
|
public molecules = new Map<string, Molecule<any>>()
|
|
92
|
+
public moleculeFamilies = new Map<string, MoleculeFamily<any, any, any>>()
|
|
85
93
|
public miscResources = new Map<string, Disposable>()
|
|
86
94
|
|
|
87
95
|
public on = {
|
|
@@ -99,6 +107,9 @@ export class Store implements Lineage {
|
|
|
99
107
|
null,
|
|
100
108
|
),
|
|
101
109
|
operationClose: new Subject<OperationProgress>(),
|
|
110
|
+
moleculeCreationStart: new Subject<MoleculeToken<any, any, any>>(),
|
|
111
|
+
moleculeCreationDone: new Subject<MoleculeToken<any, any, any>>(),
|
|
112
|
+
moleculeDisposal: new Subject<MoleculeToken<any, any, any>>(),
|
|
102
113
|
}
|
|
103
114
|
public operation: OperationProgress = { open: false }
|
|
104
115
|
public transactionMeta: TransactionEpoch | TransactionProgress<Func> = {
|
|
@@ -24,7 +24,13 @@ import type {
|
|
|
24
24
|
WritableSelectorToken,
|
|
25
25
|
WritableToken,
|
|
26
26
|
} from "atom.io"
|
|
27
|
-
import type {
|
|
27
|
+
import type {
|
|
28
|
+
Molecule,
|
|
29
|
+
MoleculeFamily,
|
|
30
|
+
MoleculeFamilyToken,
|
|
31
|
+
MoleculeToken,
|
|
32
|
+
} from "atom.io/immortal"
|
|
33
|
+
import { type Json, stringifyJson } from "atom.io/json"
|
|
28
34
|
|
|
29
35
|
import type {
|
|
30
36
|
Atom,
|
|
@@ -45,6 +51,8 @@ import type { Store } from "./store"
|
|
|
45
51
|
export type Withdrawable =
|
|
46
52
|
| Atom<any>
|
|
47
53
|
| AtomFamily<any, any>
|
|
54
|
+
| Molecule<any>
|
|
55
|
+
| MoleculeFamily<any, any, any>
|
|
48
56
|
| MutableAtom<any, any>
|
|
49
57
|
| MutableAtomFamily<any, any, any>
|
|
50
58
|
| ReadableState<any>
|
|
@@ -116,6 +124,17 @@ export function withdraw<T, K extends Json.Serializable>(
|
|
|
116
124
|
store: Store,
|
|
117
125
|
): SelectorFamily<T, any>
|
|
118
126
|
|
|
127
|
+
export function withdraw<
|
|
128
|
+
K extends Json.Serializable,
|
|
129
|
+
S extends { [key: string]: any },
|
|
130
|
+
P extends any[],
|
|
131
|
+
>(token: MoleculeToken<K, S, P>, store: Store): Molecule<K> & S
|
|
132
|
+
export function withdraw<
|
|
133
|
+
K extends Json.Serializable,
|
|
134
|
+
S extends { [key: string]: any },
|
|
135
|
+
P extends any[],
|
|
136
|
+
>(token: MoleculeFamilyToken<K, S, P>, store: Store): MoleculeFamily<K, S, P>
|
|
137
|
+
|
|
119
138
|
export function withdraw<T extends Func>(
|
|
120
139
|
token: TransactionToken<T>,
|
|
121
140
|
store: Store,
|
|
@@ -126,6 +145,8 @@ export function withdraw<T>(
|
|
|
126
145
|
): Timeline<T extends TimelineManageable ? T : never>
|
|
127
146
|
export function withdraw<T>(
|
|
128
147
|
token:
|
|
148
|
+
| MoleculeFamilyToken<any, any, any>
|
|
149
|
+
| MoleculeToken<any, any, any>
|
|
129
150
|
| RegularAtomFamilyToken<T, any>
|
|
130
151
|
| RegularAtomToken<T>
|
|
131
152
|
| SelectorFamilyToken<T, any>
|
|
@@ -163,6 +184,12 @@ export function withdraw<T>(
|
|
|
163
184
|
case `transaction`:
|
|
164
185
|
withdrawn = target.transactions.get(token.key)
|
|
165
186
|
break
|
|
187
|
+
case `molecule`:
|
|
188
|
+
withdrawn = target.molecules.get(stringifyJson(token.key))
|
|
189
|
+
break
|
|
190
|
+
case `molecule_family`:
|
|
191
|
+
withdrawn = target.moleculeFamilies.get(token.key)
|
|
192
|
+
break
|
|
166
193
|
}
|
|
167
194
|
if (withdrawn) {
|
|
168
195
|
return withdrawn
|
|
@@ -29,213 +29,237 @@ export const addAtomToTimeline = (
|
|
|
29
29
|
const atom = maybeAtom
|
|
30
30
|
store.timelineAtoms.set({ atomKey: atom.key, timelineKey: tl.key })
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
tl.subscriptions.set(
|
|
33
|
+
atom.key,
|
|
34
|
+
atom.subject.subscribe(`timeline`, (update) => {
|
|
35
|
+
const target = newest(store)
|
|
36
|
+
const currentSelectorKey =
|
|
37
|
+
store.operation.open && store.operation.token.type === `selector`
|
|
38
|
+
? store.operation.token.key
|
|
39
|
+
: null
|
|
40
|
+
const currentSelectorTime =
|
|
41
|
+
store.operation.open && store.operation.token.type === `selector`
|
|
42
|
+
? store.operation.time
|
|
43
|
+
: null
|
|
44
|
+
const { transactionApplying } = target.on
|
|
45
|
+
const currentTransactionKey = transactionApplying.state?.update.key
|
|
46
|
+
const currentTransactionInstanceId = transactionApplying.state?.update.id
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (currentTransactionKey) {
|
|
73
|
-
const txToken: TransactionToken<any> = {
|
|
74
|
-
key: currentTransactionKey,
|
|
75
|
-
type: `transaction`,
|
|
76
|
-
}
|
|
77
|
-
const currentTransaction = withdraw(txToken, store)
|
|
78
|
-
if (tl.transactionKey !== currentTransactionKey) {
|
|
79
|
-
if (tl.transactionKey) {
|
|
80
|
-
store.logger.error(
|
|
81
|
-
`🐞`,
|
|
82
|
-
`timeline`,
|
|
83
|
-
tl.key,
|
|
84
|
-
`unable to resolve transaction "${tl.transactionKey}. This is probably a bug in AtomIO.`,
|
|
48
|
+
store.logger.info(
|
|
49
|
+
`⏳`,
|
|
50
|
+
`timeline`,
|
|
51
|
+
tl.key,
|
|
52
|
+
`atom`,
|
|
53
|
+
atomToken.key,
|
|
54
|
+
`went`,
|
|
55
|
+
update.oldValue,
|
|
56
|
+
`->`,
|
|
57
|
+
update.newValue,
|
|
58
|
+
currentTransactionKey
|
|
59
|
+
? `in transaction "${currentTransactionKey}"`
|
|
60
|
+
: currentSelectorKey
|
|
61
|
+
? `in selector "${currentSelectorKey}"`
|
|
62
|
+
: ``,
|
|
63
|
+
)
|
|
64
|
+
if (tl.timeTraveling === null) {
|
|
65
|
+
if (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {
|
|
66
|
+
const mostRecentUpdate: TimelineUpdate<any> | undefined =
|
|
67
|
+
tl.history.at(-1)
|
|
68
|
+
if (mostRecentUpdate === undefined) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Timeline "${tl.key}" has a selectorTime, but no history. This is most likely a bug in AtomIO.`,
|
|
85
71
|
)
|
|
86
72
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
}
|
|
74
|
+
if (currentTransactionKey) {
|
|
75
|
+
const txToken: TransactionToken<any> = {
|
|
76
|
+
key: currentTransactionKey,
|
|
77
|
+
type: `transaction`,
|
|
78
|
+
}
|
|
79
|
+
const currentTransaction = withdraw(txToken, store)
|
|
80
|
+
if (tl.transactionKey !== currentTransactionKey) {
|
|
81
|
+
if (tl.transactionKey) {
|
|
82
|
+
store.logger.error(
|
|
83
|
+
`🐞`,
|
|
84
|
+
`timeline`,
|
|
85
|
+
tl.key,
|
|
86
|
+
`unable to resolve transaction "${tl.transactionKey}. This is probably a bug in AtomIO.`,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
tl.transactionKey = currentTransactionKey
|
|
90
|
+
const unsubscribe = currentTransaction.subject.subscribe(
|
|
91
|
+
`timeline:${tl.key}`,
|
|
92
|
+
(transactionUpdate) => {
|
|
93
|
+
unsubscribe()
|
|
94
|
+
if (tl.timeTraveling === null && currentTransactionInstanceId) {
|
|
95
|
+
if (tl.at !== tl.history.length) {
|
|
96
|
+
tl.history.splice(tl.at)
|
|
97
|
+
}
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
const filterUpdates = (
|
|
100
|
+
updates: TransactionUpdate<Func>[`updates`],
|
|
101
|
+
) =>
|
|
102
|
+
updates
|
|
103
|
+
.filter((updateFromTx) => {
|
|
104
|
+
const newestStore = newest(store)
|
|
105
|
+
if (`updates` in updateFromTx) {
|
|
106
|
+
return true
|
|
107
|
+
}
|
|
108
|
+
const atomOrFamilyKeys =
|
|
109
|
+
newestStore.timelineAtoms.getRelatedKeys(tl.key)
|
|
108
110
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
if (!atomOrFamilyKeys) {
|
|
112
|
+
return false
|
|
113
|
+
}
|
|
114
|
+
let key: string | undefined
|
|
115
|
+
let familyKey: string | undefined
|
|
116
|
+
switch (updateFromTx.type) {
|
|
117
|
+
case `state_creation`:
|
|
118
|
+
case `state_disposal`:
|
|
119
|
+
key = updateFromTx.token.key
|
|
120
|
+
familyKey = updateFromTx.token.family?.key
|
|
121
|
+
break
|
|
122
|
+
case `molecule_creation`:
|
|
123
|
+
case `molecule_disposal`:
|
|
124
|
+
break
|
|
125
|
+
default:
|
|
126
|
+
key = updateFromTx.key
|
|
127
|
+
familyKey = updateFromTx.family?.key
|
|
128
|
+
break
|
|
129
|
+
}
|
|
130
|
+
if (key === undefined) {
|
|
131
|
+
return false
|
|
132
|
+
}
|
|
133
|
+
if (atomOrFamilyKeys.has(key)) {
|
|
134
|
+
return true
|
|
135
|
+
}
|
|
136
|
+
if (familyKey !== undefined) {
|
|
137
|
+
return atomOrFamilyKeys.has(familyKey)
|
|
138
|
+
}
|
|
139
|
+
return false
|
|
140
|
+
})
|
|
141
|
+
.map((updateFromTx) => {
|
|
142
|
+
if (`updates` in updateFromTx) {
|
|
143
|
+
return {
|
|
144
|
+
...updateFromTx,
|
|
145
|
+
updates: filterUpdates(updateFromTx.updates),
|
|
146
|
+
}
|
|
122
147
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
})
|
|
148
|
+
return updateFromTx
|
|
149
|
+
})
|
|
126
150
|
|
|
127
|
-
|
|
151
|
+
const updates = filterUpdates(transactionUpdate.updates)
|
|
128
152
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
153
|
+
const timelineTransactionUpdate: TimelineTransactionUpdate = {
|
|
154
|
+
timestamp: Date.now(),
|
|
155
|
+
...transactionUpdate,
|
|
156
|
+
updates,
|
|
157
|
+
}
|
|
158
|
+
const willCapture =
|
|
159
|
+
tl.shouldCapture?.(timelineTransactionUpdate, tl) ?? true
|
|
160
|
+
if (willCapture) {
|
|
161
|
+
tl.history.push(timelineTransactionUpdate)
|
|
162
|
+
tl.at = tl.history.length
|
|
163
|
+
tl.subject.next(timelineTransactionUpdate)
|
|
164
|
+
}
|
|
134
165
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
tl.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
166
|
+
tl.transactionKey = null
|
|
167
|
+
store.logger.info(
|
|
168
|
+
`⌛`,
|
|
169
|
+
`timeline`,
|
|
170
|
+
tl.key,
|
|
171
|
+
`got a transaction_update "${transactionUpdate.key}"`,
|
|
172
|
+
)
|
|
173
|
+
},
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
} else if (currentSelectorKey && currentSelectorTime) {
|
|
177
|
+
let latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)
|
|
178
|
+
|
|
179
|
+
if (currentSelectorTime !== tl.selectorTime) {
|
|
180
|
+
latestUpdate = {
|
|
181
|
+
type: `selector_update`,
|
|
182
|
+
timestamp: currentSelectorTime,
|
|
183
|
+
key: currentSelectorKey,
|
|
184
|
+
atomUpdates: [],
|
|
185
|
+
}
|
|
186
|
+
latestUpdate.atomUpdates.push({
|
|
187
|
+
key: atom.key,
|
|
188
|
+
type: `atom_update`,
|
|
189
|
+
...update,
|
|
190
|
+
})
|
|
191
|
+
if (tl.at !== tl.history.length) {
|
|
192
|
+
tl.history.splice(tl.at)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
tl.history.push(latestUpdate)
|
|
196
|
+
|
|
197
|
+
store.logger.info(
|
|
198
|
+
`⌛`,
|
|
199
|
+
`timeline`,
|
|
200
|
+
tl.key,
|
|
201
|
+
`got a selector_update "${currentSelectorKey}" with`,
|
|
202
|
+
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
tl.at = tl.history.length
|
|
206
|
+
tl.selectorTime = currentSelectorTime
|
|
207
|
+
} else {
|
|
208
|
+
if (latestUpdate?.type === `selector_update`) {
|
|
209
|
+
latestUpdate.atomUpdates.push({
|
|
210
|
+
key: atom.key,
|
|
211
|
+
type: `atom_update`,
|
|
212
|
+
...update,
|
|
213
|
+
})
|
|
144
214
|
store.logger.info(
|
|
145
215
|
`⌛`,
|
|
146
216
|
`timeline`,
|
|
147
217
|
tl.key,
|
|
148
|
-
`
|
|
218
|
+
`set selector_update "${currentSelectorKey}" to`,
|
|
219
|
+
latestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),
|
|
149
220
|
)
|
|
150
|
-
}
|
|
151
|
-
)
|
|
152
|
-
}
|
|
153
|
-
} else if (currentSelectorKey && currentSelectorTime) {
|
|
154
|
-
let latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)
|
|
155
|
-
|
|
156
|
-
if (currentSelectorTime !== tl.selectorTime) {
|
|
157
|
-
latestUpdate = {
|
|
158
|
-
type: `selector_update`,
|
|
159
|
-
timestamp: currentSelectorTime,
|
|
160
|
-
key: currentSelectorKey,
|
|
161
|
-
atomUpdates: [],
|
|
221
|
+
}
|
|
162
222
|
}
|
|
163
|
-
latestUpdate
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
223
|
+
if (latestUpdate) {
|
|
224
|
+
const willCaptureSelectorUpdate =
|
|
225
|
+
tl.shouldCapture?.(latestUpdate, tl) ?? true
|
|
226
|
+
if (willCaptureSelectorUpdate) {
|
|
227
|
+
tl.subject.next(latestUpdate)
|
|
228
|
+
} else {
|
|
229
|
+
tl.history.pop()
|
|
230
|
+
tl.at = tl.history.length
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
const timestamp = Date.now()
|
|
235
|
+
tl.selectorTime = null
|
|
168
236
|
if (tl.at !== tl.history.length) {
|
|
169
237
|
tl.history.splice(tl.at)
|
|
170
238
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
239
|
+
const atomUpdate: TimelineAtomUpdate<any> = {
|
|
240
|
+
type: `atom_update`,
|
|
241
|
+
timestamp,
|
|
242
|
+
key: atom.key,
|
|
243
|
+
oldValue: update.oldValue,
|
|
244
|
+
newValue: update.newValue,
|
|
245
|
+
}
|
|
246
|
+
if (atom.family) {
|
|
247
|
+
atomUpdate.family = atom.family
|
|
248
|
+
}
|
|
249
|
+
const willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true
|
|
174
250
|
store.logger.info(
|
|
175
251
|
`⌛`,
|
|
176
252
|
`timeline`,
|
|
177
253
|
tl.key,
|
|
178
|
-
`got
|
|
179
|
-
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),
|
|
254
|
+
`got an atom_update to "${atom.key}"`,
|
|
180
255
|
)
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
tl.selectorTime = currentSelectorTime
|
|
184
|
-
} else {
|
|
185
|
-
if (latestUpdate?.type === `selector_update`) {
|
|
186
|
-
latestUpdate.atomUpdates.push({
|
|
187
|
-
key: atom.key,
|
|
188
|
-
type: `atom_update`,
|
|
189
|
-
...update,
|
|
190
|
-
})
|
|
191
|
-
store.logger.info(
|
|
192
|
-
`⌛`,
|
|
193
|
-
`timeline`,
|
|
194
|
-
tl.key,
|
|
195
|
-
`set selector_update "${currentSelectorKey}" to`,
|
|
196
|
-
latestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),
|
|
197
|
-
)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (latestUpdate) {
|
|
201
|
-
const willCaptureSelectorUpdate =
|
|
202
|
-
tl.shouldCapture?.(latestUpdate, tl) ?? true
|
|
203
|
-
if (willCaptureSelectorUpdate) {
|
|
204
|
-
tl.subject.next(latestUpdate)
|
|
205
|
-
} else {
|
|
206
|
-
tl.history.pop()
|
|
256
|
+
if (willCapture) {
|
|
257
|
+
tl.history.push(atomUpdate)
|
|
207
258
|
tl.at = tl.history.length
|
|
259
|
+
tl.subject.next(atomUpdate)
|
|
208
260
|
}
|
|
209
261
|
}
|
|
210
|
-
} else {
|
|
211
|
-
const timestamp = Date.now()
|
|
212
|
-
tl.selectorTime = null
|
|
213
|
-
if (tl.at !== tl.history.length) {
|
|
214
|
-
tl.history.splice(tl.at)
|
|
215
|
-
}
|
|
216
|
-
const atomUpdate: TimelineAtomUpdate<any> = {
|
|
217
|
-
type: `atom_update`,
|
|
218
|
-
timestamp,
|
|
219
|
-
key: atom.key,
|
|
220
|
-
oldValue: update.oldValue,
|
|
221
|
-
newValue: update.newValue,
|
|
222
|
-
}
|
|
223
|
-
if (atom.family) {
|
|
224
|
-
atomUpdate.family = atom.family
|
|
225
|
-
}
|
|
226
|
-
const willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true
|
|
227
|
-
store.logger.info(
|
|
228
|
-
`⌛`,
|
|
229
|
-
`timeline`,
|
|
230
|
-
tl.key,
|
|
231
|
-
`got an atom_update to "${atom.key}"`,
|
|
232
|
-
)
|
|
233
|
-
if (willCapture) {
|
|
234
|
-
tl.history.push(atomUpdate)
|
|
235
|
-
tl.at = tl.history.length
|
|
236
|
-
tl.subject.next(atomUpdate)
|
|
237
|
-
}
|
|
238
262
|
}
|
|
239
|
-
}
|
|
240
|
-
|
|
263
|
+
}),
|
|
264
|
+
)
|
|
241
265
|
}
|