atom.io 0.34.2 → 0.36.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/eslint-plugin/index.d.ts +2 -18
- package/dist/eslint-plugin/index.d.ts.map +1 -1
- package/dist/eslint-plugin/index.js +4 -141
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +74 -77
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +197 -202
- package/dist/internal/index.js.map +1 -1
- package/dist/json/index.d.ts +9 -17
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +3 -33
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +689 -795
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +55 -23
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.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 +4 -4
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +5 -11
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +2 -2
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +10 -10
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +2 -2
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +18 -18
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +13 -19
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +1 -1
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/package.json +7 -7
- package/src/eslint-plugin/index.ts +0 -1
- package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
- package/src/eslint-plugin/rules/index.ts +0 -1
- package/src/internal/atom/create-regular-atom.ts +1 -0
- package/src/internal/atom/dispose-atom.ts +1 -0
- package/src/internal/atom/index.ts +0 -1
- package/src/internal/families/find-in-store.ts +4 -5
- package/src/internal/families/get-family-of-token.ts +4 -5
- package/src/internal/families/index.ts +0 -1
- package/src/internal/families/init-family-member.ts +3 -4
- package/src/internal/families/seek-in-store.ts +4 -5
- package/src/internal/get-state/read-or-compute-value.ts +14 -2
- package/src/internal/index.ts +116 -96
- package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
- package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
- package/src/internal/join/get-internal-relations-from-store.ts +2 -2
- package/src/internal/join/join-internal.ts +6 -18
- package/src/internal/molecule.ts +1 -0
- package/src/internal/mutable/create-mutable-atom-family.ts +37 -21
- package/src/internal/mutable/create-mutable-atom.ts +17 -13
- package/src/internal/mutable/get-json-family.ts +7 -6
- package/src/internal/mutable/get-json-token.ts +6 -13
- package/src/internal/mutable/get-update-family.ts +7 -8
- package/src/internal/mutable/get-update-token.ts +5 -9
- package/src/internal/mutable/tracker-family.ts +10 -13
- package/src/internal/mutable/tracker.ts +66 -90
- package/src/internal/mutable/transceiver.ts +35 -8
- package/src/internal/selector/dispose-selector.ts +9 -9
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/internal/set-state/copy-mutable-if-needed.ts +8 -6
- package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/store/counterfeit.ts +3 -4
- package/src/internal/store/deposit.ts +7 -9
- package/src/internal/store/store.ts +2 -2
- package/src/internal/store/withdraw.ts +7 -11
- package/src/json/entries.ts +7 -7
- package/src/json/index.ts +0 -2
- package/src/main/atom.ts +68 -127
- package/src/main/dispose-state.ts +4 -6
- package/src/main/find-state.ts +6 -13
- package/src/main/get-state.ts +0 -2
- package/src/main/index.ts +1 -176
- package/src/main/join.ts +2 -9
- package/src/main/logger.ts +7 -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 +245 -0
- package/src/main/transaction.ts +28 -60
- package/src/main/validators.ts +2 -2
- package/src/react/use-json.ts +15 -25
- package/src/react-devtools/store.ts +61 -45
- package/src/realtime/shared-room-store.ts +12 -25
- package/src/realtime-client/pull-mutable-atom-family-member.ts +5 -9
- package/src/realtime-client/pull-mutable-atom.ts +5 -9
- package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
- package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
- package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
- package/src/realtime-server/realtime-mutable-provider.ts +2 -3
- package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +9 -18
- package/src/transceivers/set-rtx/set-rtx.ts +1 -1
- package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
- package/src/eslint-plugin/walk.ts +0 -81
- package/src/internal/atom/create-standalone-atom.ts +0 -39
- package/src/internal/families/create-atom-family.ts +0 -38
- package/src/json/select-json-family.ts +0 -55
- package/src/json/select-json.ts +0 -19
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import type { AsJSON, Func, Transceiver } from "atom.io/internal"
|
|
2
|
+
import type { Canonical, 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, any> ? T : never, 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, any>,
|
|
80
|
+
K extends Canonical = any,
|
|
81
|
+
> = {
|
|
82
|
+
/** The unique identifier of the atom. */
|
|
83
|
+
key: string
|
|
84
|
+
/** Discriminator. */
|
|
85
|
+
type: `mutable_atom`
|
|
86
|
+
/** Present if the atom belongs to a family. */
|
|
87
|
+
family?: FamilyMetadata<K>
|
|
88
|
+
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
89
|
+
__J?: AsJSON<T>
|
|
90
|
+
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
91
|
+
__U?: T extends Transceiver<infer Update, any> ? Update : never
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type SelectorToken<T, K extends Canonical = any> =
|
|
95
|
+
| ReadonlySelectorToken<T, K>
|
|
96
|
+
| WritableSelectorToken<T, K>
|
|
97
|
+
export type ReadonlySelectorToken<T, K extends Canonical = any> =
|
|
98
|
+
| ReadonlyHeldSelectorToken<T, K>
|
|
99
|
+
| ReadonlyPureSelectorToken<T, K>
|
|
100
|
+
export type WritableSelectorToken<T, K extends Canonical = any> =
|
|
101
|
+
| WritableHeldSelectorToken<T, K>
|
|
102
|
+
| WritablePureSelectorToken<T, K>
|
|
103
|
+
export type PureSelectorToken<T, K extends Canonical = any> =
|
|
104
|
+
| ReadonlyPureSelectorToken<T, K>
|
|
105
|
+
| WritablePureSelectorToken<T, K>
|
|
106
|
+
export type HeldSelectorToken<T, K extends Canonical = any> =
|
|
107
|
+
| ReadonlyHeldSelectorToken<T, K>
|
|
108
|
+
| WritableHeldSelectorToken<T, K>
|
|
109
|
+
|
|
110
|
+
export type WritablePureSelectorToken<T, K extends Canonical = any> = {
|
|
111
|
+
/** The unique identifier of the selector. */
|
|
112
|
+
key: string
|
|
113
|
+
/** Discriminator. */
|
|
114
|
+
type: `writable_pure_selector`
|
|
115
|
+
/** Present if the selector belongs to a family. */
|
|
116
|
+
family?: FamilyMetadata<K>
|
|
117
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
118
|
+
__T?: T
|
|
119
|
+
}
|
|
120
|
+
export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
|
|
121
|
+
/** The unique identifier of the selector. */
|
|
122
|
+
key: string
|
|
123
|
+
/** Discriminator. */
|
|
124
|
+
type: `writable_held_selector`
|
|
125
|
+
/** Present if the selector belongs to a family. */
|
|
126
|
+
family?: FamilyMetadata<K>
|
|
127
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
128
|
+
__T?: T
|
|
129
|
+
}
|
|
130
|
+
export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
|
|
131
|
+
/** The unique identifier of the selector. */
|
|
132
|
+
key: string
|
|
133
|
+
/** Discriminator. */
|
|
134
|
+
type: `readonly_pure_selector`
|
|
135
|
+
/** Present if the selector belongs to a family. */
|
|
136
|
+
family?: FamilyMetadata<K>
|
|
137
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
138
|
+
__T?: T
|
|
139
|
+
}
|
|
140
|
+
export type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
|
|
141
|
+
/** The unique identifier of the selector. */
|
|
142
|
+
key: string
|
|
143
|
+
/** Discriminator. */
|
|
144
|
+
type: `readonly_held_selector`
|
|
145
|
+
/** Present if the selector belongs to a family. */
|
|
146
|
+
family?: FamilyMetadata<K>
|
|
147
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
148
|
+
__T?: T
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Identifies a state's connection to its family.
|
|
153
|
+
*/
|
|
154
|
+
export type FamilyMetadata<K extends Canonical = any> = {
|
|
155
|
+
/** The family's unique key. */
|
|
156
|
+
key: string
|
|
157
|
+
/** The family member's unique identifier, in the form of a string. */
|
|
158
|
+
subKey: stringified<K>
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type AtomFamilyToken<T, K extends Canonical = Canonical> =
|
|
162
|
+
| MutableAtomFamilyToken<T extends Transceiver<any, any> ? T : never, K>
|
|
163
|
+
| RegularAtomFamilyToken<T, K>
|
|
164
|
+
export type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
165
|
+
/** The unique identifier of the atom family */
|
|
166
|
+
key: string
|
|
167
|
+
/** Discriminator */
|
|
168
|
+
type: `atom_family`
|
|
169
|
+
/** Never present. This is a marker that preserves the type of atoms in this family */
|
|
170
|
+
__T?: T
|
|
171
|
+
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
172
|
+
__K?: K
|
|
173
|
+
}
|
|
174
|
+
export type MutableAtomFamilyToken<
|
|
175
|
+
T extends Transceiver<any, any>,
|
|
176
|
+
K extends Canonical,
|
|
177
|
+
> = {
|
|
178
|
+
/** The unique identifier of the atom family */
|
|
179
|
+
key: string
|
|
180
|
+
/** Discriminator */
|
|
181
|
+
type: `mutable_atom_family`
|
|
182
|
+
/** Never present. This is a marker that preserves the type of atoms in this family */
|
|
183
|
+
__T?: T
|
|
184
|
+
/** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
|
|
185
|
+
__J?: AsJSON<T>
|
|
186
|
+
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
187
|
+
__K?: K
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export type SelectorFamilyToken<T, K extends Canonical> =
|
|
191
|
+
| ReadonlySelectorFamilyToken<T, K>
|
|
192
|
+
| WritableSelectorFamilyToken<T, K>
|
|
193
|
+
export type ReadonlySelectorFamilyToken<T, K extends Canonical> =
|
|
194
|
+
| ReadonlyHeldSelectorFamilyToken<T, K>
|
|
195
|
+
| ReadonlyPureSelectorFamilyToken<T, K>
|
|
196
|
+
export type WritableSelectorFamilyToken<T, K extends Canonical> =
|
|
197
|
+
| WritableHeldSelectorFamilyToken<T, K>
|
|
198
|
+
| WritablePureSelectorFamilyToken<T, K>
|
|
199
|
+
export type PureSelectorFamilyToken<T, K extends Canonical> =
|
|
200
|
+
| ReadonlyPureSelectorFamilyToken<T, K>
|
|
201
|
+
| WritablePureSelectorFamilyToken<T, K>
|
|
202
|
+
export type HeldSelectorFamilyToken<T, K extends Canonical> =
|
|
203
|
+
| ReadonlyHeldSelectorFamilyToken<T, K>
|
|
204
|
+
| WritableHeldSelectorFamilyToken<T, K>
|
|
205
|
+
|
|
206
|
+
export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
|
|
207
|
+
/** The unique identifier of the family */
|
|
208
|
+
key: string
|
|
209
|
+
/** Discriminator */
|
|
210
|
+
type: `writable_pure_selector_family`
|
|
211
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
212
|
+
__T?: T
|
|
213
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
214
|
+
__K?: K
|
|
215
|
+
}
|
|
216
|
+
export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
|
|
217
|
+
/** The unique identifier of the family */
|
|
218
|
+
key: string
|
|
219
|
+
/** Discriminator */
|
|
220
|
+
type: `readonly_pure_selector_family`
|
|
221
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
222
|
+
__T?: T
|
|
223
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
224
|
+
__K?: K
|
|
225
|
+
}
|
|
226
|
+
export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
227
|
+
/** The unique identifier of the family */
|
|
228
|
+
key: string
|
|
229
|
+
/** Discriminator */
|
|
230
|
+
type: `writable_held_selector_family`
|
|
231
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
232
|
+
__T?: T
|
|
233
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
234
|
+
__K?: K
|
|
235
|
+
}
|
|
236
|
+
export type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
237
|
+
/** The unique identifier of the family */
|
|
238
|
+
key: string
|
|
239
|
+
/** Discriminator */
|
|
240
|
+
type: `readonly_held_selector_family`
|
|
241
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
242
|
+
__T?: T
|
|
243
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
244
|
+
__K?: K
|
|
245
|
+
}
|
package/src/main/transaction.ts
CHANGED
|
@@ -1,80 +1,70 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AsJSON,
|
|
3
|
+
EnvironmentData,
|
|
4
|
+
Func,
|
|
5
|
+
Transceiver,
|
|
6
|
+
} from "atom.io/internal"
|
|
3
7
|
import {
|
|
4
8
|
actUponStore,
|
|
5
9
|
arbitrary,
|
|
6
10
|
createTransaction,
|
|
7
11
|
IMPLICIT,
|
|
8
12
|
} from "atom.io/internal"
|
|
9
|
-
import type { Canonical,
|
|
13
|
+
import type { Canonical, stringified } from "atom.io/json"
|
|
10
14
|
|
|
15
|
+
import type { disposeState } from "./dispose-state"
|
|
16
|
+
import type { findState } from "./find-state"
|
|
17
|
+
import type { getState } from "./get-state"
|
|
18
|
+
import type { resetState } from "./reset-state"
|
|
19
|
+
import type { setState } from "./set-state"
|
|
20
|
+
import type { KeyedStateUpdate } from "./subscribe"
|
|
11
21
|
import type {
|
|
12
|
-
disposeState,
|
|
13
|
-
KeyedStateUpdate,
|
|
14
22
|
MutableAtomToken,
|
|
15
23
|
ReadableToken,
|
|
16
|
-
|
|
24
|
+
TransactionToken,
|
|
17
25
|
WritablePureSelectorToken,
|
|
18
|
-
} from "
|
|
19
|
-
import type {
|
|
26
|
+
} from "./tokens"
|
|
27
|
+
import type { TokenType } from "./validators"
|
|
20
28
|
|
|
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
29
|
export type StateCreation<Token extends ReadableToken<any>> = {
|
|
33
30
|
type: `state_creation`
|
|
34
31
|
token: Token
|
|
35
32
|
}
|
|
36
|
-
|
|
33
|
+
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
34
|
+
| AtomDisposal<Token>
|
|
35
|
+
| SelectorDisposal<Token>
|
|
36
|
+
|
|
37
37
|
export type AtomDisposal<Token extends ReadableToken<any>> = {
|
|
38
38
|
type: `state_disposal`
|
|
39
39
|
subType: `atom`
|
|
40
40
|
token: Token
|
|
41
41
|
value: TokenType<Token>
|
|
42
42
|
}
|
|
43
|
-
/** @public */
|
|
44
43
|
export type SelectorDisposal<Token extends ReadableToken<any>> = {
|
|
45
44
|
type: `state_disposal`
|
|
46
45
|
subType: `selector`
|
|
47
46
|
token: Token
|
|
48
47
|
}
|
|
49
|
-
/** @public */
|
|
50
|
-
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
51
|
-
| AtomDisposal<Token>
|
|
52
|
-
| SelectorDisposal<Token>
|
|
53
48
|
|
|
54
|
-
/** @public */
|
|
55
49
|
export type MoleculeCreation = {
|
|
56
50
|
type: `molecule_creation`
|
|
57
51
|
key: Canonical
|
|
58
52
|
provenance: Canonical
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
/** @public */
|
|
62
54
|
export type MoleculeDisposal = {
|
|
63
55
|
type: `molecule_disposal`
|
|
64
56
|
key: Canonical
|
|
65
57
|
provenance: stringified<Canonical>[]
|
|
66
58
|
values: [key: string, value: any][]
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
/** @public */
|
|
70
60
|
export type MoleculeTransfer = {
|
|
71
61
|
type: `molecule_transfer`
|
|
72
62
|
key: Canonical
|
|
63
|
+
exclusive: boolean
|
|
73
64
|
from: Canonical[]
|
|
74
65
|
to: Canonical[]
|
|
75
66
|
}
|
|
76
67
|
|
|
77
|
-
/** @public */
|
|
78
68
|
export type TransactionUpdateContent =
|
|
79
69
|
| KeyedStateUpdate<unknown>
|
|
80
70
|
| MoleculeCreation
|
|
@@ -84,7 +74,6 @@ export type TransactionUpdateContent =
|
|
|
84
74
|
| StateDisposal<ReadableToken<unknown>>
|
|
85
75
|
| TransactionUpdate<Func>
|
|
86
76
|
|
|
87
|
-
/** @public */
|
|
88
77
|
export type TransactionUpdate<F extends Func> = {
|
|
89
78
|
type: `transaction_update`
|
|
90
79
|
key: string
|
|
@@ -95,54 +84,35 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
95
84
|
output: ReturnType<F>
|
|
96
85
|
}
|
|
97
86
|
|
|
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 */
|
|
87
|
+
export type ReaderToolkit = Pick<ActorToolkit, `find` | `get` | `json`>
|
|
88
|
+
export type WriterToolkit = Pick<ActorToolkit, `find` | `get` | `json` | `set`>
|
|
110
89
|
export type ActorToolkit = Readonly<{
|
|
111
90
|
get: typeof getState
|
|
112
91
|
set: typeof setState
|
|
113
92
|
reset: typeof resetState
|
|
114
93
|
find: typeof findState
|
|
115
|
-
json: <T extends Transceiver<any
|
|
116
|
-
state: MutableAtomToken<T
|
|
117
|
-
) => WritablePureSelectorToken<
|
|
94
|
+
json: <T extends Transceiver<any, any>>(
|
|
95
|
+
state: MutableAtomToken<T>,
|
|
96
|
+
) => WritablePureSelectorToken<AsJSON<T>>
|
|
118
97
|
dispose: typeof disposeState
|
|
119
98
|
run: typeof runTransaction
|
|
120
99
|
env: () => EnvironmentData
|
|
121
100
|
}>
|
|
122
101
|
|
|
123
|
-
/** @public */
|
|
124
102
|
export type Read<F extends Func> = (
|
|
125
|
-
toolkit:
|
|
103
|
+
toolkit: ReaderToolkit,
|
|
126
104
|
...parameters: Parameters<F>
|
|
127
105
|
) => ReturnType<F>
|
|
128
|
-
|
|
129
|
-
/** @public */
|
|
130
106
|
export type Write<F extends Func> = (
|
|
131
|
-
toolkit:
|
|
107
|
+
toolkit: WriterToolkit,
|
|
132
108
|
...parameters: Parameters<F>
|
|
133
109
|
) => ReturnType<F>
|
|
134
|
-
|
|
135
|
-
/** @public */
|
|
136
110
|
export type Transact<F extends Func> = (
|
|
137
111
|
toolkit: ActorToolkit,
|
|
138
112
|
...parameters: Parameters<F>
|
|
139
113
|
) => ReturnType<F>
|
|
140
|
-
|
|
141
|
-
/** @public */
|
|
142
114
|
export type TransactionIO<Token extends TransactionToken<any>> =
|
|
143
115
|
Token extends TransactionToken<infer F> ? F : never
|
|
144
|
-
|
|
145
|
-
/** @public */
|
|
146
116
|
export type TransactionOptions<F extends Func> = {
|
|
147
117
|
/** The unique identifier of the transaction */
|
|
148
118
|
key: string
|
|
@@ -151,7 +121,6 @@ export type TransactionOptions<F extends Func> = {
|
|
|
151
121
|
}
|
|
152
122
|
|
|
153
123
|
/**
|
|
154
|
-
* @public
|
|
155
124
|
* Create a transaction, a mechanism for batching updates multiple states in a single, all-or-nothing operation
|
|
156
125
|
* @param options - {@link TransactionOptions}
|
|
157
126
|
* @returns A reference to the transaction created: a {@link TransactionToken}
|
|
@@ -163,7 +132,6 @@ export function transaction<F extends Func>(
|
|
|
163
132
|
}
|
|
164
133
|
|
|
165
134
|
/**
|
|
166
|
-
* @public
|
|
167
135
|
* Execute a {@link transaction}
|
|
168
136
|
* @param token - A {@link TransactionToken}
|
|
169
137
|
* @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
|
package/src/main/validators.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
WritablePureSelectorFamilyToken,
|
|
12
12
|
WritablePureSelectorToken,
|
|
13
13
|
WritableToken,
|
|
14
|
-
} from "
|
|
14
|
+
} from "./tokens"
|
|
15
15
|
|
|
16
16
|
export type TokenType<
|
|
17
17
|
Comparison extends ReadableFamilyToken<any, any> | ReadableToken<any>,
|
|
@@ -56,7 +56,7 @@ export function belongsTo<Family extends RegularAtomFamilyToken<any, any>>(
|
|
|
56
56
|
family: Family,
|
|
57
57
|
unknownToken: ReadableToken<any>,
|
|
58
58
|
): unknownToken is RegularAtomToken<TokenType<Family>>
|
|
59
|
-
export function belongsTo<Family extends MutableAtomFamilyToken<any, any
|
|
59
|
+
export function belongsTo<Family extends MutableAtomFamilyToken<any, any>>(
|
|
60
60
|
family: Family,
|
|
61
61
|
unknownToken: ReadableToken<any>,
|
|
62
62
|
): unknownToken is MutableAtomToken<TokenType<Family>, any>
|
package/src/react/use-json.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
MutableAtomToken,
|
|
4
|
-
ReadableToken,
|
|
5
|
-
} from "atom.io"
|
|
1
|
+
import type { MutableAtomFamilyToken, MutableAtomToken } from "atom.io"
|
|
2
|
+
import type { AsJSON, Transceiver } from "atom.io/internal"
|
|
6
3
|
import { findInStore, getJsonToken } from "atom.io/internal"
|
|
7
4
|
import type { Canonical, Json } from "atom.io/json"
|
|
8
5
|
import * as React from "react"
|
|
@@ -10,29 +7,22 @@ import * as React from "react"
|
|
|
10
7
|
import { StoreContext } from "./store-context"
|
|
11
8
|
import { useO } from "./use-o"
|
|
12
9
|
|
|
13
|
-
export function useJSON<
|
|
14
|
-
token: MutableAtomToken<
|
|
15
|
-
):
|
|
10
|
+
export function useJSON<T extends Transceiver<any, any>>(
|
|
11
|
+
token: MutableAtomToken<T>,
|
|
12
|
+
): AsJSON<T>
|
|
16
13
|
|
|
17
|
-
export function useJSON<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
export function useJSON<T extends Transceiver<any, any>, K extends Canonical>(
|
|
15
|
+
token: MutableAtomFamilyToken<T, K>,
|
|
16
|
+
key: K,
|
|
17
|
+
): AsJSON<T>
|
|
21
18
|
|
|
22
|
-
export function useJSON
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
token:
|
|
27
|
-
| MutableAtomFamilyToken<any, Serializable, Key>
|
|
28
|
-
| MutableAtomToken<any, Serializable>,
|
|
29
|
-
key?: Key,
|
|
30
|
-
): Serializable {
|
|
19
|
+
export function useJSON(
|
|
20
|
+
token: MutableAtomFamilyToken<any, any> | MutableAtomToken<any>,
|
|
21
|
+
key?: Canonical,
|
|
22
|
+
): Json.Serializable {
|
|
31
23
|
const store = React.useContext(StoreContext)
|
|
32
|
-
const stateToken:
|
|
33
|
-
token.type === `mutable_atom_family`
|
|
34
|
-
? findInStore(store, token, key as Key)
|
|
35
|
-
: token
|
|
24
|
+
const stateToken: MutableAtomToken<any> =
|
|
25
|
+
token.type === `mutable_atom_family` ? findInStore(store, token, key) : token
|
|
36
26
|
const jsonToken = getJsonToken(store, stateToken)
|
|
37
27
|
return useO(jsonToken)
|
|
38
28
|
}
|
|
@@ -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,30 +3,20 @@ import type {
|
|
|
3
3
|
MutableAtomToken,
|
|
4
4
|
ReadonlyPureSelectorFamilyToken,
|
|
5
5
|
} from "atom.io"
|
|
6
|
-
import {
|
|
7
|
-
import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
6
|
+
import { getInternalRelations, join, mutableAtom, selectorFamily } from "atom.io"
|
|
8
7
|
import { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
9
8
|
|
|
10
|
-
export const usersInThisRoomIndex: MutableAtomToken<
|
|
11
|
-
SetRTX<string
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
mutable: true,
|
|
16
|
-
default: () => new SetRTX<string>(),
|
|
17
|
-
toJson: (set) => set.toJSON(),
|
|
18
|
-
fromJson: (json) => SetRTX.fromJSON(json),
|
|
19
|
-
})
|
|
9
|
+
export const usersInThisRoomIndex: MutableAtomToken<SetRTX<string>> =
|
|
10
|
+
mutableAtom<SetRTX<string>>({
|
|
11
|
+
key: `usersInRoomIndex`,
|
|
12
|
+
class: SetRTX,
|
|
13
|
+
})
|
|
20
14
|
|
|
21
|
-
export const roomIndex: MutableAtomToken<
|
|
22
|
-
SetRTX<string
|
|
23
|
-
|
|
24
|
-
> = atom<SetRTX<string>, SetRTXJson<string>>({
|
|
15
|
+
export const roomIndex: MutableAtomToken<SetRTX<string>> = mutableAtom<
|
|
16
|
+
SetRTX<string>
|
|
17
|
+
>({
|
|
25
18
|
key: `roomIndex`,
|
|
26
|
-
|
|
27
|
-
mutable: true,
|
|
28
|
-
toJson: (set) => set.toJSON(),
|
|
29
|
-
fromJson: (json) => SetRTX.fromJSON(json),
|
|
19
|
+
class: SetRTX,
|
|
30
20
|
})
|
|
31
21
|
|
|
32
22
|
export type UserInRoomMeta = {
|
|
@@ -54,12 +44,9 @@ export const usersInRooms: JoinToken<
|
|
|
54
44
|
)
|
|
55
45
|
|
|
56
46
|
export const usersInMyRoomView: ReadonlyPureSelectorFamilyToken<
|
|
57
|
-
MutableAtomToken<SetRTX<string
|
|
47
|
+
MutableAtomToken<SetRTX<string>>[],
|
|
58
48
|
string
|
|
59
|
-
> = selectorFamily<
|
|
60
|
-
MutableAtomToken<SetRTX<string>, SetRTXJson<string>>[],
|
|
61
|
-
string
|
|
62
|
-
>({
|
|
49
|
+
> = selectorFamily<MutableAtomToken<SetRTX<string>>[], string>({
|
|
63
50
|
key: `usersInMyRoomView`,
|
|
64
51
|
get:
|
|
65
52
|
(myUsername) =>
|