atom.io 0.34.0 → 0.34.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint-plugin/index.js +1 -2
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +26 -22
- package/dist/internal/index.js.map +1 -1
- package/dist/json/index.d.ts +19 -4
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +4 -0
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +431 -26
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +109 -17
- package/dist/main/index.js.map +1 -1
- package/dist/realtime-client/index.js +4 -8
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.js +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +10 -10
- package/src/internal/join/create-join.ts +27 -0
- package/src/internal/join/index.ts +1 -0
- package/src/internal/junction.ts +2 -0
- package/src/json/entries.ts +10 -3
- package/src/json/index.ts +40 -14
- package/src/main/atom.ts +53 -12
- package/src/main/dispose-state.ts +8 -2
- package/src/main/find-state.ts +44 -14
- package/src/main/get-state.ts +2 -2
- package/src/main/index.ts +8 -0
- package/src/main/join.ts +78 -22
- package/src/main/realm.ts +50 -4
- package/src/main/selector.ts +116 -6
- package/src/main/subscribe.ts +31 -1
- package/src/main/timeline.ts +41 -15
- package/src/main/transaction.ts +39 -3
package/src/main/selector.ts
CHANGED
|
@@ -14,23 +14,35 @@ import type {
|
|
|
14
14
|
import type { Read, Write } from "./transaction"
|
|
15
15
|
|
|
16
16
|
export type WritablePureSelectorOptions<T> = {
|
|
17
|
+
/** The unique identifier of the selector */
|
|
17
18
|
key: string
|
|
19
|
+
/** For each instantiated selector, a function that computes its value */
|
|
18
20
|
get: Read<() => T>
|
|
21
|
+
/** For each instantiated selector, a function that sets its value */
|
|
19
22
|
set: Write<(newValue: T) => void>
|
|
20
23
|
}
|
|
21
24
|
export type ReadonlyPureSelectorOptions<T> = {
|
|
25
|
+
/** The unique identifier of the selector */
|
|
22
26
|
key: string
|
|
27
|
+
/** For each instantiated selector, a function that computes its value */
|
|
23
28
|
get: Read<() => T>
|
|
24
29
|
}
|
|
25
30
|
export type ReadonlyHeldSelectorOptions<T extends object> = {
|
|
31
|
+
/** The unique identifier of the selector */
|
|
26
32
|
key: string
|
|
33
|
+
/** For each instantiated selector, a constant reference to a value that will not be replaced */
|
|
27
34
|
const: T
|
|
35
|
+
/** For each instantiated selector, a function that computes its value */
|
|
28
36
|
get: Read<(permanent: T) => void>
|
|
29
37
|
}
|
|
30
38
|
export type WritableHeldSelectorOptions<T extends object> = {
|
|
39
|
+
/** The unique identifier of the selector */
|
|
31
40
|
key: string
|
|
41
|
+
/** For each instantiated selector, a constant reference to a value that will not be replaced */
|
|
32
42
|
const: T
|
|
43
|
+
/** For each instantiated selector, a function that computes its value */
|
|
33
44
|
get: Read<(permanent: T) => void>
|
|
45
|
+
/** For each instantiated selector, a function that sets its value */
|
|
34
46
|
set: Write<(newValue: T) => void>
|
|
35
47
|
}
|
|
36
48
|
|
|
@@ -44,7 +56,7 @@ export type WritableHeldSelectorOptions<T extends object> = {
|
|
|
44
56
|
* The reference to that object is permanent and will not be replaced.
|
|
45
57
|
*
|
|
46
58
|
* A writable selector can be "set" to a new value.
|
|
47
|
-
* It is advised to set its dependencies to values
|
|
59
|
+
* It is strongly advised to set its dependencies to values
|
|
48
60
|
* that would produce the new value of the selector.
|
|
49
61
|
*
|
|
50
62
|
* @param options - {@link WritableHeldSelectorOptions}.
|
|
@@ -55,7 +67,6 @@ export type WritableHeldSelectorOptions<T extends object> = {
|
|
|
55
67
|
export function selector<T extends object>(
|
|
56
68
|
options: WritableHeldSelectorOptions<T>,
|
|
57
69
|
): WritableHeldSelectorToken<T>
|
|
58
|
-
|
|
59
70
|
/**
|
|
60
71
|
* @public
|
|
61
72
|
* Declare a selector. The value of a selector should depend
|
|
@@ -75,7 +86,6 @@ export function selector<T extends object>(
|
|
|
75
86
|
export function selector<T extends object>(
|
|
76
87
|
options: ReadonlyHeldSelectorOptions<T>,
|
|
77
88
|
): ReadonlyHeldSelectorToken<T>
|
|
78
|
-
|
|
79
89
|
/**
|
|
80
90
|
* @public
|
|
81
91
|
* Declare a selector. The value of a selector should depend
|
|
@@ -85,7 +95,7 @@ export function selector<T extends object>(
|
|
|
85
95
|
* in order to be garbage collected when a root atom of the selector is set.
|
|
86
96
|
*
|
|
87
97
|
* A writable selector can be "set" to a new value.
|
|
88
|
-
* It is advised to set its dependencies to values
|
|
98
|
+
* It is strongly advised to set its dependencies to values
|
|
89
99
|
* that would produce the new value of the selector.
|
|
90
100
|
*
|
|
91
101
|
* @param options - {@link TransientWritableSelectorOptions}.
|
|
@@ -96,7 +106,6 @@ export function selector<T extends object>(
|
|
|
96
106
|
export function selector<T>(
|
|
97
107
|
options: WritablePureSelectorOptions<T>,
|
|
98
108
|
): WritablePureSelectorToken<T>
|
|
99
|
-
|
|
100
109
|
/**
|
|
101
110
|
* @public
|
|
102
111
|
* Declare a selector. The value of a selector should depend
|
|
@@ -115,7 +124,6 @@ export function selector<T>(
|
|
|
115
124
|
export function selector<T>(
|
|
116
125
|
options: ReadonlyPureSelectorOptions<T>,
|
|
117
126
|
): ReadonlyPureSelectorToken<T>
|
|
118
|
-
|
|
119
127
|
export function selector(
|
|
120
128
|
options:
|
|
121
129
|
| ReadonlyHeldSelectorOptions<any>
|
|
@@ -130,55 +138,87 @@ export function selector(
|
|
|
130
138
|
return createStandaloneSelector(IMPLICIT.STORE, options)
|
|
131
139
|
}
|
|
132
140
|
|
|
141
|
+
/** @public */
|
|
133
142
|
export type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
143
|
+
/** The unique identifier of the family */
|
|
134
144
|
key: string
|
|
145
|
+
/** For each instantiated family member, a function that computes its value */
|
|
135
146
|
get: (key: K) => Read<() => T>
|
|
147
|
+
/** For each instantiated family member, a function that sets its value */
|
|
136
148
|
set: (key: K) => Write<(newValue: T) => void>
|
|
137
149
|
}
|
|
150
|
+
/** @public */
|
|
138
151
|
export type ReadonlyPureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
152
|
+
/** The unique identifier of the family */
|
|
139
153
|
key: string
|
|
154
|
+
/** For each instantiated family member, a function that computes its value */
|
|
140
155
|
get: (key: K) => Read<() => T>
|
|
141
156
|
}
|
|
157
|
+
/** @public */
|
|
142
158
|
export type WritableHeldSelectorFamilyOptions<
|
|
143
159
|
T extends object,
|
|
144
160
|
K extends Canonical,
|
|
145
161
|
> = {
|
|
162
|
+
/** The unique identifier of the family */
|
|
146
163
|
key: string
|
|
164
|
+
/** For each instantiated family member, a constant reference to a value that will not be replaced */
|
|
147
165
|
const: (key: K) => T
|
|
166
|
+
/** For each instantiated family member, a function that computes its value */
|
|
148
167
|
get: (key: K) => Read<(permanent: T) => void>
|
|
168
|
+
/** For each instantiated family member, a function that sets its value */
|
|
149
169
|
set: (key: K) => Write<(newValue: T) => void>
|
|
150
170
|
}
|
|
171
|
+
/** @public */
|
|
151
172
|
export type ReadonlyHeldSelectorFamilyOptions<
|
|
152
173
|
T extends object,
|
|
153
174
|
K extends Canonical,
|
|
154
175
|
> = {
|
|
176
|
+
/** The unique identifier of the family */
|
|
155
177
|
key: string
|
|
178
|
+
/** For each instantiated family member, a constant reference to a value that will not be replaced */
|
|
156
179
|
const: (key: K) => T
|
|
180
|
+
/** For each instantiated family member, a function that computes its value */
|
|
157
181
|
get: (key: K) => Read<(permanent: T) => void>
|
|
158
182
|
}
|
|
159
183
|
|
|
160
184
|
export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
|
|
185
|
+
/** The unique identifier of the family */
|
|
161
186
|
key: string
|
|
187
|
+
/** Discriminator */
|
|
162
188
|
type: `writable_pure_selector_family`
|
|
189
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
163
190
|
__T?: T
|
|
191
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
164
192
|
__K?: K
|
|
165
193
|
}
|
|
166
194
|
export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
|
|
195
|
+
/** The unique identifier of the family */
|
|
167
196
|
key: string
|
|
197
|
+
/** Discriminator */
|
|
168
198
|
type: `readonly_pure_selector_family`
|
|
199
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
169
200
|
__T?: T
|
|
201
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
170
202
|
__K?: K
|
|
171
203
|
}
|
|
172
204
|
export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
205
|
+
/** The unique identifier of the family */
|
|
173
206
|
key: string
|
|
207
|
+
/** Discriminator */
|
|
174
208
|
type: `writable_held_selector_family`
|
|
209
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
175
210
|
__T?: T
|
|
211
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
176
212
|
__K?: K
|
|
177
213
|
}
|
|
178
214
|
export type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
215
|
+
/** The unique identifier of the family */
|
|
179
216
|
key: string
|
|
217
|
+
/** Discriminator */
|
|
180
218
|
type: `readonly_held_selector_family`
|
|
219
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
181
220
|
__T?: T
|
|
221
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
182
222
|
__K?: K
|
|
183
223
|
}
|
|
184
224
|
|
|
@@ -200,15 +240,85 @@ export type SelectorFamilyToken<T, K extends Canonical> =
|
|
|
200
240
|
| HeldSelectorFamilyToken<T, K>
|
|
201
241
|
| PureSelectorFamilyToken<T, K>
|
|
202
242
|
|
|
243
|
+
/**
|
|
244
|
+
* @public
|
|
245
|
+
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
246
|
+
*
|
|
247
|
+
* The value of a held selector should depend on the value of atoms or other selectors in the store,
|
|
248
|
+
* and should be recycled when a root atom of the selector is set.
|
|
249
|
+
*
|
|
250
|
+
* A held selector's value must be some object.
|
|
251
|
+
* The reference to that object is permanent and will not be replaced.
|
|
252
|
+
*
|
|
253
|
+
* A writable selector can be "set" to a new value.
|
|
254
|
+
* It is advised to set its dependencies to values
|
|
255
|
+
* that would produce the new value of the selector.
|
|
256
|
+
*
|
|
257
|
+
* @param options - {@link WritableHeldSelectorFamilyOptions}.
|
|
258
|
+
* @returns
|
|
259
|
+
* A reference to the selector family created: a {@link WritableHeldSelectorFamilyToken}
|
|
260
|
+
* @overload WritableHeld
|
|
261
|
+
*/
|
|
203
262
|
export function selectorFamily<T extends object, K extends Canonical>(
|
|
204
263
|
options: WritableHeldSelectorFamilyOptions<T, K>,
|
|
205
264
|
): WritableHeldSelectorFamilyToken<T, K>
|
|
265
|
+
/**
|
|
266
|
+
* @public
|
|
267
|
+
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
268
|
+
*
|
|
269
|
+
* The value of a held selector should depend on the value of atoms or other selectors in the store,
|
|
270
|
+
* and should be recycled when a root atom of the selector is set.
|
|
271
|
+
*
|
|
272
|
+
* A held selector's value must be some object.
|
|
273
|
+
* The reference to that object is permanent and will not be replaced.
|
|
274
|
+
*
|
|
275
|
+
* A readonly selector can be "gotten" but not "set".
|
|
276
|
+
*
|
|
277
|
+
* @param options - {@link ReadonlyHeldSelectorFamilyOptions}.
|
|
278
|
+
* @returns
|
|
279
|
+
* A reference to the selector family created: a {@link ReadonlyHeldSelectorFamilyToken}
|
|
280
|
+
* @overload ReadonlyHeld
|
|
281
|
+
*/
|
|
206
282
|
export function selectorFamily<T extends object, K extends Canonical>(
|
|
207
283
|
options: ReadonlyHeldSelectorFamilyOptions<T, K>,
|
|
208
284
|
): ReadonlyHeldSelectorFamilyToken<T, K>
|
|
285
|
+
/**
|
|
286
|
+
* @public
|
|
287
|
+
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
288
|
+
*
|
|
289
|
+
* The value of a selector should depend on the value of atoms or other selectors in the store.
|
|
290
|
+
*
|
|
291
|
+
* A pure selector's current value is evicted from the store
|
|
292
|
+
* in order to be garbage collected when a root atom of the selector is set.
|
|
293
|
+
*
|
|
294
|
+
* A writable selector can be "set" to a new value.
|
|
295
|
+
* It is advised to set its dependencies to values
|
|
296
|
+
* that would produce the new value of the selector.
|
|
297
|
+
*
|
|
298
|
+
* @param options - {@link TransientWritableSelectorFamilyOptions}.
|
|
299
|
+
* @returns
|
|
300
|
+
* A reference to the selector family created: a {@link TransientWritableSelectorFamilyToken}
|
|
301
|
+
* @overload WritablePure
|
|
302
|
+
*/
|
|
209
303
|
export function selectorFamily<T, K extends Canonical>(
|
|
210
304
|
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
211
305
|
): WritablePureSelectorFamilyToken<T, K>
|
|
306
|
+
/**
|
|
307
|
+
* @public
|
|
308
|
+
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
309
|
+
*
|
|
310
|
+
* The value of a selector should depend on the value of atoms or other selectors in the store.
|
|
311
|
+
*
|
|
312
|
+
* A pure selector's current value is evicted from the store
|
|
313
|
+
* in order to be garbage collected when a root atom of the selector is set.
|
|
314
|
+
*
|
|
315
|
+
* A readonly selector can be "gotten" but not "set".
|
|
316
|
+
*
|
|
317
|
+
* @param options - {@link ReadonlyPureSelectorFamilyOptions}.
|
|
318
|
+
* @returns
|
|
319
|
+
* A reference to the selector family created: a {@link ReadonlyPureSelectorFamilyToken}
|
|
320
|
+
* @overload ReadonlyPure
|
|
321
|
+
*/
|
|
212
322
|
export function selectorFamily<T, K extends Canonical>(
|
|
213
323
|
options: ReadonlyPureSelectorFamilyOptions<T, K>,
|
|
214
324
|
): ReadonlyPureSelectorFamilyToken<T, K>
|
package/src/main/subscribe.ts
CHANGED
|
@@ -11,7 +11,9 @@ import type {
|
|
|
11
11
|
TransactionUpdate,
|
|
12
12
|
} from "."
|
|
13
13
|
|
|
14
|
+
/** @public */
|
|
14
15
|
export type StateUpdate<T> = { newValue: T; oldValue: T }
|
|
16
|
+
/** @public */
|
|
15
17
|
export type KeyedStateUpdate<T> = Flat<
|
|
16
18
|
StateUpdate<T> & {
|
|
17
19
|
key: string
|
|
@@ -19,22 +21,50 @@ export type KeyedStateUpdate<T> = Flat<
|
|
|
19
21
|
family?: FamilyMetadata
|
|
20
22
|
}
|
|
21
23
|
>
|
|
24
|
+
/** @public */
|
|
22
25
|
export type UpdateHandler<T> = (update: StateUpdate<T>) => void
|
|
23
|
-
|
|
26
|
+
/** @public */
|
|
24
27
|
export type TransactionUpdateHandler<F extends Func> = (
|
|
25
28
|
data: TransactionUpdate<F>,
|
|
26
29
|
) => void
|
|
27
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
* Subscribe to a state in the implicit store
|
|
34
|
+
* @param token - The token of the state to subscribe to
|
|
35
|
+
* @param handleUpdate - A function that will be called when the state is updated
|
|
36
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
37
|
+
* @returns A function that can be called to unsubscribe from the state
|
|
38
|
+
* @overload State
|
|
39
|
+
*/
|
|
28
40
|
export function subscribe<T>(
|
|
29
41
|
token: ReadableToken<T>,
|
|
30
42
|
handleUpdate: UpdateHandler<T>,
|
|
31
43
|
key?: string,
|
|
32
44
|
): () => void
|
|
45
|
+
/**
|
|
46
|
+
* @public
|
|
47
|
+
* Subscribe to a transaction in the implicit store
|
|
48
|
+
* @param token - The token of the transaction to subscribe to
|
|
49
|
+
* @param handleUpdate - A function that will be called when the transaction succeeds
|
|
50
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
51
|
+
* @returns A function that can be called to unsubscribe from the transaction
|
|
52
|
+
* @overload Transaction
|
|
53
|
+
*/
|
|
33
54
|
export function subscribe<F extends Func>(
|
|
34
55
|
token: TransactionToken<F>,
|
|
35
56
|
handleUpdate: TransactionUpdateHandler<F>,
|
|
36
57
|
key?: string,
|
|
37
58
|
): () => void
|
|
59
|
+
/**
|
|
60
|
+
* @public
|
|
61
|
+
* Subscribe to a timeline in the implicit store
|
|
62
|
+
* @param token - The token of the timeline to subscribe to
|
|
63
|
+
* @param handleUpdate - A function that will be called when a new update is available
|
|
64
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
65
|
+
* @returns A function that can be called to unsubscribe from the timeline
|
|
66
|
+
* @overload Timeline
|
|
67
|
+
*/
|
|
38
68
|
export function subscribe<M extends TimelineManageable>(
|
|
39
69
|
token: TimelineToken<M>,
|
|
40
70
|
handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,
|
package/src/main/timeline.ts
CHANGED
|
@@ -12,7 +12,9 @@ import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
|
|
|
12
12
|
|
|
13
13
|
import type { AtomFamilyToken, AtomToken } from "."
|
|
14
14
|
|
|
15
|
+
/** @public */
|
|
15
16
|
export type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>
|
|
17
|
+
/** @public */
|
|
16
18
|
export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
|
|
17
19
|
any,
|
|
18
20
|
any
|
|
@@ -22,21 +24,34 @@ export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
|
|
|
22
24
|
? M
|
|
23
25
|
: never
|
|
24
26
|
|
|
27
|
+
/** @public */
|
|
25
28
|
export type TimelineToken<M> = {
|
|
29
|
+
/** The unique identifier of the timeline */
|
|
26
30
|
key: string
|
|
31
|
+
/** Discriminator */
|
|
27
32
|
type: `timeline`
|
|
33
|
+
/** Never present. This is a marker that preserves the type of the managed atoms */
|
|
28
34
|
__M?: M
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @public
|
|
39
|
+
* If there is an update ahead of the cursor (in the future of this {@link timeline}), apply it and move the cursor to the next update
|
|
40
|
+
* @param timeline - A {@link TimelineToken}
|
|
41
|
+
*/
|
|
42
|
+
export const redo = (timeline: TimelineToken<any>): void => {
|
|
43
|
+
timeTravel(IMPLICIT.STORE, `redo`, timeline)
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @public
|
|
47
|
+
* Reverse the last update on the {@link timeline} and move the cursor to the previous update
|
|
48
|
+
* @param timeline - A {@link TimelineToken}
|
|
49
|
+
*/
|
|
50
|
+
export const undo = (timeline: TimelineToken<any>): void => {
|
|
51
|
+
timeTravel(IMPLICIT.STORE, `undo`, timeline)
|
|
38
52
|
}
|
|
39
53
|
|
|
54
|
+
/** @public */
|
|
40
55
|
export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
41
56
|
| TimelineAtomUpdate<ManagedAtom>
|
|
42
57
|
| TimelineMoleculeCreation
|
|
@@ -46,16 +61,27 @@ export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
|
46
61
|
| TimelineStateDisposal<AtomOnly<ManagedAtom>>
|
|
47
62
|
| TimelineTransactionUpdate
|
|
48
63
|
|
|
64
|
+
/** @public */
|
|
65
|
+
export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
66
|
+
/** The unique identifier of the timeline */
|
|
67
|
+
key: string
|
|
68
|
+
/** The managed atoms (and families of atoms) to record */
|
|
69
|
+
scope: ManagedAtom[]
|
|
70
|
+
/** A function that determines whether a given update should be recorded */
|
|
71
|
+
shouldCapture?: (
|
|
72
|
+
update: TimelineUpdate<ManagedAtom>,
|
|
73
|
+
timeline: Timeline<TimelineManageable>,
|
|
74
|
+
) => boolean
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @public
|
|
79
|
+
* Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms
|
|
80
|
+
* @param options - {@link TimelineOptions}
|
|
81
|
+
* @returns A reference to the timeline created: a {@link TimelineToken}
|
|
82
|
+
*/
|
|
49
83
|
export const timeline = <ManagedAtom extends TimelineManageable>(
|
|
50
84
|
options: TimelineOptions<ManagedAtom>,
|
|
51
85
|
): TimelineToken<ManagedAtom> => {
|
|
52
86
|
return createTimeline(IMPLICIT.STORE, options)
|
|
53
87
|
}
|
|
54
|
-
|
|
55
|
-
export const redo = (tl: TimelineToken<any>): void => {
|
|
56
|
-
timeTravel(IMPLICIT.STORE, `redo`, tl)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const undo = (tl: TimelineToken<any>): void => {
|
|
60
|
-
timeTravel(IMPLICIT.STORE, `undo`, tl)
|
|
61
|
-
}
|
package/src/main/transaction.ts
CHANGED
|
@@ -18,37 +18,47 @@ import type {
|
|
|
18
18
|
} from "."
|
|
19
19
|
import type { resetState } from "./reset-state"
|
|
20
20
|
|
|
21
|
+
/** @public */
|
|
21
22
|
export type TransactionToken<F extends Func> = {
|
|
23
|
+
/** The unique identifier of the transaction */
|
|
22
24
|
key: string
|
|
25
|
+
/** Discriminator */
|
|
23
26
|
type: `transaction`
|
|
27
|
+
/** Never present. This is a marker that preserves the type of the transaction function */
|
|
24
28
|
__F?: F
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
/** @public */
|
|
27
32
|
export type StateCreation<Token extends ReadableToken<any>> = {
|
|
28
33
|
type: `state_creation`
|
|
29
34
|
token: Token
|
|
30
35
|
}
|
|
36
|
+
/** @public */
|
|
31
37
|
export type AtomDisposal<Token extends ReadableToken<any>> = {
|
|
32
38
|
type: `state_disposal`
|
|
33
39
|
subType: `atom`
|
|
34
40
|
token: Token
|
|
35
41
|
value: TokenType<Token>
|
|
36
42
|
}
|
|
43
|
+
/** @public */
|
|
37
44
|
export type SelectorDisposal<Token extends ReadableToken<any>> = {
|
|
38
45
|
type: `state_disposal`
|
|
39
46
|
subType: `selector`
|
|
40
47
|
token: Token
|
|
41
48
|
}
|
|
49
|
+
/** @public */
|
|
42
50
|
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
43
51
|
| AtomDisposal<Token>
|
|
44
52
|
| SelectorDisposal<Token>
|
|
45
53
|
|
|
54
|
+
/** @public */
|
|
46
55
|
export type MoleculeCreation = {
|
|
47
56
|
type: `molecule_creation`
|
|
48
57
|
key: Canonical
|
|
49
58
|
provenance: Canonical
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
/** @public */
|
|
52
62
|
export type MoleculeDisposal = {
|
|
53
63
|
type: `molecule_disposal`
|
|
54
64
|
key: Canonical
|
|
@@ -56,6 +66,7 @@ export type MoleculeDisposal = {
|
|
|
56
66
|
values: [key: string, value: any][]
|
|
57
67
|
}
|
|
58
68
|
|
|
69
|
+
/** @public */
|
|
59
70
|
export type MoleculeTransfer = {
|
|
60
71
|
type: `molecule_transfer`
|
|
61
72
|
key: Canonical
|
|
@@ -63,6 +74,7 @@ export type MoleculeTransfer = {
|
|
|
63
74
|
to: Canonical[]
|
|
64
75
|
}
|
|
65
76
|
|
|
77
|
+
/** @public */
|
|
66
78
|
export type TransactionUpdateContent =
|
|
67
79
|
| KeyedStateUpdate<unknown>
|
|
68
80
|
| MoleculeCreation
|
|
@@ -72,6 +84,7 @@ export type TransactionUpdateContent =
|
|
|
72
84
|
| StateDisposal<ReadableToken<unknown>>
|
|
73
85
|
| TransactionUpdate<Func>
|
|
74
86
|
|
|
87
|
+
/** @public */
|
|
75
88
|
export type TransactionUpdate<F extends Func> = {
|
|
76
89
|
type: `transaction_update`
|
|
77
90
|
key: string
|
|
@@ -82,7 +95,9 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
82
95
|
output: ReturnType<F>
|
|
83
96
|
}
|
|
84
97
|
|
|
98
|
+
/** @public */
|
|
85
99
|
export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json`>
|
|
100
|
+
/** @public */
|
|
86
101
|
export type SetterToolkit = Readonly<{
|
|
87
102
|
get: typeof getState
|
|
88
103
|
set: typeof setState
|
|
@@ -91,6 +106,7 @@ export type SetterToolkit = Readonly<{
|
|
|
91
106
|
state: MutableAtomToken<T, J>,
|
|
92
107
|
) => WritablePureSelectorToken<J>
|
|
93
108
|
}>
|
|
109
|
+
/** @public */
|
|
94
110
|
export type ActorToolkit = Readonly<{
|
|
95
111
|
get: typeof getState
|
|
96
112
|
set: typeof setState
|
|
@@ -104,35 +120,55 @@ export type ActorToolkit = Readonly<{
|
|
|
104
120
|
env: () => EnvironmentData
|
|
105
121
|
}>
|
|
106
122
|
|
|
123
|
+
/** @public */
|
|
107
124
|
export type Read<F extends Func> = (
|
|
108
125
|
toolkit: GetterToolkit,
|
|
109
126
|
...parameters: Parameters<F>
|
|
110
127
|
) => ReturnType<F>
|
|
111
128
|
|
|
129
|
+
/** @public */
|
|
112
130
|
export type Write<F extends Func> = (
|
|
113
131
|
toolkit: SetterToolkit,
|
|
114
132
|
...parameters: Parameters<F>
|
|
115
133
|
) => ReturnType<F>
|
|
116
134
|
|
|
135
|
+
/** @public */
|
|
117
136
|
export type Transact<F extends Func> = (
|
|
118
137
|
toolkit: ActorToolkit,
|
|
119
138
|
...parameters: Parameters<F>
|
|
120
139
|
) => ReturnType<F>
|
|
121
140
|
|
|
141
|
+
/** @public */
|
|
142
|
+
export type TransactionIO<Token extends TransactionToken<any>> =
|
|
143
|
+
Token extends TransactionToken<infer F> ? F : never
|
|
144
|
+
|
|
145
|
+
/** @public */
|
|
122
146
|
export type TransactionOptions<F extends Func> = {
|
|
147
|
+
/** The unique identifier of the transaction */
|
|
123
148
|
key: string
|
|
149
|
+
/** The operation to perform */
|
|
124
150
|
do: Transact<F>
|
|
125
151
|
}
|
|
126
152
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
153
|
+
/**
|
|
154
|
+
* @public
|
|
155
|
+
* Create a transaction, a mechanism for batching updates multiple states in a single, all-or-nothing operation
|
|
156
|
+
* @param options - {@link TransactionOptions}
|
|
157
|
+
* @returns A reference to the transaction created: a {@link TransactionToken}
|
|
158
|
+
*/
|
|
130
159
|
export function transaction<F extends Func>(
|
|
131
160
|
options: TransactionOptions<F>,
|
|
132
161
|
): TransactionToken<F> {
|
|
133
162
|
return createTransaction(IMPLICIT.STORE, options)
|
|
134
163
|
}
|
|
135
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @public
|
|
167
|
+
* Execute a {@link transaction}
|
|
168
|
+
* @param token - A {@link TransactionToken}
|
|
169
|
+
* @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
|
|
170
|
+
* @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
|
|
171
|
+
*/
|
|
136
172
|
export function runTransaction<F extends Func>(
|
|
137
173
|
token: TransactionToken<F>,
|
|
138
174
|
id: string = arbitrary(),
|