atom.io 0.34.2 → 0.35.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/dist/internal/index.d.ts +32 -41
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +106 -128
- package/dist/internal/index.js.map +1 -1
- package/dist/json/index.d.ts +7 -7
- package/dist/json/index.js +2 -2
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +779 -886
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +46 -14
- package/dist/main/index.js.map +1 -1
- package/dist/react-devtools/index.js +10 -10
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +3 -5
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.js +10 -10
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +8 -10
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +4 -4
- package/src/internal/atom/create-regular-atom.ts +1 -0
- package/src/internal/atom/index.ts +0 -1
- package/src/internal/families/index.ts +0 -1
- package/src/internal/index.ts +111 -89
- package/src/internal/join/join-internal.ts +3 -4
- package/src/internal/mutable/create-mutable-atom-family.ts +0 -1
- package/src/internal/mutable/create-mutable-atom.ts +1 -1
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/json/entries.ts +7 -7
- package/src/main/atom.ts +67 -114
- package/src/main/dispose-state.ts +0 -2
- package/src/main/find-state.ts +3 -9
- package/src/main/get-state.ts +0 -2
- package/src/main/index.ts +1 -176
- package/src/main/join.ts +0 -7
- package/src/main/reset-state.ts +0 -2
- package/src/main/selector.ts +5 -72
- package/src/main/set-state.ts +1 -4
- package/src/main/silo.ts +14 -5
- package/src/main/subscribe.ts +0 -7
- package/src/main/timeline.ts +1 -18
- package/src/main/tokens.ts +247 -0
- package/src/main/transaction.ts +17 -55
- package/src/main/validators.ts +1 -1
- package/src/react-devtools/store.ts +61 -45
- package/src/realtime/shared-room-store.ts +3 -5
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +3 -5
- package/src/internal/atom/create-standalone-atom.ts +0 -39
- package/src/internal/families/create-atom-family.ts +0 -38
package/src/main/timeline.ts
CHANGED
|
@@ -10,11 +10,9 @@ import type {
|
|
|
10
10
|
} from "atom.io/internal"
|
|
11
11
|
import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
|
|
12
12
|
|
|
13
|
-
import type { AtomFamilyToken, AtomToken } from "."
|
|
13
|
+
import type { AtomFamilyToken, AtomToken, TimelineToken } from "."
|
|
14
14
|
|
|
15
|
-
/** @public */
|
|
16
15
|
export type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>
|
|
17
|
-
/** @public */
|
|
18
16
|
export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
|
|
19
17
|
any,
|
|
20
18
|
any
|
|
@@ -24,18 +22,7 @@ export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
|
|
|
24
22
|
? M
|
|
25
23
|
: never
|
|
26
24
|
|
|
27
|
-
/** @public */
|
|
28
|
-
export type TimelineToken<M> = {
|
|
29
|
-
/** The unique identifier of the timeline */
|
|
30
|
-
key: string
|
|
31
|
-
/** Discriminator */
|
|
32
|
-
type: `timeline`
|
|
33
|
-
/** Never present. This is a marker that preserves the type of the managed atoms */
|
|
34
|
-
__M?: M
|
|
35
|
-
}
|
|
36
|
-
|
|
37
25
|
/**
|
|
38
|
-
* @public
|
|
39
26
|
* 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
27
|
* @param timeline - A {@link TimelineToken}
|
|
41
28
|
*/
|
|
@@ -43,7 +30,6 @@ export const redo = (timeline: TimelineToken<any>): void => {
|
|
|
43
30
|
timeTravel(IMPLICIT.STORE, `redo`, timeline)
|
|
44
31
|
}
|
|
45
32
|
/**
|
|
46
|
-
* @public
|
|
47
33
|
* Reverse the last update on the {@link timeline} and move the cursor to the previous update
|
|
48
34
|
* @param timeline - A {@link TimelineToken}
|
|
49
35
|
*/
|
|
@@ -51,7 +37,6 @@ export const undo = (timeline: TimelineToken<any>): void => {
|
|
|
51
37
|
timeTravel(IMPLICIT.STORE, `undo`, timeline)
|
|
52
38
|
}
|
|
53
39
|
|
|
54
|
-
/** @public */
|
|
55
40
|
export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
56
41
|
| TimelineAtomUpdate<ManagedAtom>
|
|
57
42
|
| TimelineMoleculeCreation
|
|
@@ -61,7 +46,6 @@ export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
|
61
46
|
| TimelineStateDisposal<AtomOnly<ManagedAtom>>
|
|
62
47
|
| TimelineTransactionUpdate
|
|
63
48
|
|
|
64
|
-
/** @public */
|
|
65
49
|
export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
66
50
|
/** The unique identifier of the timeline */
|
|
67
51
|
key: string
|
|
@@ -75,7 +59,6 @@ export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
|
75
59
|
}
|
|
76
60
|
|
|
77
61
|
/**
|
|
78
|
-
* @public
|
|
79
62
|
* Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms
|
|
80
63
|
* @param options - {@link TimelineOptions}
|
|
81
64
|
* @returns A reference to the timeline created: a {@link TimelineToken}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import type { Func, Transceiver } from "atom.io/internal"
|
|
2
|
+
import type { Canonical, Json, stringified } from "atom.io/json"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
|
|
6
|
+
*
|
|
7
|
+
* While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
|
|
8
|
+
*
|
|
9
|
+
* Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
|
|
10
|
+
*
|
|
11
|
+
* Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
|
|
12
|
+
*
|
|
13
|
+
* Tokens are fully serializable, so they can be passed between processes.
|
|
14
|
+
*/
|
|
15
|
+
export type AtomIOToken =
|
|
16
|
+
| ReadableFamilyToken<any, any>
|
|
17
|
+
| ReadableToken<any>
|
|
18
|
+
| TimelineToken<any>
|
|
19
|
+
| TransactionToken<any>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* These states cannot be set.
|
|
23
|
+
*/
|
|
24
|
+
export type ReadableToken<T, K extends Canonical = any> =
|
|
25
|
+
| AtomToken<T, K>
|
|
26
|
+
| SelectorToken<T, K>
|
|
27
|
+
/**
|
|
28
|
+
* These states can be set.
|
|
29
|
+
*/
|
|
30
|
+
export type WritableToken<T, K extends Canonical = any> =
|
|
31
|
+
| AtomToken<T, K>
|
|
32
|
+
| WritableSelectorToken<T, K>
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* States belonging to this family can be gotten from the store.
|
|
36
|
+
*/
|
|
37
|
+
export type ReadableFamilyToken<T, K extends Canonical> =
|
|
38
|
+
| AtomFamilyToken<T, K>
|
|
39
|
+
| SelectorFamilyToken<T, K>
|
|
40
|
+
/**
|
|
41
|
+
* States belonging to this family can be set.
|
|
42
|
+
*/
|
|
43
|
+
export type WritableFamilyToken<T, K extends Canonical> =
|
|
44
|
+
| AtomFamilyToken<T, K>
|
|
45
|
+
| WritableSelectorFamilyToken<T, K>
|
|
46
|
+
|
|
47
|
+
export type TimelineToken<M> = {
|
|
48
|
+
/** The unique identifier of the timeline */
|
|
49
|
+
key: string
|
|
50
|
+
/** Discriminator */
|
|
51
|
+
type: `timeline`
|
|
52
|
+
/** Never present. This is a marker that preserves the type of the managed atoms */
|
|
53
|
+
__M?: M
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type TransactionToken<F extends Func> = {
|
|
57
|
+
/** The unique identifier of the transaction */
|
|
58
|
+
key: string
|
|
59
|
+
/** Discriminator */
|
|
60
|
+
type: `transaction`
|
|
61
|
+
/** Never present. This is a marker that preserves the type of the transaction function */
|
|
62
|
+
__F?: F
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type AtomToken<T, K extends Canonical = any> =
|
|
66
|
+
| MutableAtomToken<T extends Transceiver<any> ? T : never, any, K>
|
|
67
|
+
| RegularAtomToken<T, K>
|
|
68
|
+
export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
69
|
+
/** The unique identifier of the atom. */
|
|
70
|
+
key: string
|
|
71
|
+
/** Discriminator. */
|
|
72
|
+
type: `atom`
|
|
73
|
+
/** Present if the atom belongs to a family. */
|
|
74
|
+
family?: FamilyMetadata<K>
|
|
75
|
+
/** Never present. This is a marker that preserves the type of the atom's value. */
|
|
76
|
+
__T?: T
|
|
77
|
+
}
|
|
78
|
+
export type MutableAtomToken<
|
|
79
|
+
T extends Transceiver<any>,
|
|
80
|
+
J extends Json.Serializable,
|
|
81
|
+
K extends Canonical = any,
|
|
82
|
+
> = {
|
|
83
|
+
/** The unique identifier of the atom. */
|
|
84
|
+
key: string
|
|
85
|
+
/** Discriminator. */
|
|
86
|
+
type: `mutable_atom`
|
|
87
|
+
/** Present if the atom belongs to a family. */
|
|
88
|
+
family?: FamilyMetadata<K>
|
|
89
|
+
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
90
|
+
__J?: J
|
|
91
|
+
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
92
|
+
__U?: T extends Transceiver<infer Update> ? Update : never
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type SelectorToken<T, K extends Canonical = any> =
|
|
96
|
+
| ReadonlySelectorToken<T, K>
|
|
97
|
+
| WritableSelectorToken<T, K>
|
|
98
|
+
export type ReadonlySelectorToken<T, K extends Canonical = any> =
|
|
99
|
+
| ReadonlyHeldSelectorToken<T, K>
|
|
100
|
+
| ReadonlyPureSelectorToken<T, K>
|
|
101
|
+
export type WritableSelectorToken<T, K extends Canonical = any> =
|
|
102
|
+
| WritableHeldSelectorToken<T, K>
|
|
103
|
+
| WritablePureSelectorToken<T, K>
|
|
104
|
+
export type PureSelectorToken<T, K extends Canonical = any> =
|
|
105
|
+
| ReadonlyPureSelectorToken<T, K>
|
|
106
|
+
| WritablePureSelectorToken<T, K>
|
|
107
|
+
export type HeldSelectorToken<T, K extends Canonical = any> =
|
|
108
|
+
| ReadonlyHeldSelectorToken<T, K>
|
|
109
|
+
| WritableHeldSelectorToken<T, K>
|
|
110
|
+
|
|
111
|
+
export type WritablePureSelectorToken<T, K extends Canonical = any> = {
|
|
112
|
+
/** The unique identifier of the selector. */
|
|
113
|
+
key: string
|
|
114
|
+
/** Discriminator. */
|
|
115
|
+
type: `writable_pure_selector`
|
|
116
|
+
/** Present if the selector belongs to a family. */
|
|
117
|
+
family?: FamilyMetadata<K>
|
|
118
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
119
|
+
__T?: T
|
|
120
|
+
}
|
|
121
|
+
export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
|
|
122
|
+
/** The unique identifier of the selector. */
|
|
123
|
+
key: string
|
|
124
|
+
/** Discriminator. */
|
|
125
|
+
type: `writable_held_selector`
|
|
126
|
+
/** Present if the selector belongs to a family. */
|
|
127
|
+
family?: FamilyMetadata<K>
|
|
128
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
129
|
+
__T?: T
|
|
130
|
+
}
|
|
131
|
+
export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
|
|
132
|
+
/** The unique identifier of the selector. */
|
|
133
|
+
key: string
|
|
134
|
+
/** Discriminator. */
|
|
135
|
+
type: `readonly_pure_selector`
|
|
136
|
+
/** Present if the selector belongs to a family. */
|
|
137
|
+
family?: FamilyMetadata<K>
|
|
138
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
139
|
+
__T?: T
|
|
140
|
+
}
|
|
141
|
+
export type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
|
|
142
|
+
/** The unique identifier of the selector. */
|
|
143
|
+
key: string
|
|
144
|
+
/** Discriminator. */
|
|
145
|
+
type: `readonly_held_selector`
|
|
146
|
+
/** Present if the selector belongs to a family. */
|
|
147
|
+
family?: FamilyMetadata<K>
|
|
148
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
149
|
+
__T?: T
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Identifies a state's connection to its family.
|
|
154
|
+
*/
|
|
155
|
+
export type FamilyMetadata<K extends Canonical = any> = {
|
|
156
|
+
/** The family's unique key. */
|
|
157
|
+
key: string
|
|
158
|
+
/** The family member's unique identifier, in the form of a string. */
|
|
159
|
+
subKey: stringified<K>
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export type AtomFamilyToken<T, K extends Canonical = Canonical> =
|
|
163
|
+
| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>
|
|
164
|
+
| RegularAtomFamilyToken<T, K>
|
|
165
|
+
export type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
166
|
+
/** The unique identifier of the atom family */
|
|
167
|
+
key: string
|
|
168
|
+
/** Discriminator */
|
|
169
|
+
type: `atom_family`
|
|
170
|
+
/** Never present. This is a marker that preserves the type of atoms in this family */
|
|
171
|
+
__T?: T
|
|
172
|
+
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
173
|
+
__K?: K
|
|
174
|
+
}
|
|
175
|
+
export type MutableAtomFamilyToken<
|
|
176
|
+
T extends Transceiver<any>,
|
|
177
|
+
J extends Json.Serializable,
|
|
178
|
+
K extends Canonical,
|
|
179
|
+
> = {
|
|
180
|
+
/** The unique identifier of the atom family */
|
|
181
|
+
key: string
|
|
182
|
+
/** Discriminator */
|
|
183
|
+
type: `mutable_atom_family`
|
|
184
|
+
/** Never present. This is a marker that preserves the type of atoms in this family */
|
|
185
|
+
__T?: T
|
|
186
|
+
/** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
|
|
187
|
+
__J?: J
|
|
188
|
+
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
189
|
+
__K?: K
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export type SelectorFamilyToken<T, K extends Canonical> =
|
|
193
|
+
| ReadonlySelectorFamilyToken<T, K>
|
|
194
|
+
| WritableSelectorFamilyToken<T, K>
|
|
195
|
+
export type ReadonlySelectorFamilyToken<T, K extends Canonical> =
|
|
196
|
+
| ReadonlyHeldSelectorFamilyToken<T, K>
|
|
197
|
+
| ReadonlyPureSelectorFamilyToken<T, K>
|
|
198
|
+
export type WritableSelectorFamilyToken<T, K extends Canonical> =
|
|
199
|
+
| WritableHeldSelectorFamilyToken<T, K>
|
|
200
|
+
| WritablePureSelectorFamilyToken<T, K>
|
|
201
|
+
export type PureSelectorFamilyToken<T, K extends Canonical> =
|
|
202
|
+
| ReadonlyPureSelectorFamilyToken<T, K>
|
|
203
|
+
| WritablePureSelectorFamilyToken<T, K>
|
|
204
|
+
export type HeldSelectorFamilyToken<T, K extends Canonical> =
|
|
205
|
+
| ReadonlyHeldSelectorFamilyToken<T, K>
|
|
206
|
+
| WritableHeldSelectorFamilyToken<T, K>
|
|
207
|
+
|
|
208
|
+
export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
|
|
209
|
+
/** The unique identifier of the family */
|
|
210
|
+
key: string
|
|
211
|
+
/** Discriminator */
|
|
212
|
+
type: `writable_pure_selector_family`
|
|
213
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
214
|
+
__T?: T
|
|
215
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
216
|
+
__K?: K
|
|
217
|
+
}
|
|
218
|
+
export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
|
|
219
|
+
/** The unique identifier of the family */
|
|
220
|
+
key: string
|
|
221
|
+
/** Discriminator */
|
|
222
|
+
type: `readonly_pure_selector_family`
|
|
223
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
224
|
+
__T?: T
|
|
225
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
226
|
+
__K?: K
|
|
227
|
+
}
|
|
228
|
+
export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
229
|
+
/** The unique identifier of the family */
|
|
230
|
+
key: string
|
|
231
|
+
/** Discriminator */
|
|
232
|
+
type: `writable_held_selector_family`
|
|
233
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
234
|
+
__T?: T
|
|
235
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
236
|
+
__K?: K
|
|
237
|
+
}
|
|
238
|
+
export type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
239
|
+
/** The unique identifier of the family */
|
|
240
|
+
key: string
|
|
241
|
+
/** Discriminator */
|
|
242
|
+
type: `readonly_held_selector_family`
|
|
243
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
244
|
+
__T?: T
|
|
245
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
246
|
+
__K?: K
|
|
247
|
+
}
|
package/src/main/transaction.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { findState, getState, setState } from "atom.io"
|
|
2
1
|
import type { EnvironmentData, Func, Transceiver } from "atom.io/internal"
|
|
3
2
|
import {
|
|
4
3
|
actUponStore,
|
|
@@ -8,65 +7,51 @@ import {
|
|
|
8
7
|
} from "atom.io/internal"
|
|
9
8
|
import type { Canonical, Json, stringified } from "atom.io/json"
|
|
10
9
|
|
|
10
|
+
import type { disposeState } from "./dispose-state"
|
|
11
|
+
import type { findState } from "./find-state"
|
|
12
|
+
import type { getState } from "./get-state"
|
|
13
|
+
import type { resetState } from "./reset-state"
|
|
14
|
+
import type { setState } from "./set-state"
|
|
15
|
+
import type { KeyedStateUpdate } from "./subscribe"
|
|
11
16
|
import type {
|
|
12
|
-
disposeState,
|
|
13
|
-
KeyedStateUpdate,
|
|
14
17
|
MutableAtomToken,
|
|
15
18
|
ReadableToken,
|
|
16
|
-
|
|
19
|
+
TransactionToken,
|
|
17
20
|
WritablePureSelectorToken,
|
|
18
|
-
} from "
|
|
19
|
-
import type {
|
|
21
|
+
} from "./tokens"
|
|
22
|
+
import type { TokenType } from "./validators"
|
|
20
23
|
|
|
21
|
-
/** @public */
|
|
22
|
-
export type TransactionToken<F extends Func> = {
|
|
23
|
-
/** The unique identifier of the transaction */
|
|
24
|
-
key: string
|
|
25
|
-
/** Discriminator */
|
|
26
|
-
type: `transaction`
|
|
27
|
-
/** Never present. This is a marker that preserves the type of the transaction function */
|
|
28
|
-
__F?: F
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** @public */
|
|
32
24
|
export type StateCreation<Token extends ReadableToken<any>> = {
|
|
33
25
|
type: `state_creation`
|
|
34
26
|
token: Token
|
|
35
27
|
}
|
|
36
|
-
|
|
28
|
+
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
29
|
+
| AtomDisposal<Token>
|
|
30
|
+
| SelectorDisposal<Token>
|
|
31
|
+
|
|
37
32
|
export type AtomDisposal<Token extends ReadableToken<any>> = {
|
|
38
33
|
type: `state_disposal`
|
|
39
34
|
subType: `atom`
|
|
40
35
|
token: Token
|
|
41
36
|
value: TokenType<Token>
|
|
42
37
|
}
|
|
43
|
-
/** @public */
|
|
44
38
|
export type SelectorDisposal<Token extends ReadableToken<any>> = {
|
|
45
39
|
type: `state_disposal`
|
|
46
40
|
subType: `selector`
|
|
47
41
|
token: Token
|
|
48
42
|
}
|
|
49
|
-
/** @public */
|
|
50
|
-
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
51
|
-
| AtomDisposal<Token>
|
|
52
|
-
| SelectorDisposal<Token>
|
|
53
43
|
|
|
54
|
-
/** @public */
|
|
55
44
|
export type MoleculeCreation = {
|
|
56
45
|
type: `molecule_creation`
|
|
57
46
|
key: Canonical
|
|
58
47
|
provenance: Canonical
|
|
59
48
|
}
|
|
60
|
-
|
|
61
|
-
/** @public */
|
|
62
49
|
export type MoleculeDisposal = {
|
|
63
50
|
type: `molecule_disposal`
|
|
64
51
|
key: Canonical
|
|
65
52
|
provenance: stringified<Canonical>[]
|
|
66
53
|
values: [key: string, value: any][]
|
|
67
54
|
}
|
|
68
|
-
|
|
69
|
-
/** @public */
|
|
70
55
|
export type MoleculeTransfer = {
|
|
71
56
|
type: `molecule_transfer`
|
|
72
57
|
key: Canonical
|
|
@@ -74,7 +59,6 @@ export type MoleculeTransfer = {
|
|
|
74
59
|
to: Canonical[]
|
|
75
60
|
}
|
|
76
61
|
|
|
77
|
-
/** @public */
|
|
78
62
|
export type TransactionUpdateContent =
|
|
79
63
|
| KeyedStateUpdate<unknown>
|
|
80
64
|
| MoleculeCreation
|
|
@@ -84,7 +68,6 @@ export type TransactionUpdateContent =
|
|
|
84
68
|
| StateDisposal<ReadableToken<unknown>>
|
|
85
69
|
| TransactionUpdate<Func>
|
|
86
70
|
|
|
87
|
-
/** @public */
|
|
88
71
|
export type TransactionUpdate<F extends Func> = {
|
|
89
72
|
type: `transaction_update`
|
|
90
73
|
key: string
|
|
@@ -95,18 +78,8 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
95
78
|
output: ReturnType<F>
|
|
96
79
|
}
|
|
97
80
|
|
|
98
|
-
|
|
99
|
-
export type
|
|
100
|
-
/** @public */
|
|
101
|
-
export type SetterToolkit = Readonly<{
|
|
102
|
-
get: typeof getState
|
|
103
|
-
set: typeof setState
|
|
104
|
-
find: typeof findState
|
|
105
|
-
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
106
|
-
state: MutableAtomToken<T, J>,
|
|
107
|
-
) => WritablePureSelectorToken<J>
|
|
108
|
-
}>
|
|
109
|
-
/** @public */
|
|
81
|
+
export type ReaderToolkit = Pick<ActorToolkit, `find` | `get` | `json`>
|
|
82
|
+
export type WriterToolkit = Pick<ActorToolkit, `find` | `get` | `json` | `set`>
|
|
110
83
|
export type ActorToolkit = Readonly<{
|
|
111
84
|
get: typeof getState
|
|
112
85
|
set: typeof setState
|
|
@@ -120,29 +93,20 @@ export type ActorToolkit = Readonly<{
|
|
|
120
93
|
env: () => EnvironmentData
|
|
121
94
|
}>
|
|
122
95
|
|
|
123
|
-
/** @public */
|
|
124
96
|
export type Read<F extends Func> = (
|
|
125
|
-
toolkit:
|
|
97
|
+
toolkit: ReaderToolkit,
|
|
126
98
|
...parameters: Parameters<F>
|
|
127
99
|
) => ReturnType<F>
|
|
128
|
-
|
|
129
|
-
/** @public */
|
|
130
100
|
export type Write<F extends Func> = (
|
|
131
|
-
toolkit:
|
|
101
|
+
toolkit: WriterToolkit,
|
|
132
102
|
...parameters: Parameters<F>
|
|
133
103
|
) => ReturnType<F>
|
|
134
|
-
|
|
135
|
-
/** @public */
|
|
136
104
|
export type Transact<F extends Func> = (
|
|
137
105
|
toolkit: ActorToolkit,
|
|
138
106
|
...parameters: Parameters<F>
|
|
139
107
|
) => ReturnType<F>
|
|
140
|
-
|
|
141
|
-
/** @public */
|
|
142
108
|
export type TransactionIO<Token extends TransactionToken<any>> =
|
|
143
109
|
Token extends TransactionToken<infer F> ? F : never
|
|
144
|
-
|
|
145
|
-
/** @public */
|
|
146
110
|
export type TransactionOptions<F extends Func> = {
|
|
147
111
|
/** The unique identifier of the transaction */
|
|
148
112
|
key: string
|
|
@@ -151,7 +115,6 @@ export type TransactionOptions<F extends Func> = {
|
|
|
151
115
|
}
|
|
152
116
|
|
|
153
117
|
/**
|
|
154
|
-
* @public
|
|
155
118
|
* Create a transaction, a mechanism for batching updates multiple states in a single, all-or-nothing operation
|
|
156
119
|
* @param options - {@link TransactionOptions}
|
|
157
120
|
* @returns A reference to the transaction created: a {@link TransactionToken}
|
|
@@ -163,7 +126,6 @@ export function transaction<F extends Func>(
|
|
|
163
126
|
}
|
|
164
127
|
|
|
165
128
|
/**
|
|
166
|
-
* @public
|
|
167
129
|
* Execute a {@link transaction}
|
|
168
130
|
* @param token - A {@link TransactionToken}
|
|
169
131
|
* @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
|
package/src/main/validators.ts
CHANGED
|
@@ -6,8 +6,8 @@ import type {
|
|
|
6
6
|
TransactionToken,
|
|
7
7
|
} from "atom.io"
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
createRegularAtom,
|
|
10
|
+
createRegularAtomFamily,
|
|
11
11
|
createTransaction,
|
|
12
12
|
type Store,
|
|
13
13
|
} from "atom.io/internal"
|
|
@@ -39,53 +39,69 @@ export function attachDevtoolsStates(
|
|
|
39
39
|
): DevtoolsStates & IntrospectionStates & { store: Store } {
|
|
40
40
|
const introspectionStates = attachIntrospectionStates(store)
|
|
41
41
|
|
|
42
|
-
const devtoolsAreHiddenAtom =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
window.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
const devtoolsAreHiddenAtom = createRegularAtom<boolean>(
|
|
43
|
+
store,
|
|
44
|
+
{
|
|
45
|
+
key: `🔍 Devtools Are Hidden`,
|
|
46
|
+
default: hideByDefault,
|
|
47
|
+
effects:
|
|
48
|
+
typeof window === `undefined`
|
|
49
|
+
? []
|
|
50
|
+
: [
|
|
51
|
+
persistSync(window.localStorage, JSON, `🔍 Devtools Are Hidden`),
|
|
52
|
+
({ setSelf }) => {
|
|
53
|
+
window.addEventListener(`keydown`, (e) => {
|
|
54
|
+
if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === `a`) {
|
|
55
|
+
e.preventDefault()
|
|
56
|
+
setSelf((state) => !state)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
undefined,
|
|
63
|
+
)
|
|
60
64
|
|
|
61
|
-
const devtoolsAreOpenAtom =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const devtoolsAreOpenAtom = createRegularAtom<boolean>(
|
|
66
|
+
store,
|
|
67
|
+
{
|
|
68
|
+
key: `🔍 Devtools Are Open`,
|
|
69
|
+
default: true,
|
|
70
|
+
effects:
|
|
71
|
+
typeof window === `undefined`
|
|
72
|
+
? []
|
|
73
|
+
: [persistSync(window.localStorage, JSON, `🔍 Devtools Are Open`)],
|
|
74
|
+
},
|
|
75
|
+
undefined,
|
|
76
|
+
)
|
|
69
77
|
|
|
70
|
-
const devtoolsViewSelectionAtom =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
const devtoolsViewSelectionAtom = createRegularAtom<DevtoolsView>(
|
|
79
|
+
store,
|
|
80
|
+
{
|
|
81
|
+
key: `🔍 Devtools View Selection`,
|
|
82
|
+
default: `atoms`,
|
|
83
|
+
effects:
|
|
84
|
+
typeof window === `undefined`
|
|
85
|
+
? []
|
|
86
|
+
: [persistSync(window.localStorage, JSON, `🔍 Devtools View`)],
|
|
87
|
+
},
|
|
88
|
+
undefined,
|
|
89
|
+
)
|
|
78
90
|
|
|
79
|
-
const devtoolsViewOptionsAtom =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
const devtoolsViewOptionsAtom = createRegularAtom<DevtoolsView[]>(
|
|
92
|
+
store,
|
|
93
|
+
{
|
|
94
|
+
key: `🔍 Devtools View Options`,
|
|
95
|
+
default: [`atoms`, `selectors`, `transactions`, `timelines`],
|
|
96
|
+
effects:
|
|
97
|
+
typeof window === `undefined`
|
|
98
|
+
? []
|
|
99
|
+
: [persistSync(window.localStorage, JSON, `🔍 Devtools View Options`)],
|
|
100
|
+
},
|
|
101
|
+
undefined,
|
|
102
|
+
)
|
|
87
103
|
|
|
88
|
-
const viewIsOpenAtoms =
|
|
104
|
+
const viewIsOpenAtoms = createRegularAtomFamily<
|
|
89
105
|
boolean,
|
|
90
106
|
readonly (number | string)[]
|
|
91
107
|
>(store, {
|
|
@@ -3,16 +3,15 @@ import type {
|
|
|
3
3
|
MutableAtomToken,
|
|
4
4
|
ReadonlyPureSelectorFamilyToken,
|
|
5
5
|
} from "atom.io"
|
|
6
|
-
import {
|
|
6
|
+
import { getInternalRelations, join, mutableAtom, selectorFamily } from "atom.io"
|
|
7
7
|
import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
8
8
|
import { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
9
9
|
|
|
10
10
|
export const usersInThisRoomIndex: MutableAtomToken<
|
|
11
11
|
SetRTX<string>,
|
|
12
12
|
SetRTXJson<string>
|
|
13
|
-
> =
|
|
13
|
+
> = mutableAtom<SetRTX<string>, SetRTXJson<string>>({
|
|
14
14
|
key: `usersInRoomIndex`,
|
|
15
|
-
mutable: true,
|
|
16
15
|
default: () => new SetRTX<string>(),
|
|
17
16
|
toJson: (set) => set.toJSON(),
|
|
18
17
|
fromJson: (json) => SetRTX.fromJSON(json),
|
|
@@ -21,10 +20,9 @@ export const usersInThisRoomIndex: MutableAtomToken<
|
|
|
21
20
|
export const roomIndex: MutableAtomToken<
|
|
22
21
|
SetRTX<string>,
|
|
23
22
|
SetRTXJson<string>
|
|
24
|
-
> =
|
|
23
|
+
> = mutableAtom<SetRTX<string>, SetRTXJson<string>>({
|
|
25
24
|
key: `roomIndex`,
|
|
26
25
|
default: () => new SetRTX<string>(),
|
|
27
|
-
mutable: true,
|
|
28
26
|
toJson: (set) => set.toJSON(),
|
|
29
27
|
fromJson: (json) => SetRTX.fromJSON(json),
|
|
30
28
|
})
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
MutableAtomToken,
|
|
5
5
|
RegularAtomFamilyToken,
|
|
6
6
|
} from "atom.io"
|
|
7
|
-
import {
|
|
7
|
+
import { atomFamily, join, mutableAtom } from "atom.io"
|
|
8
8
|
import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
9
9
|
import { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
10
10
|
|
|
@@ -32,9 +32,8 @@ export const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey> =
|
|
|
32
32
|
export const socketIndex: MutableAtomToken<
|
|
33
33
|
SetRTX<SocketKey>,
|
|
34
34
|
SetRTXJson<SocketKey>
|
|
35
|
-
> =
|
|
35
|
+
> = mutableAtom<SetRTX<SocketKey>, SetRTXJson<SocketKey>>({
|
|
36
36
|
key: `socketsIndex`,
|
|
37
|
-
mutable: true,
|
|
38
37
|
default: () => new SetRTX(),
|
|
39
38
|
toJson: (set) => set.toJSON(),
|
|
40
39
|
fromJson: (json) => SetRTX.fromJSON(json),
|
|
@@ -42,9 +41,8 @@ export const socketIndex: MutableAtomToken<
|
|
|
42
41
|
export const userIndex: MutableAtomToken<
|
|
43
42
|
SetRTX<UserKey>,
|
|
44
43
|
SetRTXJson<UserKey>
|
|
45
|
-
> =
|
|
44
|
+
> = mutableAtom<SetRTX<UserKey>, SetRTXJson<UserKey>>({
|
|
46
45
|
key: `usersIndex`,
|
|
47
|
-
mutable: true,
|
|
48
46
|
default: () => new SetRTX(),
|
|
49
47
|
toJson: (set) => set.toJSON(),
|
|
50
48
|
fromJson: (json) => SetRTX.fromJSON(json),
|