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/find-state.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
MutableAtomFamilyToken,
|
|
3
2
|
MutableAtomToken,
|
|
4
3
|
ReadableFamilyToken,
|
|
5
4
|
ReadableToken,
|
|
6
5
|
ReadonlySelectorFamilyToken,
|
|
7
6
|
ReadonlySelectorToken,
|
|
8
|
-
RegularAtomFamilyToken,
|
|
9
7
|
RegularAtomToken,
|
|
10
8
|
WritableFamilyToken,
|
|
11
9
|
WritableSelectorFamilyToken,
|
|
@@ -16,8 +14,9 @@ import type { Transceiver } from "atom.io/internal"
|
|
|
16
14
|
import { findInStore, IMPLICIT } from "atom.io/internal"
|
|
17
15
|
import type { Canonical, Json } from "atom.io/json"
|
|
18
16
|
|
|
17
|
+
import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
|
|
18
|
+
|
|
19
19
|
/**
|
|
20
|
-
* @public
|
|
21
20
|
* Finds a {@link MutableAtomToken} in the store, without accessing its value.
|
|
22
21
|
*
|
|
23
22
|
* In an ephemeral store, this will create a new atom if one does not exist with the given key.
|
|
@@ -37,7 +36,6 @@ export function findState<
|
|
|
37
36
|
Key extends K,
|
|
38
37
|
>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>
|
|
39
38
|
/**
|
|
40
|
-
* @public
|
|
41
39
|
* Finds a {@link RegularAtomToken} in the store, without accessing its value.
|
|
42
40
|
*
|
|
43
41
|
* In an ephemeral store, this will create a new atom if one does not exist with the given key.
|
|
@@ -55,7 +53,6 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
55
53
|
key: Key,
|
|
56
54
|
): RegularAtomToken<T, K>
|
|
57
55
|
/**
|
|
58
|
-
* @public
|
|
59
56
|
* Finds a {@link WritableSelectorToken} in the store, without accessing its value.
|
|
60
57
|
*
|
|
61
58
|
* In an ephemeral store, this will create a new selector if one does not exist with the given key.
|
|
@@ -73,7 +70,6 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
73
70
|
key: Key,
|
|
74
71
|
): WritableSelectorToken<T, K>
|
|
75
72
|
/**
|
|
76
|
-
* @public
|
|
77
73
|
* Finds a {@link ReadonlySelectorToken} in the store, without accessing its value.
|
|
78
74
|
*
|
|
79
75
|
* In an ephemeral store, this will create a new selector if one does not exist with the given key.
|
|
@@ -91,7 +87,6 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
91
87
|
key: Key,
|
|
92
88
|
): ReadonlySelectorToken<T, K>
|
|
93
89
|
/**
|
|
94
|
-
* @public
|
|
95
90
|
* Finds a {@link WritableToken} in the store, without accessing its value.
|
|
96
91
|
*
|
|
97
92
|
* In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
|
|
@@ -109,7 +104,6 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
109
104
|
key: Key,
|
|
110
105
|
): WritableToken<T, K>
|
|
111
106
|
/**
|
|
112
|
-
* @public
|
|
113
107
|
* Finds a {@link MutableAtomToken} in the store, without accessing its value.
|
|
114
108
|
*
|
|
115
109
|
* In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
|
|
@@ -130,7 +124,7 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
130
124
|
|
|
131
125
|
export function findState(
|
|
132
126
|
token: ReadableFamilyToken<any, any>,
|
|
133
|
-
key:
|
|
127
|
+
key: Canonical,
|
|
134
128
|
): ReadableToken<any> {
|
|
135
129
|
const state = findInStore(IMPLICIT.STORE, token, key)
|
|
136
130
|
return state
|
package/src/main/get-state.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { Canonical } from "atom.io/json"
|
|
|
4
4
|
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @public
|
|
8
7
|
* Read or compute the current value of a state
|
|
9
8
|
* @param token - The token of the state to get
|
|
10
9
|
* @return The current value of the state
|
|
@@ -14,7 +13,6 @@ import type { ReadableFamilyToken, ReadableToken } from "."
|
|
|
14
13
|
export function getState<T>(token: ReadableToken<T>): T
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
|
-
* @public
|
|
18
16
|
* Read or compute the current value of a state
|
|
19
17
|
* @param token - The token of a state family
|
|
20
18
|
* @param key - The unique key of the state to get
|
package/src/main/index.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import type { Transceiver } from "atom.io/internal"
|
|
2
|
-
import type { Canonical, Json, stringified } from "atom.io/json"
|
|
3
|
-
|
|
4
|
-
import type { AtomFamilyToken } from "./atom"
|
|
5
|
-
import type {
|
|
6
|
-
SelectorFamilyToken,
|
|
7
|
-
WritableSelectorFamilyToken,
|
|
8
|
-
} from "./selector"
|
|
9
|
-
import type { TimelineToken } from "./timeline"
|
|
10
|
-
import type { TransactionToken } from "./transaction"
|
|
11
|
-
|
|
12
1
|
export * from "./atom"
|
|
13
2
|
export * from "./dispose-state"
|
|
14
3
|
export * from "./find-state"
|
|
@@ -22,175 +11,11 @@ export * from "./set-state"
|
|
|
22
11
|
export * from "./silo"
|
|
23
12
|
export * from "./subscribe"
|
|
24
13
|
export * from "./timeline"
|
|
14
|
+
export type * from "./tokens"
|
|
25
15
|
export * from "./transaction"
|
|
26
16
|
export * from "./validators"
|
|
27
17
|
|
|
28
18
|
/**
|
|
29
|
-
* @public
|
|
30
|
-
* A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
|
|
31
|
-
*
|
|
32
|
-
* While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
|
|
33
|
-
*
|
|
34
|
-
* Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
|
|
35
|
-
*
|
|
36
|
-
* Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
|
|
37
|
-
*
|
|
38
|
-
* Tokens are fully serializable, so they can be passed between processes.
|
|
39
|
-
*/
|
|
40
|
-
export type AtomIOToken =
|
|
41
|
-
| ReadableFamilyToken<any, any>
|
|
42
|
-
| ReadableToken<any>
|
|
43
|
-
| TimelineToken<any>
|
|
44
|
-
| TransactionToken<any>
|
|
45
|
-
|
|
46
|
-
/** @public */
|
|
47
|
-
export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
48
|
-
/** The unique identifier of the atom. */
|
|
49
|
-
key: string
|
|
50
|
-
/** Discriminator. */
|
|
51
|
-
type: `atom`
|
|
52
|
-
/** Present if the atom belongs to a family. */
|
|
53
|
-
family?: FamilyMetadata<K>
|
|
54
|
-
/** Never present. This is a marker that preserves the type of the atom's value. */
|
|
55
|
-
__T?: T
|
|
56
|
-
}
|
|
57
|
-
/** @public */
|
|
58
|
-
export type MutableAtomToken<
|
|
59
|
-
T extends Transceiver<any>,
|
|
60
|
-
J extends Json.Serializable,
|
|
61
|
-
K extends Canonical = any,
|
|
62
|
-
> = {
|
|
63
|
-
/** The unique identifier of the atom. */
|
|
64
|
-
key: string
|
|
65
|
-
/** Discriminator. */
|
|
66
|
-
type: `mutable_atom`
|
|
67
|
-
/** Present if the atom belongs to a family. */
|
|
68
|
-
family?: FamilyMetadata<K>
|
|
69
|
-
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
70
|
-
__J?: J
|
|
71
|
-
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
72
|
-
__U?: T extends Transceiver<infer Update> ? Update : never
|
|
73
|
-
}
|
|
74
|
-
/** @public */
|
|
75
|
-
export type AtomToken<T, K extends Canonical = any> =
|
|
76
|
-
| MutableAtomToken<T extends Transceiver<any> ? T : never, any, K>
|
|
77
|
-
| RegularAtomToken<T, K>
|
|
78
|
-
|
|
79
|
-
/** @public */
|
|
80
|
-
export type WritablePureSelectorToken<T, K extends Canonical = any> = {
|
|
81
|
-
/** The unique identifier of the selector. */
|
|
82
|
-
key: string
|
|
83
|
-
/** Discriminator. */
|
|
84
|
-
type: `writable_pure_selector`
|
|
85
|
-
/** Present if the selector belongs to a family. */
|
|
86
|
-
family?: FamilyMetadata<K>
|
|
87
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
88
|
-
__T?: T
|
|
89
|
-
}
|
|
90
|
-
/** @public */
|
|
91
|
-
export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
|
|
92
|
-
/** The unique identifier of the selector. */
|
|
93
|
-
key: string
|
|
94
|
-
/** Discriminator. */
|
|
95
|
-
type: `writable_held_selector`
|
|
96
|
-
/** Present if the selector belongs to a family. */
|
|
97
|
-
family?: FamilyMetadata<K>
|
|
98
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
99
|
-
__T?: T
|
|
100
|
-
}
|
|
101
|
-
/** @public */
|
|
102
|
-
export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
|
|
103
|
-
/** The unique identifier of the selector. */
|
|
104
|
-
key: string
|
|
105
|
-
/** Discriminator. */
|
|
106
|
-
type: `readonly_pure_selector`
|
|
107
|
-
/** Present if the selector belongs to a family. */
|
|
108
|
-
family?: FamilyMetadata<K>
|
|
109
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
110
|
-
__T?: T
|
|
111
|
-
}
|
|
112
|
-
/** @public */
|
|
113
|
-
export type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
|
|
114
|
-
/** The unique identifier of the selector. */
|
|
115
|
-
key: string
|
|
116
|
-
/** Discriminator. */
|
|
117
|
-
type: `readonly_held_selector`
|
|
118
|
-
/** Present if the selector belongs to a family. */
|
|
119
|
-
family?: FamilyMetadata<K>
|
|
120
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
121
|
-
__T?: T
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** @public */
|
|
125
|
-
export type PureSelectorToken<T, K extends Canonical = any> =
|
|
126
|
-
| ReadonlyPureSelectorToken<T, K>
|
|
127
|
-
| WritablePureSelectorToken<T, K>
|
|
128
|
-
|
|
129
|
-
/** @public */
|
|
130
|
-
export type HeldSelectorToken<T, K extends Canonical = any> =
|
|
131
|
-
| ReadonlyHeldSelectorToken<T, K>
|
|
132
|
-
| WritableHeldSelectorToken<T, K>
|
|
133
|
-
|
|
134
|
-
/** @public */
|
|
135
|
-
export type ReadonlySelectorToken<T, K extends Canonical = any> =
|
|
136
|
-
| ReadonlyHeldSelectorToken<T, K>
|
|
137
|
-
| ReadonlyPureSelectorToken<T, K>
|
|
138
|
-
|
|
139
|
-
/** @public */
|
|
140
|
-
export type WritableSelectorToken<T, K extends Canonical = any> =
|
|
141
|
-
| WritableHeldSelectorToken<T, K>
|
|
142
|
-
| WritablePureSelectorToken<T, K>
|
|
143
|
-
|
|
144
|
-
/** @public */
|
|
145
|
-
export type SelectorToken<T, K extends Canonical = any> =
|
|
146
|
-
| ReadonlyHeldSelectorToken<T, K>
|
|
147
|
-
| ReadonlyPureSelectorToken<T, K>
|
|
148
|
-
| WritableHeldSelectorToken<T, K>
|
|
149
|
-
| WritablePureSelectorToken<T, K>
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @public
|
|
153
|
-
* These states can be set.
|
|
154
|
-
*/
|
|
155
|
-
export type WritableToken<T, K extends Canonical = any> =
|
|
156
|
-
| AtomToken<T, K>
|
|
157
|
-
| WritableSelectorToken<T, K>
|
|
158
|
-
/**
|
|
159
|
-
* @public
|
|
160
|
-
* These states cannot be set.
|
|
161
|
-
*/
|
|
162
|
-
export type ReadableToken<T, K extends Canonical = any> =
|
|
163
|
-
| AtomToken<T, K>
|
|
164
|
-
| SelectorToken<T, K>
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @public
|
|
168
|
-
* States belonging to this family can be set.
|
|
169
|
-
*/
|
|
170
|
-
export type WritableFamilyToken<T, K extends Canonical> =
|
|
171
|
-
| AtomFamilyToken<T, K>
|
|
172
|
-
| WritableSelectorFamilyToken<T, K>
|
|
173
|
-
/**
|
|
174
|
-
* @public
|
|
175
|
-
* States belonging to this family cannot be set.
|
|
176
|
-
*/
|
|
177
|
-
export type ReadableFamilyToken<T, K extends Canonical> =
|
|
178
|
-
| AtomFamilyToken<T, K>
|
|
179
|
-
| SelectorFamilyToken<T, K>
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @public
|
|
183
|
-
* Identifies a state's connection to its family.
|
|
184
|
-
*/
|
|
185
|
-
export type FamilyMetadata<K extends Canonical = any> = {
|
|
186
|
-
/** The family's unique key. */
|
|
187
|
-
key: string
|
|
188
|
-
/** The family member's unique identifier, in the form of a string. */
|
|
189
|
-
subKey: stringified<K>
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* @public
|
|
194
19
|
* Loadable is used to type atoms or selectors that may at some point be initialized to or set to a {@link Promise}.
|
|
195
20
|
*
|
|
196
21
|
* When a Promise is cached as the value of a state in atom.io, that state will be automatically set to the resolved value of the Promise when it is resolved.
|
package/src/main/join.ts
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
import type { Json } from "atom.io/json"
|
|
17
17
|
import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
18
18
|
|
|
19
|
-
/** @public */
|
|
20
19
|
// biome-ignore format: intersection
|
|
21
20
|
export type JoinOptions<
|
|
22
21
|
ASide extends string,
|
|
@@ -40,7 +39,6 @@ export type JoinOptions<
|
|
|
40
39
|
}
|
|
41
40
|
> & Partial<JunctionEntriesBase<AType, BType, Content>>
|
|
42
41
|
|
|
43
|
-
/** @public */
|
|
44
42
|
export type JoinToken<
|
|
45
43
|
ASide extends string,
|
|
46
44
|
AType extends string,
|
|
@@ -68,7 +66,6 @@ export type JoinToken<
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
/**
|
|
71
|
-
* @public
|
|
72
69
|
* Create a join, an interface for managing relations between two sets of keys.
|
|
73
70
|
*
|
|
74
71
|
* Use joins when it is important to view relationships from either side.
|
|
@@ -92,7 +89,6 @@ export function join<
|
|
|
92
89
|
defaultContent?: undefined,
|
|
93
90
|
): JoinToken<ASide, AType, BSide, BType, Cardinality, null>
|
|
94
91
|
/**
|
|
95
|
-
* @public
|
|
96
92
|
* Create a join, an interface for managing relations between two sets of keys.
|
|
97
93
|
*
|
|
98
94
|
* Use joins when it is important to view relationships from either side.
|
|
@@ -212,7 +208,6 @@ export type JoinStates<
|
|
|
212
208
|
: never
|
|
213
209
|
|
|
214
210
|
/**
|
|
215
|
-
* @public
|
|
216
211
|
* Find the current value of a relation owned by a {@link join}
|
|
217
212
|
* @param token - The token of the join
|
|
218
213
|
* @param key - The key of the relation to find
|
|
@@ -235,7 +230,6 @@ export function findRelations<
|
|
|
235
230
|
}
|
|
236
231
|
|
|
237
232
|
/**
|
|
238
|
-
* @public
|
|
239
233
|
* Change one or multiple relations owned by a {@link join}
|
|
240
234
|
* @param token - The token of the join
|
|
241
235
|
* @param change - A function that takes a {@link Junction} interface to edit the relations
|
|
@@ -255,7 +249,6 @@ export function editRelations<
|
|
|
255
249
|
}
|
|
256
250
|
|
|
257
251
|
/**
|
|
258
|
-
* @public
|
|
259
252
|
* @param token - The token of the join
|
|
260
253
|
* @returns
|
|
261
254
|
* A {@link MutableAtomFamilyToken} to access the internal relations
|
package/src/main/reset-state.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { Canonical } from "atom.io/json"
|
|
|
4
4
|
import type { WritableFamilyToken, WritableToken } from "."
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @public
|
|
8
7
|
* Set the value of a state into the implicit store back to its default value.
|
|
9
8
|
* @param token - An atom or writable selector token.
|
|
10
9
|
* @overload Default
|
|
@@ -12,7 +11,6 @@ import type { WritableFamilyToken, WritableToken } from "."
|
|
|
12
11
|
*/
|
|
13
12
|
export function resetState(token: WritableToken<any>): void
|
|
14
13
|
/**
|
|
15
|
-
* @public
|
|
16
14
|
* Set the value of a state into the implicit store back to its default value.
|
|
17
15
|
* @param token - An atom family or writable selector family token.
|
|
18
16
|
* @param key - The unique key of the state to set.
|
package/src/main/selector.ts
CHANGED
|
@@ -6,11 +6,15 @@ import {
|
|
|
6
6
|
import type { Canonical } from "atom.io/json"
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
|
+
ReadonlyHeldSelectorFamilyToken,
|
|
9
10
|
ReadonlyHeldSelectorToken,
|
|
11
|
+
ReadonlyPureSelectorFamilyToken,
|
|
10
12
|
ReadonlyPureSelectorToken,
|
|
13
|
+
WritableHeldSelectorFamilyToken,
|
|
11
14
|
WritableHeldSelectorToken,
|
|
15
|
+
WritablePureSelectorFamilyToken,
|
|
12
16
|
WritablePureSelectorToken,
|
|
13
|
-
} from "
|
|
17
|
+
} from "./tokens"
|
|
14
18
|
import type { Read, Write } from "./transaction"
|
|
15
19
|
|
|
16
20
|
export type WritablePureSelectorOptions<T> = {
|
|
@@ -47,7 +51,6 @@ export type WritableHeldSelectorOptions<T extends object> = {
|
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
/**
|
|
50
|
-
* @public
|
|
51
54
|
* Declare a selector. The value of a selector should depend
|
|
52
55
|
* on the value of atoms or other selectors in the store, and
|
|
53
56
|
* should be recycled when a root atom of the selector is set.
|
|
@@ -68,7 +71,6 @@ export function selector<T extends object>(
|
|
|
68
71
|
options: WritableHeldSelectorOptions<T>,
|
|
69
72
|
): WritableHeldSelectorToken<T>
|
|
70
73
|
/**
|
|
71
|
-
* @public
|
|
72
74
|
* Declare a selector. The value of a selector should depend
|
|
73
75
|
* on the value of atoms or other selectors in the store,
|
|
74
76
|
* and should be recycled when a root atom of the selector is set.
|
|
@@ -87,7 +89,6 @@ export function selector<T extends object>(
|
|
|
87
89
|
options: ReadonlyHeldSelectorOptions<T>,
|
|
88
90
|
): ReadonlyHeldSelectorToken<T>
|
|
89
91
|
/**
|
|
90
|
-
* @public
|
|
91
92
|
* Declare a selector. The value of a selector should depend
|
|
92
93
|
* on the value of atoms or other selectors in the store.
|
|
93
94
|
*
|
|
@@ -107,7 +108,6 @@ export function selector<T>(
|
|
|
107
108
|
options: WritablePureSelectorOptions<T>,
|
|
108
109
|
): WritablePureSelectorToken<T>
|
|
109
110
|
/**
|
|
110
|
-
* @public
|
|
111
111
|
* Declare a selector. The value of a selector should depend
|
|
112
112
|
* on the value of atoms or other selectors in the store.
|
|
113
113
|
*
|
|
@@ -138,7 +138,6 @@ export function selector(
|
|
|
138
138
|
return createStandaloneSelector(IMPLICIT.STORE, options)
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
/** @public */
|
|
142
141
|
export type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
143
142
|
/** The unique identifier of the family */
|
|
144
143
|
key: string
|
|
@@ -147,14 +146,12 @@ export type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
|
147
146
|
/** For each instantiated family member, a function that sets its value */
|
|
148
147
|
set: (key: K) => Write<(newValue: T) => void>
|
|
149
148
|
}
|
|
150
|
-
/** @public */
|
|
151
149
|
export type ReadonlyPureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
152
150
|
/** The unique identifier of the family */
|
|
153
151
|
key: string
|
|
154
152
|
/** For each instantiated family member, a function that computes its value */
|
|
155
153
|
get: (key: K) => Read<() => T>
|
|
156
154
|
}
|
|
157
|
-
/** @public */
|
|
158
155
|
export type WritableHeldSelectorFamilyOptions<
|
|
159
156
|
T extends object,
|
|
160
157
|
K extends Canonical,
|
|
@@ -168,7 +165,6 @@ export type WritableHeldSelectorFamilyOptions<
|
|
|
168
165
|
/** For each instantiated family member, a function that sets its value */
|
|
169
166
|
set: (key: K) => Write<(newValue: T) => void>
|
|
170
167
|
}
|
|
171
|
-
/** @public */
|
|
172
168
|
export type ReadonlyHeldSelectorFamilyOptions<
|
|
173
169
|
T extends object,
|
|
174
170
|
K extends Canonical,
|
|
@@ -181,67 +177,7 @@ export type ReadonlyHeldSelectorFamilyOptions<
|
|
|
181
177
|
get: (key: K) => Read<(permanent: T) => void>
|
|
182
178
|
}
|
|
183
179
|
|
|
184
|
-
export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
|
|
185
|
-
/** The unique identifier of the family */
|
|
186
|
-
key: string
|
|
187
|
-
/** Discriminator */
|
|
188
|
-
type: `writable_pure_selector_family`
|
|
189
|
-
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
190
|
-
__T?: T
|
|
191
|
-
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
192
|
-
__K?: K
|
|
193
|
-
}
|
|
194
|
-
export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
|
|
195
|
-
/** The unique identifier of the family */
|
|
196
|
-
key: string
|
|
197
|
-
/** Discriminator */
|
|
198
|
-
type: `readonly_pure_selector_family`
|
|
199
|
-
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
200
|
-
__T?: T
|
|
201
|
-
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
202
|
-
__K?: K
|
|
203
|
-
}
|
|
204
|
-
export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
205
|
-
/** The unique identifier of the family */
|
|
206
|
-
key: string
|
|
207
|
-
/** Discriminator */
|
|
208
|
-
type: `writable_held_selector_family`
|
|
209
|
-
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
210
|
-
__T?: T
|
|
211
|
-
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
212
|
-
__K?: K
|
|
213
|
-
}
|
|
214
|
-
export type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
215
|
-
/** The unique identifier of the family */
|
|
216
|
-
key: string
|
|
217
|
-
/** Discriminator */
|
|
218
|
-
type: `readonly_held_selector_family`
|
|
219
|
-
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
220
|
-
__T?: T
|
|
221
|
-
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
222
|
-
__K?: K
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export type PureSelectorFamilyToken<T, K extends Canonical> =
|
|
226
|
-
| ReadonlyPureSelectorFamilyToken<T, K>
|
|
227
|
-
| WritablePureSelectorFamilyToken<T, K>
|
|
228
|
-
export type HeldSelectorFamilyToken<T, K extends Canonical> =
|
|
229
|
-
| ReadonlyHeldSelectorFamilyToken<T, K>
|
|
230
|
-
| WritableHeldSelectorFamilyToken<T, K>
|
|
231
|
-
export type ReadonlySelectorFamilyToken<T, K extends Canonical> =
|
|
232
|
-
| ReadonlyHeldSelectorFamilyToken<T, K>
|
|
233
|
-
| ReadonlyPureSelectorFamilyToken<T, K>
|
|
234
|
-
|
|
235
|
-
export type WritableSelectorFamilyToken<T, K extends Canonical> =
|
|
236
|
-
| WritableHeldSelectorFamilyToken<T, K>
|
|
237
|
-
| WritablePureSelectorFamilyToken<T, K>
|
|
238
|
-
|
|
239
|
-
export type SelectorFamilyToken<T, K extends Canonical> =
|
|
240
|
-
| HeldSelectorFamilyToken<T, K>
|
|
241
|
-
| PureSelectorFamilyToken<T, K>
|
|
242
|
-
|
|
243
180
|
/**
|
|
244
|
-
* @public
|
|
245
181
|
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
246
182
|
*
|
|
247
183
|
* The value of a held selector should depend on the value of atoms or other selectors in the store,
|
|
@@ -263,7 +199,6 @@ export function selectorFamily<T extends object, K extends Canonical>(
|
|
|
263
199
|
options: WritableHeldSelectorFamilyOptions<T, K>,
|
|
264
200
|
): WritableHeldSelectorFamilyToken<T, K>
|
|
265
201
|
/**
|
|
266
|
-
* @public
|
|
267
202
|
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
268
203
|
*
|
|
269
204
|
* The value of a held selector should depend on the value of atoms or other selectors in the store,
|
|
@@ -283,7 +218,6 @@ export function selectorFamily<T extends object, K extends Canonical>(
|
|
|
283
218
|
options: ReadonlyHeldSelectorFamilyOptions<T, K>,
|
|
284
219
|
): ReadonlyHeldSelectorFamilyToken<T, K>
|
|
285
220
|
/**
|
|
286
|
-
* @public
|
|
287
221
|
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
288
222
|
*
|
|
289
223
|
* The value of a selector should depend on the value of atoms or other selectors in the store.
|
|
@@ -304,7 +238,6 @@ export function selectorFamily<T, K extends Canonical>(
|
|
|
304
238
|
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
305
239
|
): WritablePureSelectorFamilyToken<T, K>
|
|
306
240
|
/**
|
|
307
|
-
* @public
|
|
308
241
|
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
309
242
|
*
|
|
310
243
|
* The value of a selector should depend on the value of atoms or other selectors in the store.
|
package/src/main/set-state.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type { WritableFamilyToken, WritableToken } from "
|
|
4
|
+
import type { WritableFamilyToken, WritableToken } from "./tokens"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @public
|
|
8
7
|
* A function that sets the value of a state.
|
|
9
8
|
* @param oldValue - The current value of the state.
|
|
10
9
|
* @returns
|
|
@@ -13,7 +12,6 @@ import type { WritableFamilyToken, WritableToken } from "."
|
|
|
13
12
|
export type Setter<T, New extends T> = (oldValue: T) => New
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
|
-
* @public
|
|
17
15
|
* Set the value of a state into the implicit store.
|
|
18
16
|
* @param token - An atom or writable selector token.
|
|
19
17
|
* @param value - The new value of the state.
|
|
@@ -26,7 +24,6 @@ export function setState<T, New extends T>(
|
|
|
26
24
|
): void
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
|
-
* @public
|
|
30
27
|
* Set the value of a state into the implicit store.
|
|
31
28
|
* @param token - An atom family or writable selector family token.
|
|
32
29
|
* @param key - The unique key of the state to set.
|
package/src/main/silo.ts
CHANGED
|
@@ -2,9 +2,11 @@ import type { findState } from "atom.io"
|
|
|
2
2
|
import {
|
|
3
3
|
actUponStore,
|
|
4
4
|
arbitrary,
|
|
5
|
-
|
|
5
|
+
createMutableAtom,
|
|
6
|
+
createMutableAtomFamily,
|
|
7
|
+
createRegularAtom,
|
|
8
|
+
createRegularAtomFamily,
|
|
6
9
|
createSelectorFamily,
|
|
7
|
-
createStandaloneAtom,
|
|
8
10
|
createStandaloneSelector,
|
|
9
11
|
createTimeline,
|
|
10
12
|
createTransaction,
|
|
@@ -30,7 +32,7 @@ import type {
|
|
|
30
32
|
timeline,
|
|
31
33
|
undo,
|
|
32
34
|
} from "."
|
|
33
|
-
import type { atom, atomFamily } from "./atom"
|
|
35
|
+
import type { atom, atomFamily, mutableAtom, mutableAtomFamily } from "./atom"
|
|
34
36
|
import type { resetState } from "./reset-state"
|
|
35
37
|
import type { selector, selectorFamily } from "./selector"
|
|
36
38
|
import type { runTransaction, transaction } from "./transaction"
|
|
@@ -38,7 +40,9 @@ import type { runTransaction, transaction } from "./transaction"
|
|
|
38
40
|
export class Silo {
|
|
39
41
|
public store: Store
|
|
40
42
|
public atom: typeof atom
|
|
43
|
+
public mutableAtom: typeof mutableAtom
|
|
41
44
|
public atomFamily: typeof atomFamily
|
|
45
|
+
public mutableAtomFamily: typeof mutableAtomFamily
|
|
42
46
|
public selector: typeof selector
|
|
43
47
|
public selectorFamily: typeof selectorFamily
|
|
44
48
|
public transaction: typeof transaction
|
|
@@ -57,9 +61,14 @@ export class Silo {
|
|
|
57
61
|
public constructor(config: Store[`config`], fromStore: Store | null = null) {
|
|
58
62
|
const s = (this.store = new Store(config, fromStore))
|
|
59
63
|
this.atom = ((options: Parameters<typeof atom>[0]) =>
|
|
60
|
-
|
|
64
|
+
createRegularAtom(s, options, undefined)) as typeof atom
|
|
65
|
+
this.mutableAtom = ((options: Parameters<typeof mutableAtom>[0]) =>
|
|
66
|
+
createMutableAtom(s, options, undefined)) as typeof mutableAtom
|
|
61
67
|
this.atomFamily = ((options: Parameters<typeof atomFamily>[0]) =>
|
|
62
|
-
|
|
68
|
+
createRegularAtomFamily(s, options)) as typeof atomFamily
|
|
69
|
+
this.mutableAtomFamily = ((
|
|
70
|
+
options: Parameters<typeof mutableAtomFamily>[0],
|
|
71
|
+
) => createMutableAtomFamily(s, options)) as typeof mutableAtomFamily
|
|
63
72
|
this.selector = ((options: Parameters<typeof selector>[0]) =>
|
|
64
73
|
createStandaloneSelector(s, options)) as typeof selector
|
|
65
74
|
this.selectorFamily = ((options: Parameters<typeof selectorFamily>[0]) =>
|
package/src/main/subscribe.ts
CHANGED
|
@@ -11,9 +11,7 @@ import type {
|
|
|
11
11
|
TransactionUpdate,
|
|
12
12
|
} from "."
|
|
13
13
|
|
|
14
|
-
/** @public */
|
|
15
14
|
export type StateUpdate<T> = { newValue: T; oldValue: T }
|
|
16
|
-
/** @public */
|
|
17
15
|
export type KeyedStateUpdate<T> = Flat<
|
|
18
16
|
StateUpdate<T> & {
|
|
19
17
|
key: string
|
|
@@ -21,15 +19,12 @@ export type KeyedStateUpdate<T> = Flat<
|
|
|
21
19
|
family?: FamilyMetadata
|
|
22
20
|
}
|
|
23
21
|
>
|
|
24
|
-
/** @public */
|
|
25
22
|
export type UpdateHandler<T> = (update: StateUpdate<T>) => void
|
|
26
|
-
/** @public */
|
|
27
23
|
export type TransactionUpdateHandler<F extends Func> = (
|
|
28
24
|
data: TransactionUpdate<F>,
|
|
29
25
|
) => void
|
|
30
26
|
|
|
31
27
|
/**
|
|
32
|
-
* @public
|
|
33
28
|
* Subscribe to a state in the implicit store
|
|
34
29
|
* @param token - The token of the state to subscribe to
|
|
35
30
|
* @param handleUpdate - A function that will be called when the state is updated
|
|
@@ -43,7 +38,6 @@ export function subscribe<T>(
|
|
|
43
38
|
key?: string,
|
|
44
39
|
): () => void
|
|
45
40
|
/**
|
|
46
|
-
* @public
|
|
47
41
|
* Subscribe to a transaction in the implicit store
|
|
48
42
|
* @param token - The token of the transaction to subscribe to
|
|
49
43
|
* @param handleUpdate - A function that will be called when the transaction succeeds
|
|
@@ -57,7 +51,6 @@ export function subscribe<F extends Func>(
|
|
|
57
51
|
key?: string,
|
|
58
52
|
): () => void
|
|
59
53
|
/**
|
|
60
|
-
* @public
|
|
61
54
|
* Subscribe to a timeline in the implicit store
|
|
62
55
|
* @param token - The token of the timeline to subscribe to
|
|
63
56
|
* @param handleUpdate - A function that will be called when a new update is available
|