atom.io 0.34.1 → 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 +19 -7
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +4 -0
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +704 -788
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +61 -33
- 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 +12 -12
- 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 +10 -3
- package/src/json/index.ts +40 -17
- package/src/main/atom.ts +68 -115
- 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 +12 -20
- 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 +24 -32
- 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/dist/main/index.d.ts
CHANGED
|
@@ -1,85 +1,132 @@
|
|
|
1
1
|
import { Each, EnvironmentData, Flat, Func, Junction, JunctionEntriesBase, JunctionSchemaBase, Refinement, Store, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate, Transceiver } from "atom.io/internal";
|
|
2
2
|
import { Canonical, Json, JsonInterface, stringified } from "atom.io/json";
|
|
3
|
-
import { MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1,
|
|
3
|
+
import { MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, ReadonlyPureSelectorToken as ReadonlyPureSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, RegularAtomToken as RegularAtomToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, WritableToken as WritableToken$1, findState as findState$1 } from "atom.io";
|
|
4
4
|
import { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx";
|
|
5
5
|
|
|
6
|
-
//#region src/main/
|
|
6
|
+
//#region src/main/tokens.d.ts
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* Create a mutable atom, a global reactive variable in the implicit store
|
|
9
|
+
* A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
11
|
+
* While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
|
|
13
12
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
|
|
14
|
+
*
|
|
15
|
+
* Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
|
|
16
|
+
*
|
|
17
|
+
* Tokens are fully serializable, so they can be passed between processes.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
type AtomIOToken = ReadableFamilyToken<any, any> | ReadableToken<any> | TimelineToken<any> | TransactionToken<any>;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* Create a regular atom, a global reactive variable in the implicit store
|
|
23
|
-
* @param options - {@link RegularAtomOptions}.
|
|
24
|
-
* @returns
|
|
25
|
-
* A reference to the atom created: a {@link RegularAtomToken}
|
|
26
|
-
* @overload Regular
|
|
21
|
+
* These states cannot be set.
|
|
27
22
|
*/
|
|
28
|
-
|
|
29
|
-
/** @public */
|
|
30
|
-
type Effectors<T> = {
|
|
31
|
-
/**
|
|
32
|
-
* Reset the value of the atom to its default
|
|
33
|
-
*/
|
|
34
|
-
resetSelf: () => void;
|
|
35
|
-
/**
|
|
36
|
-
* Set the value of the atom
|
|
37
|
-
* @param next - The new value of the atom, or a setter function
|
|
38
|
-
*/
|
|
39
|
-
setSelf: <New extends T>(next: New | Setter<T, New>) => void;
|
|
40
|
-
/** Subscribe to changes to the atom */
|
|
41
|
-
onSet: (callback: (options: {
|
|
42
|
-
newValue: T;
|
|
43
|
-
oldValue: T;
|
|
44
|
-
}) => void) => void;
|
|
45
|
-
};
|
|
23
|
+
type ReadableToken<T, K extends Canonical = any> = AtomToken<T, K> | SelectorToken<T, K>;
|
|
46
24
|
/**
|
|
47
|
-
*
|
|
48
|
-
* A function that runs side effects when the atom is set
|
|
49
|
-
* @param tools - {@link Effectors} that can be used to run side effects
|
|
50
|
-
* @returns
|
|
51
|
-
* Optionally, a cleanup function that will be called when the atom is disposed
|
|
25
|
+
* These states can be set.
|
|
52
26
|
*/
|
|
53
|
-
type
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
27
|
+
type WritableToken<T, K extends Canonical = any> = AtomToken<T, K> | WritableSelectorToken<T, K>;
|
|
28
|
+
/**
|
|
29
|
+
* States belonging to this family can be gotten from the store.
|
|
30
|
+
*/
|
|
31
|
+
type ReadableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
|
|
32
|
+
/**
|
|
33
|
+
* States belonging to this family can be set.
|
|
34
|
+
*/
|
|
35
|
+
type WritableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
|
|
36
|
+
type TimelineToken<M> = {
|
|
37
|
+
/** The unique identifier of the timeline */
|
|
57
38
|
key: string;
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
|
|
39
|
+
/** Discriminator */
|
|
40
|
+
type: `timeline`;
|
|
41
|
+
/** Never present. This is a marker that preserves the type of the managed atoms */
|
|
42
|
+
__M?: M;
|
|
62
43
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/** Used to signal that the atom is mutable */
|
|
66
|
-
mutable: true;
|
|
67
|
-
/** The unique identifier of the atom */
|
|
44
|
+
type TransactionToken<F extends Func> = {
|
|
45
|
+
/** The unique identifier of the transaction */
|
|
68
46
|
key: string;
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
|
|
47
|
+
/** Discriminator */
|
|
48
|
+
type: `transaction`;
|
|
49
|
+
/** Never present. This is a marker that preserves the type of the transaction function */
|
|
50
|
+
__F?: F;
|
|
73
51
|
};
|
|
74
|
-
|
|
75
|
-
type
|
|
76
|
-
/** The unique identifier of the atom
|
|
52
|
+
type AtomToken<T, K extends Canonical = any> = MutableAtomToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomToken<T, K>;
|
|
53
|
+
type RegularAtomToken<T, K extends Canonical = any> = {
|
|
54
|
+
/** The unique identifier of the atom. */
|
|
77
55
|
key: string;
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
|
|
56
|
+
/** Discriminator. */
|
|
57
|
+
type: `atom`;
|
|
58
|
+
/** Present if the atom belongs to a family. */
|
|
59
|
+
family?: FamilyMetadata<K>;
|
|
60
|
+
/** Never present. This is a marker that preserves the type of the atom's value. */
|
|
61
|
+
__T?: T;
|
|
62
|
+
};
|
|
63
|
+
type MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical = any> = {
|
|
64
|
+
/** The unique identifier of the atom. */
|
|
65
|
+
key: string;
|
|
66
|
+
/** Discriminator. */
|
|
67
|
+
type: `mutable_atom`;
|
|
68
|
+
/** Present if the atom belongs to a family. */
|
|
69
|
+
family?: FamilyMetadata<K>;
|
|
70
|
+
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
71
|
+
__J?: J;
|
|
72
|
+
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
73
|
+
__U?: T extends Transceiver<infer Update> ? Update : never;
|
|
74
|
+
};
|
|
75
|
+
type SelectorToken<T, K extends Canonical = any> = ReadonlySelectorToken<T, K> | WritableSelectorToken<T, K>;
|
|
76
|
+
type ReadonlySelectorToken<T, K extends Canonical = any> = ReadonlyHeldSelectorToken<T, K> | ReadonlyPureSelectorToken<T, K>;
|
|
77
|
+
type WritableSelectorToken<T, K extends Canonical = any> = WritableHeldSelectorToken<T, K> | WritablePureSelectorToken<T, K>;
|
|
78
|
+
type PureSelectorToken<T, K extends Canonical = any> = ReadonlyPureSelectorToken<T, K> | WritablePureSelectorToken<T, K>;
|
|
79
|
+
type HeldSelectorToken<T, K extends Canonical = any> = ReadonlyHeldSelectorToken<T, K> | WritableHeldSelectorToken<T, K>;
|
|
80
|
+
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
|
+
type WritableHeldSelectorToken<T, K extends Canonical = any> = {
|
|
91
|
+
/** The unique identifier of the selector. */
|
|
92
|
+
key: string;
|
|
93
|
+
/** Discriminator. */
|
|
94
|
+
type: `writable_held_selector`;
|
|
95
|
+
/** Present if the selector belongs to a family. */
|
|
96
|
+
family?: FamilyMetadata<K>;
|
|
97
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
98
|
+
__T?: T;
|
|
99
|
+
};
|
|
100
|
+
type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
|
|
101
|
+
/** The unique identifier of the selector. */
|
|
102
|
+
key: string;
|
|
103
|
+
/** Discriminator. */
|
|
104
|
+
type: `readonly_pure_selector`;
|
|
105
|
+
/** Present if the selector belongs to a family. */
|
|
106
|
+
family?: FamilyMetadata<K>;
|
|
107
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
108
|
+
__T?: T;
|
|
109
|
+
};
|
|
110
|
+
type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
|
|
111
|
+
/** The unique identifier of the selector. */
|
|
112
|
+
key: string;
|
|
113
|
+
/** Discriminator. */
|
|
114
|
+
type: `readonly_held_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
|
+
/**
|
|
121
|
+
* Identifies a state's connection to its family.
|
|
122
|
+
*/
|
|
123
|
+
type FamilyMetadata<K extends Canonical = any> = {
|
|
124
|
+
/** The family's unique key. */
|
|
125
|
+
key: string;
|
|
126
|
+
/** The family member's unique identifier, in the form of a string. */
|
|
127
|
+
subKey: stringified<K>;
|
|
82
128
|
};
|
|
129
|
+
type AtomFamilyToken<T, K extends Canonical = Canonical> = MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomFamilyToken<T, K>;
|
|
83
130
|
type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
84
131
|
/** The unique identifier of the atom family */
|
|
85
132
|
key: string;
|
|
@@ -90,17 +137,6 @@ type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
|
90
137
|
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
91
138
|
__K?: K;
|
|
92
139
|
};
|
|
93
|
-
/** @public */
|
|
94
|
-
type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = JsonInterface<T, J> & {
|
|
95
|
-
/** Used to signal that the atoms created from this family are mutable */
|
|
96
|
-
mutable: true;
|
|
97
|
-
/** The unique identifier of the atom family */
|
|
98
|
-
key: string;
|
|
99
|
-
/** A function to create an initial value for each atom in the family */
|
|
100
|
-
default: (key: K) => T;
|
|
101
|
-
/** Hooks used to run side effects when an atom in the family is set */
|
|
102
|
-
effects?: (key: K) => AtomEffect<T>[];
|
|
103
|
-
};
|
|
104
140
|
type MutableAtomFamilyToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = {
|
|
105
141
|
/** The unique identifier of the atom family */
|
|
106
142
|
key: string;
|
|
@@ -113,539 +149,246 @@ type MutableAtomFamilyToken<T extends Transceiver<any>, J extends Json.Serializa
|
|
|
113
149
|
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
114
150
|
__K?: K;
|
|
115
151
|
};
|
|
116
|
-
type
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
152
|
+
type SelectorFamilyToken<T, K extends Canonical> = ReadonlySelectorFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
|
|
153
|
+
type ReadonlySelectorFamilyToken<T, K extends Canonical> = ReadonlyHeldSelectorFamilyToken<T, K> | ReadonlyPureSelectorFamilyToken<T, K>;
|
|
154
|
+
type WritableSelectorFamilyToken<T, K extends Canonical> = WritableHeldSelectorFamilyToken<T, K> | WritablePureSelectorFamilyToken<T, K>;
|
|
155
|
+
type PureSelectorFamilyToken<T, K extends Canonical> = ReadonlyPureSelectorFamilyToken<T, K> | WritablePureSelectorFamilyToken<T, K>;
|
|
156
|
+
type HeldSelectorFamilyToken<T, K extends Canonical> = ReadonlyHeldSelectorFamilyToken<T, K> | WritableHeldSelectorFamilyToken<T, K>;
|
|
157
|
+
type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
|
|
158
|
+
/** The unique identifier of the family */
|
|
159
|
+
key: string;
|
|
160
|
+
/** Discriminator */
|
|
161
|
+
type: `writable_pure_selector_family`;
|
|
162
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
163
|
+
__T?: T;
|
|
164
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
165
|
+
__K?: K;
|
|
166
|
+
};
|
|
167
|
+
type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
|
|
168
|
+
/** The unique identifier of the family */
|
|
169
|
+
key: string;
|
|
170
|
+
/** Discriminator */
|
|
171
|
+
type: `readonly_pure_selector_family`;
|
|
172
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
173
|
+
__T?: T;
|
|
174
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
175
|
+
__K?: K;
|
|
176
|
+
};
|
|
177
|
+
type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
178
|
+
/** The unique identifier of the family */
|
|
179
|
+
key: string;
|
|
180
|
+
/** Discriminator */
|
|
181
|
+
type: `writable_held_selector_family`;
|
|
182
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
183
|
+
__T?: T;
|
|
184
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
185
|
+
__K?: K;
|
|
186
|
+
};
|
|
187
|
+
type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
188
|
+
/** The unique identifier of the family */
|
|
189
|
+
key: string;
|
|
190
|
+
/** Discriminator */
|
|
191
|
+
type: `readonly_held_selector_family`;
|
|
192
|
+
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
193
|
+
__T?: T;
|
|
194
|
+
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
195
|
+
__K?: K;
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/main/set-state.d.ts
|
|
129
199
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @param options - {@link RegularAtomFamilyOptions}
|
|
200
|
+
* A function that sets the value of a state.
|
|
201
|
+
* @param oldValue - The current value of the state.
|
|
133
202
|
* @returns
|
|
134
|
-
*
|
|
135
|
-
* @overload Regular
|
|
203
|
+
* The new value of the state.
|
|
136
204
|
*/
|
|
137
|
-
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/main/reset-state.d.ts
|
|
205
|
+
type Setter<T, New extends T> = (oldValue: T) => New;
|
|
140
206
|
/**
|
|
141
|
-
*
|
|
142
|
-
* Set the value of a state into the implicit store back to its default value.
|
|
207
|
+
* Set the value of a state into the implicit store.
|
|
143
208
|
* @param token - An atom or writable selector token.
|
|
209
|
+
* @param value - The new value of the state.
|
|
144
210
|
* @overload Default
|
|
145
211
|
* @default
|
|
146
212
|
*/
|
|
147
|
-
declare function
|
|
213
|
+
declare function setState<T, New extends T>(token: WritableToken<T>, value: New | Setter<T, New>): void;
|
|
148
214
|
/**
|
|
149
|
-
*
|
|
150
|
-
* Set the value of a state into the implicit store back to its default value.
|
|
215
|
+
* Set the value of a state into the implicit store.
|
|
151
216
|
* @param token - An atom family or writable selector family token.
|
|
152
217
|
* @param key - The unique key of the state to set.
|
|
218
|
+
* @param value - The new value of the state.
|
|
153
219
|
* @overload Streamlined
|
|
154
220
|
*/
|
|
155
|
-
declare function
|
|
221
|
+
declare function setState<T, K extends Canonical, New extends T, Key extends K>(token: WritableFamilyToken<T, K>, key: Key, value: New | Setter<T, New>): void;
|
|
156
222
|
//#endregion
|
|
157
|
-
//#region src/main/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
/** The unique identifier of the transaction */
|
|
223
|
+
//#region src/main/atom.d.ts
|
|
224
|
+
type RegularAtomOptions<T> = {
|
|
225
|
+
/** The unique identifier of the atom */
|
|
161
226
|
key: string;
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
|
|
227
|
+
/** The starting value of the atom */
|
|
228
|
+
default: T | (() => T);
|
|
229
|
+
/** Hooks used to run side effects when the atom is set */
|
|
230
|
+
effects?: AtomEffect<T>[];
|
|
166
231
|
};
|
|
167
|
-
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
token: Token;
|
|
177
|
-
value: TokenType<Token>;
|
|
178
|
-
};
|
|
179
|
-
/** @public */
|
|
180
|
-
type SelectorDisposal<Token extends ReadableToken<any>> = {
|
|
181
|
-
type: `state_disposal`;
|
|
182
|
-
subType: `selector`;
|
|
183
|
-
token: Token;
|
|
184
|
-
};
|
|
185
|
-
/** @public */
|
|
186
|
-
type StateDisposal<Token extends ReadableToken<any>> = AtomDisposal<Token> | SelectorDisposal<Token>;
|
|
187
|
-
/** @public */
|
|
188
|
-
type MoleculeCreation = {
|
|
189
|
-
type: `molecule_creation`;
|
|
190
|
-
key: Canonical;
|
|
191
|
-
provenance: Canonical;
|
|
192
|
-
};
|
|
193
|
-
/** @public */
|
|
194
|
-
type MoleculeDisposal = {
|
|
195
|
-
type: `molecule_disposal`;
|
|
196
|
-
key: Canonical;
|
|
197
|
-
provenance: stringified<Canonical>[];
|
|
198
|
-
values: [key: string, value: any][];
|
|
199
|
-
};
|
|
200
|
-
/** @public */
|
|
201
|
-
type MoleculeTransfer = {
|
|
202
|
-
type: `molecule_transfer`;
|
|
203
|
-
key: Canonical;
|
|
204
|
-
from: Canonical[];
|
|
205
|
-
to: Canonical[];
|
|
206
|
-
};
|
|
207
|
-
/** @public */
|
|
208
|
-
type TransactionUpdateContent = KeyedStateUpdate<unknown> | MoleculeCreation | MoleculeDisposal | MoleculeTransfer | StateCreation<ReadableToken<unknown>> | StateDisposal<ReadableToken<unknown>> | TransactionUpdate<Func>;
|
|
209
|
-
/** @public */
|
|
210
|
-
type TransactionUpdate<F extends Func> = {
|
|
211
|
-
type: `transaction_update`;
|
|
212
|
-
key: string;
|
|
213
|
-
id: string;
|
|
214
|
-
epoch: number;
|
|
215
|
-
updates: TransactionUpdateContent[];
|
|
216
|
-
params: Parameters<F>;
|
|
217
|
-
output: ReturnType<F>;
|
|
218
|
-
};
|
|
219
|
-
/** @public */
|
|
220
|
-
type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json`>;
|
|
221
|
-
/** @public */
|
|
222
|
-
type SetterToolkit = Readonly<{
|
|
223
|
-
get: typeof getState$1;
|
|
224
|
-
set: typeof setState$1;
|
|
225
|
-
find: typeof findState$1;
|
|
226
|
-
json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritablePureSelectorToken<J>;
|
|
227
|
-
}>;
|
|
228
|
-
/** @public */
|
|
229
|
-
type ActorToolkit = Readonly<{
|
|
230
|
-
get: typeof getState$1;
|
|
231
|
-
set: typeof setState$1;
|
|
232
|
-
reset: typeof resetState;
|
|
233
|
-
find: typeof findState$1;
|
|
234
|
-
json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritablePureSelectorToken<J>;
|
|
235
|
-
dispose: typeof disposeState;
|
|
236
|
-
run: typeof runTransaction;
|
|
237
|
-
env: () => EnvironmentData;
|
|
238
|
-
}>;
|
|
239
|
-
/** @public */
|
|
240
|
-
type Read<F extends Func> = (toolkit: GetterToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
|
|
241
|
-
/** @public */
|
|
242
|
-
type Write<F extends Func> = (toolkit: SetterToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
|
|
243
|
-
/** @public */
|
|
244
|
-
type Transact<F extends Func> = (toolkit: ActorToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
|
|
245
|
-
/** @public */
|
|
246
|
-
type TransactionIO<Token extends TransactionToken<any>> = Token extends TransactionToken<infer F> ? F : never;
|
|
247
|
-
/** @public */
|
|
248
|
-
type TransactionOptions<F extends Func> = {
|
|
249
|
-
/** The unique identifier of the transaction */
|
|
232
|
+
/**
|
|
233
|
+
* Create a regular atom, a global reactive variable in the implicit store
|
|
234
|
+
* @param options - {@link RegularAtomOptions}.
|
|
235
|
+
* @returns
|
|
236
|
+
* A reference to the atom created: a {@link RegularAtomToken}
|
|
237
|
+
*/
|
|
238
|
+
declare function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>;
|
|
239
|
+
type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & {
|
|
240
|
+
/** The unique identifier of the atom */
|
|
250
241
|
key: string;
|
|
251
|
-
/**
|
|
252
|
-
|
|
242
|
+
/** A function to create an initial value for the atom */
|
|
243
|
+
default: () => T;
|
|
244
|
+
/** Hooks used to run side effects when the atom is set */
|
|
245
|
+
effects?: AtomEffect<T>[];
|
|
253
246
|
};
|
|
254
247
|
/**
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
248
|
+
* Create a mutable atom, a global reactive variable in the implicit store
|
|
249
|
+
*
|
|
250
|
+
* The value of a mutable atom must be some kind of {@link Transceiver}.
|
|
251
|
+
*
|
|
252
|
+
* @param options - {@link MutableAtomOptions}.
|
|
253
|
+
* @returns
|
|
254
|
+
* A reference to the atom created: a {@link MutableAtomToken}
|
|
259
255
|
*/
|
|
260
|
-
declare function
|
|
256
|
+
declare function mutableAtom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
|
|
261
257
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* @
|
|
265
|
-
*
|
|
266
|
-
* @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
|
|
258
|
+
* A function that runs side effects when the atom is set
|
|
259
|
+
* @param tools - {@link Effectors} that can be used to run side effects
|
|
260
|
+
* @returns
|
|
261
|
+
* Optionally, a cleanup function that will be called when the atom is disposed
|
|
267
262
|
*/
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
263
|
+
type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void;
|
|
264
|
+
type Effectors<T> = {
|
|
265
|
+
/**
|
|
266
|
+
* Reset the value of the atom to its default
|
|
267
|
+
*/
|
|
268
|
+
resetSelf: () => void;
|
|
269
|
+
/**
|
|
270
|
+
* Set the value of the atom
|
|
271
|
+
* @param next - The new value of the atom, or a setter function
|
|
272
|
+
*/
|
|
273
|
+
setSelf: <New extends T>(next: New | Setter<T, New>) => void;
|
|
274
|
+
/** Subscribe to changes to the atom */
|
|
275
|
+
onSet: (callback: (options: {
|
|
276
|
+
newValue: T;
|
|
277
|
+
oldValue: T;
|
|
278
|
+
}) => void) => void;
|
|
284
279
|
};
|
|
285
|
-
type
|
|
286
|
-
/** The unique identifier of the
|
|
280
|
+
type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
281
|
+
/** The unique identifier of the atom family */
|
|
287
282
|
key: string;
|
|
288
|
-
/**
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
|
|
283
|
+
/** The starting value of the atom family */
|
|
284
|
+
default: T | ((key: K) => T);
|
|
285
|
+
/** Hooks used to run side effects when an atom in the family is set */
|
|
286
|
+
effects?: (key: K) => AtomEffect<T>[];
|
|
292
287
|
};
|
|
293
|
-
|
|
294
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms.
|
|
290
|
+
* @param options - {@link RegularAtomFamilyOptions}
|
|
291
|
+
* @returns
|
|
292
|
+
* A reference to the atom family created: a {@link RegularAtomFamilyToken}
|
|
293
|
+
*/
|
|
294
|
+
declare function atomFamily<T, K extends Canonical>(options: RegularAtomFamilyOptions<T, K>): RegularAtomFamilyToken<T, K>;
|
|
295
|
+
type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = JsonInterface<T, J> & {
|
|
296
|
+
/** The unique identifier of the atom family */
|
|
295
297
|
key: string;
|
|
296
|
-
/**
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
/** For each instantiated selector, a function that sets its value */
|
|
301
|
-
set: Write<(newValue: T) => void>;
|
|
298
|
+
/** A function to create an initial value for each atom in the family */
|
|
299
|
+
default: (key: K) => T;
|
|
300
|
+
/** Hooks used to run side effects when an atom in the family is set */
|
|
301
|
+
effects?: (key: K) => AtomEffect<T>[];
|
|
302
302
|
};
|
|
303
303
|
/**
|
|
304
|
-
*
|
|
305
|
-
* Declare a selector. The value of a selector should depend
|
|
306
|
-
* on the value of atoms or other selectors in the store, and
|
|
307
|
-
* should be recycled when a root atom of the selector is set.
|
|
304
|
+
* Create a family of mutable atoms, allowing for the dynamic creation and disposal of atoms.
|
|
308
305
|
*
|
|
309
|
-
*
|
|
310
|
-
* The reference to that object is permanent and will not be replaced.
|
|
306
|
+
* The value of a mutable atom must be some kind of {@link Transceiver}.
|
|
311
307
|
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
308
|
+
* @param options - {@link MutableAtomFamilyOptions}
|
|
309
|
+
* @returns
|
|
310
|
+
* A reference to the atom family created: a {@link MutableAtomFamilyToken}
|
|
311
|
+
*/
|
|
312
|
+
declare function mutableAtomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamilyToken<T, J, K>;
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/main/dispose-state.d.ts
|
|
315
|
+
/**
|
|
316
|
+
* Disposes of a state in the implicit store.
|
|
315
317
|
*
|
|
316
|
-
*
|
|
318
|
+
* Only family members can be disposed of.
|
|
319
|
+
*
|
|
320
|
+
* @param token - The token of the state to dispose
|
|
321
|
+
* @overload Default
|
|
322
|
+
*/
|
|
323
|
+
declare function disposeState(token: ReadableToken<any>): void;
|
|
324
|
+
/**
|
|
325
|
+
* Disposes of a state in the implicit store.
|
|
326
|
+
*
|
|
327
|
+
* Only family members can be disposed of.
|
|
328
|
+
*
|
|
329
|
+
* @param token - The token of the state family to dispose
|
|
330
|
+
* @param key - The unique key of the state to dispose
|
|
331
|
+
*/
|
|
332
|
+
declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/main/find-state.d.ts
|
|
335
|
+
/**
|
|
336
|
+
* Finds a {@link MutableAtomToken} in the store, without accessing its value.
|
|
337
|
+
*
|
|
338
|
+
* In an ephemeral store, this will create a new atom if one does not exist with the given key.
|
|
339
|
+
*
|
|
340
|
+
* In an immortal store, a "counterfeit" atom token will be returned in this case and a warning will be logged.
|
|
341
|
+
*
|
|
342
|
+
* @param token - A {@link MutableAtomFamilyToken}
|
|
343
|
+
* @param key - The key of the state
|
|
317
344
|
* @returns
|
|
318
|
-
* The
|
|
319
|
-
* @overload
|
|
345
|
+
* The current value of the state
|
|
346
|
+
* @overload Mutable Atom
|
|
320
347
|
*/
|
|
321
|
-
declare function
|
|
348
|
+
declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical, Key extends K>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken$1<T, J, K>;
|
|
322
349
|
/**
|
|
323
|
-
* @
|
|
324
|
-
* Declare a selector. The value of a selector should depend
|
|
325
|
-
* on the value of atoms or other selectors in the store,
|
|
326
|
-
* and should be recycled when a root atom of the selector is set.
|
|
350
|
+
* Finds a {@link RegularAtomToken} in the store, without accessing its value.
|
|
327
351
|
*
|
|
328
|
-
*
|
|
329
|
-
* The reference to that object is permanent and will not be replaced.
|
|
352
|
+
* In an ephemeral store, this will create a new atom if one does not exist with the given key.
|
|
330
353
|
*
|
|
331
|
-
*
|
|
354
|
+
* In an immortal store, a "counterfeit" atom token will be returned in this case and a warning will be logged.
|
|
332
355
|
*
|
|
333
|
-
* @param
|
|
356
|
+
* @param token - The token of the state family
|
|
357
|
+
* @param key - The key of the state
|
|
334
358
|
* @returns
|
|
335
|
-
* The
|
|
336
|
-
* @overload
|
|
359
|
+
* The current value of the state
|
|
360
|
+
* @overload Regular Atom
|
|
337
361
|
*/
|
|
338
|
-
declare function
|
|
362
|
+
declare function findState<T, K extends Canonical, Key extends K>(token: RegularAtomFamilyToken<T, K>, key: Key): RegularAtomToken$1<T, K>;
|
|
339
363
|
/**
|
|
340
|
-
* @
|
|
341
|
-
* Declare a selector. The value of a selector should depend
|
|
342
|
-
* on the value of atoms or other selectors in the store.
|
|
364
|
+
* Finds a {@link WritableSelectorToken} in the store, without accessing its value.
|
|
343
365
|
*
|
|
344
|
-
*
|
|
345
|
-
* in order to be garbage collected when a root atom of the selector is set.
|
|
366
|
+
* In an ephemeral store, this will create a new selector if one does not exist with the given key.
|
|
346
367
|
*
|
|
347
|
-
*
|
|
348
|
-
* It is strongly advised to set its dependencies to values
|
|
349
|
-
* that would produce the new value of the selector.
|
|
368
|
+
* In an immortal store, a "counterfeit" selector token will be returned in this case and a warning will be logged.
|
|
350
369
|
*
|
|
351
|
-
* @param
|
|
370
|
+
* @param token - The token of the state family
|
|
371
|
+
* @param key - The key of the state
|
|
352
372
|
* @returns
|
|
353
|
-
* The
|
|
354
|
-
* @overload
|
|
373
|
+
* The current value of the state
|
|
374
|
+
* @overload Writable Selector
|
|
355
375
|
*/
|
|
356
|
-
declare function
|
|
376
|
+
declare function findState<T, K extends Canonical, Key extends K>(token: WritableSelectorFamilyToken$1<T, K>, key: Key): WritableSelectorToken$1<T, K>;
|
|
357
377
|
/**
|
|
358
|
-
* @
|
|
359
|
-
* Declare a selector. The value of a selector should depend
|
|
360
|
-
* on the value of atoms or other selectors in the store.
|
|
378
|
+
* Finds a {@link ReadonlySelectorToken} in the store, without accessing its value.
|
|
361
379
|
*
|
|
362
|
-
*
|
|
363
|
-
* in order to be garbage collected when a root atom of the selector is set.
|
|
380
|
+
* In an ephemeral store, this will create a new selector if one does not exist with the given key.
|
|
364
381
|
*
|
|
365
|
-
*
|
|
382
|
+
* In an immortal store, a "counterfeit" selector token will be returned in this case and a warning will be logged.
|
|
366
383
|
*
|
|
367
|
-
* @param
|
|
384
|
+
* @param token - The token of the state family
|
|
385
|
+
* @param key - The key of the state
|
|
368
386
|
* @returns
|
|
369
|
-
* The
|
|
370
|
-
* @overload
|
|
371
|
-
*/
|
|
372
|
-
declare function selector<T>(options: ReadonlyPureSelectorOptions<T>): ReadonlyPureSelectorToken<T>;
|
|
373
|
-
/** @public */
|
|
374
|
-
type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
375
|
-
/** The unique identifier of the family */
|
|
376
|
-
key: string;
|
|
377
|
-
/** For each instantiated family member, a function that computes its value */
|
|
378
|
-
get: (key: K) => Read<() => T>;
|
|
379
|
-
/** For each instantiated family member, a function that sets its value */
|
|
380
|
-
set: (key: K) => Write<(newValue: T) => void>;
|
|
381
|
-
};
|
|
382
|
-
/** @public */
|
|
383
|
-
type ReadonlyPureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
384
|
-
/** The unique identifier of the family */
|
|
385
|
-
key: string;
|
|
386
|
-
/** For each instantiated family member, a function that computes its value */
|
|
387
|
-
get: (key: K) => Read<() => T>;
|
|
388
|
-
};
|
|
389
|
-
/** @public */
|
|
390
|
-
type WritableHeldSelectorFamilyOptions<T extends object, K extends Canonical> = {
|
|
391
|
-
/** The unique identifier of the family */
|
|
392
|
-
key: string;
|
|
393
|
-
/** For each instantiated family member, a constant reference to a value that will not be replaced */
|
|
394
|
-
const: (key: K) => T;
|
|
395
|
-
/** For each instantiated family member, a function that computes its value */
|
|
396
|
-
get: (key: K) => Read<(permanent: T) => void>;
|
|
397
|
-
/** For each instantiated family member, a function that sets its value */
|
|
398
|
-
set: (key: K) => Write<(newValue: T) => void>;
|
|
399
|
-
};
|
|
400
|
-
/** @public */
|
|
401
|
-
type ReadonlyHeldSelectorFamilyOptions<T extends object, K extends Canonical> = {
|
|
402
|
-
/** The unique identifier of the family */
|
|
403
|
-
key: string;
|
|
404
|
-
/** For each instantiated family member, a constant reference to a value that will not be replaced */
|
|
405
|
-
const: (key: K) => T;
|
|
406
|
-
/** For each instantiated family member, a function that computes its value */
|
|
407
|
-
get: (key: K) => Read<(permanent: T) => void>;
|
|
408
|
-
};
|
|
409
|
-
type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
|
|
410
|
-
/** The unique identifier of the family */
|
|
411
|
-
key: string;
|
|
412
|
-
/** Discriminator */
|
|
413
|
-
type: `writable_pure_selector_family`;
|
|
414
|
-
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
415
|
-
__T?: T;
|
|
416
|
-
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
417
|
-
__K?: K;
|
|
418
|
-
};
|
|
419
|
-
type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
|
|
420
|
-
/** The unique identifier of the family */
|
|
421
|
-
key: string;
|
|
422
|
-
/** Discriminator */
|
|
423
|
-
type: `readonly_pure_selector_family`;
|
|
424
|
-
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
425
|
-
__T?: T;
|
|
426
|
-
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
427
|
-
__K?: K;
|
|
428
|
-
};
|
|
429
|
-
type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
430
|
-
/** The unique identifier of the family */
|
|
431
|
-
key: string;
|
|
432
|
-
/** Discriminator */
|
|
433
|
-
type: `writable_held_selector_family`;
|
|
434
|
-
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
435
|
-
__T?: T;
|
|
436
|
-
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
437
|
-
__K?: K;
|
|
438
|
-
};
|
|
439
|
-
type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
440
|
-
/** The unique identifier of the family */
|
|
441
|
-
key: string;
|
|
442
|
-
/** Discriminator */
|
|
443
|
-
type: `readonly_held_selector_family`;
|
|
444
|
-
/** Never present. This is a marker that preserves the type of the value of each family member */
|
|
445
|
-
__T?: T;
|
|
446
|
-
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
447
|
-
__K?: K;
|
|
448
|
-
};
|
|
449
|
-
type PureSelectorFamilyToken<T, K extends Canonical> = ReadonlyPureSelectorFamilyToken<T, K> | WritablePureSelectorFamilyToken<T, K>;
|
|
450
|
-
type HeldSelectorFamilyToken<T, K extends Canonical> = ReadonlyHeldSelectorFamilyToken<T, K> | WritableHeldSelectorFamilyToken<T, K>;
|
|
451
|
-
type ReadonlySelectorFamilyToken<T, K extends Canonical> = ReadonlyHeldSelectorFamilyToken<T, K> | ReadonlyPureSelectorFamilyToken<T, K>;
|
|
452
|
-
type WritableSelectorFamilyToken<T, K extends Canonical> = WritableHeldSelectorFamilyToken<T, K> | WritablePureSelectorFamilyToken<T, K>;
|
|
453
|
-
type SelectorFamilyToken<T, K extends Canonical> = HeldSelectorFamilyToken<T, K> | PureSelectorFamilyToken<T, K>;
|
|
454
|
-
/**
|
|
455
|
-
* @public
|
|
456
|
-
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
457
|
-
*
|
|
458
|
-
* The value of a held selector should depend on the value of atoms or other selectors in the store,
|
|
459
|
-
* and should be recycled when a root atom of the selector is set.
|
|
460
|
-
*
|
|
461
|
-
* A held selector's value must be some object.
|
|
462
|
-
* The reference to that object is permanent and will not be replaced.
|
|
463
|
-
*
|
|
464
|
-
* A writable selector can be "set" to a new value.
|
|
465
|
-
* It is advised to set its dependencies to values
|
|
466
|
-
* that would produce the new value of the selector.
|
|
467
|
-
*
|
|
468
|
-
* @param options - {@link WritableHeldSelectorFamilyOptions}.
|
|
469
|
-
* @returns
|
|
470
|
-
* A reference to the selector family created: a {@link WritableHeldSelectorFamilyToken}
|
|
471
|
-
* @overload WritableHeld
|
|
472
|
-
*/
|
|
473
|
-
declare function selectorFamily<T extends object, K extends Canonical>(options: WritableHeldSelectorFamilyOptions<T, K>): WritableHeldSelectorFamilyToken<T, K>;
|
|
474
|
-
/**
|
|
475
|
-
* @public
|
|
476
|
-
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
477
|
-
*
|
|
478
|
-
* The value of a held selector should depend on the value of atoms or other selectors in the store,
|
|
479
|
-
* and should be recycled when a root atom of the selector is set.
|
|
480
|
-
*
|
|
481
|
-
* A held selector's value must be some object.
|
|
482
|
-
* The reference to that object is permanent and will not be replaced.
|
|
483
|
-
*
|
|
484
|
-
* A readonly selector can be "gotten" but not "set".
|
|
485
|
-
*
|
|
486
|
-
* @param options - {@link ReadonlyHeldSelectorFamilyOptions}.
|
|
487
|
-
* @returns
|
|
488
|
-
* A reference to the selector family created: a {@link ReadonlyHeldSelectorFamilyToken}
|
|
489
|
-
* @overload ReadonlyHeld
|
|
490
|
-
*/
|
|
491
|
-
declare function selectorFamily<T extends object, K extends Canonical>(options: ReadonlyHeldSelectorFamilyOptions<T, K>): ReadonlyHeldSelectorFamilyToken<T, K>;
|
|
492
|
-
/**
|
|
493
|
-
* @public
|
|
494
|
-
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
495
|
-
*
|
|
496
|
-
* The value of a selector should depend on the value of atoms or other selectors in the store.
|
|
497
|
-
*
|
|
498
|
-
* A pure selector's current value is evicted from the store
|
|
499
|
-
* in order to be garbage collected when a root atom of the selector is set.
|
|
500
|
-
*
|
|
501
|
-
* A writable selector can be "set" to a new value.
|
|
502
|
-
* It is advised to set its dependencies to values
|
|
503
|
-
* that would produce the new value of the selector.
|
|
504
|
-
*
|
|
505
|
-
* @param options - {@link TransientWritableSelectorFamilyOptions}.
|
|
506
|
-
* @returns
|
|
507
|
-
* A reference to the selector family created: a {@link TransientWritableSelectorFamilyToken}
|
|
508
|
-
* @overload WritablePure
|
|
509
|
-
*/
|
|
510
|
-
declare function selectorFamily<T, K extends Canonical>(options: WritablePureSelectorFamilyOptions<T, K>): WritablePureSelectorFamilyToken<T, K>;
|
|
511
|
-
/**
|
|
512
|
-
* @public
|
|
513
|
-
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
514
|
-
*
|
|
515
|
-
* The value of a selector should depend on the value of atoms or other selectors in the store.
|
|
516
|
-
*
|
|
517
|
-
* A pure selector's current value is evicted from the store
|
|
518
|
-
* in order to be garbage collected when a root atom of the selector is set.
|
|
519
|
-
*
|
|
520
|
-
* A readonly selector can be "gotten" but not "set".
|
|
521
|
-
*
|
|
522
|
-
* @param options - {@link ReadonlyPureSelectorFamilyOptions}.
|
|
523
|
-
* @returns
|
|
524
|
-
* A reference to the selector family created: a {@link ReadonlyPureSelectorFamilyToken}
|
|
525
|
-
* @overload ReadonlyPure
|
|
526
|
-
*/
|
|
527
|
-
declare function selectorFamily<T, K extends Canonical>(options: ReadonlyPureSelectorFamilyOptions<T, K>): ReadonlyPureSelectorFamilyToken<T, K>;
|
|
528
|
-
//#endregion
|
|
529
|
-
//#region src/main/timeline.d.ts
|
|
530
|
-
/** @public */
|
|
531
|
-
type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
|
|
532
|
-
/** @public */
|
|
533
|
-
type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
|
|
534
|
-
/** @public */
|
|
535
|
-
type TimelineToken<M> = {
|
|
536
|
-
/** The unique identifier of the timeline */
|
|
537
|
-
key: string;
|
|
538
|
-
/** Discriminator */
|
|
539
|
-
type: `timeline`;
|
|
540
|
-
/** Never present. This is a marker that preserves the type of the managed atoms */
|
|
541
|
-
__M?: M;
|
|
542
|
-
};
|
|
543
|
-
/** @public */
|
|
544
|
-
type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
545
|
-
/** The unique identifier of the timeline */
|
|
546
|
-
key: string;
|
|
547
|
-
/** The managed atoms (and families of atoms) to record */
|
|
548
|
-
scope: ManagedAtom[];
|
|
549
|
-
/** A function that determines whether a given update should be recorded */
|
|
550
|
-
shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
|
|
551
|
-
};
|
|
552
|
-
/** @public */
|
|
553
|
-
type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation | TimelineMoleculeDisposal | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
|
|
554
|
-
/**
|
|
555
|
-
* @public
|
|
556
|
-
* Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms.
|
|
557
|
-
* @param options - {@link TimelineOptions}
|
|
558
|
-
* @returns A reference to the timeline created: a {@link TimelineToken}
|
|
559
|
-
*/
|
|
560
|
-
declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
|
|
561
|
-
declare const redo: (tl: TimelineToken<any>) => void;
|
|
562
|
-
declare const undo: (tl: TimelineToken<any>) => void;
|
|
563
|
-
//#endregion
|
|
564
|
-
//#region src/main/dispose-state.d.ts
|
|
565
|
-
/**
|
|
566
|
-
* @public
|
|
567
|
-
* Disposes of a state in the implicit store.
|
|
568
|
-
*
|
|
569
|
-
* Only family members can be disposed of.
|
|
570
|
-
*
|
|
571
|
-
* @param token - The token of the state to dispose
|
|
572
|
-
* @overload Default
|
|
573
|
-
*/
|
|
574
|
-
declare function disposeState(token: ReadableToken<any>): void;
|
|
575
|
-
/**
|
|
576
|
-
* @public
|
|
577
|
-
* Disposes of a state in the implicit store.
|
|
578
|
-
*
|
|
579
|
-
* Only family members can be disposed of.
|
|
580
|
-
*
|
|
581
|
-
* @param token - The token of the state family to dispose
|
|
582
|
-
* @param key - The unique key of the state to dispose
|
|
583
|
-
*/
|
|
584
|
-
declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
|
|
585
|
-
//#endregion
|
|
586
|
-
//#region src/main/find-state.d.ts
|
|
587
|
-
/**
|
|
588
|
-
* @public
|
|
589
|
-
* Finds a {@link MutableAtomToken} in the store, without accessing its value.
|
|
590
|
-
*
|
|
591
|
-
* In an ephemeral store, this will create a new atom if one does not exist with the given key.
|
|
592
|
-
*
|
|
593
|
-
* In an immortal store, a "counterfeit" atom token will be returned in this case and a warning will be logged.
|
|
594
|
-
*
|
|
595
|
-
* @param token - A {@link MutableAtomFamilyToken}
|
|
596
|
-
* @param key - The key of the state
|
|
597
|
-
* @returns
|
|
598
|
-
* The current value of the state
|
|
599
|
-
* @overload Mutable Atom
|
|
600
|
-
*/
|
|
601
|
-
declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical, Key extends K>(token: MutableAtomFamilyToken$1<T, J, K>, key: Key): MutableAtomToken$1<T, J, K>;
|
|
602
|
-
/**
|
|
603
|
-
* @public
|
|
604
|
-
* Finds a {@link RegularAtomToken} in the store, without accessing its value.
|
|
605
|
-
*
|
|
606
|
-
* In an ephemeral store, this will create a new atom if one does not exist with the given key.
|
|
607
|
-
*
|
|
608
|
-
* In an immortal store, a "counterfeit" atom token will be returned in this case and a warning will be logged.
|
|
609
|
-
*
|
|
610
|
-
* @param token - The token of the state family
|
|
611
|
-
* @param key - The key of the state
|
|
612
|
-
* @returns
|
|
613
|
-
* The current value of the state
|
|
614
|
-
* @overload Regular Atom
|
|
615
|
-
*/
|
|
616
|
-
declare function findState<T, K extends Canonical, Key extends K>(token: RegularAtomFamilyToken$1<T, K>, key: Key): RegularAtomToken$1<T, K>;
|
|
617
|
-
/**
|
|
618
|
-
* @public
|
|
619
|
-
* Finds a {@link WritableSelectorToken} in the store, without accessing its value.
|
|
620
|
-
*
|
|
621
|
-
* In an ephemeral store, this will create a new selector if one does not exist with the given key.
|
|
622
|
-
*
|
|
623
|
-
* In an immortal store, a "counterfeit" selector token will be returned in this case and a warning will be logged.
|
|
624
|
-
*
|
|
625
|
-
* @param token - The token of the state family
|
|
626
|
-
* @param key - The key of the state
|
|
627
|
-
* @returns
|
|
628
|
-
* The current value of the state
|
|
629
|
-
* @overload Writable Selector
|
|
630
|
-
*/
|
|
631
|
-
declare function findState<T, K extends Canonical, Key extends K>(token: WritableSelectorFamilyToken$1<T, K>, key: Key): WritableSelectorToken$1<T, K>;
|
|
632
|
-
/**
|
|
633
|
-
* @public
|
|
634
|
-
* Finds a {@link ReadonlySelectorToken} in the store, without accessing its value.
|
|
635
|
-
*
|
|
636
|
-
* In an ephemeral store, this will create a new selector if one does not exist with the given key.
|
|
637
|
-
*
|
|
638
|
-
* In an immortal store, a "counterfeit" selector token will be returned in this case and a warning will be logged.
|
|
639
|
-
*
|
|
640
|
-
* @param token - The token of the state family
|
|
641
|
-
* @param key - The key of the state
|
|
642
|
-
* @returns
|
|
643
|
-
* The current value of the state
|
|
644
|
-
* @overload Readonly Selector
|
|
387
|
+
* The current value of the state
|
|
388
|
+
* @overload Readonly Selector
|
|
645
389
|
*/
|
|
646
390
|
declare function findState<T, K extends Canonical, Key extends K>(token: ReadonlySelectorFamilyToken$1<T, K>, key: Key): ReadonlySelectorToken$1<T, K>;
|
|
647
391
|
/**
|
|
648
|
-
* @public
|
|
649
392
|
* Finds a {@link WritableToken} in the store, without accessing its value.
|
|
650
393
|
*
|
|
651
394
|
* In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
|
|
@@ -660,7 +403,6 @@ declare function findState<T, K extends Canonical, Key extends K>(token: Readonl
|
|
|
660
403
|
*/
|
|
661
404
|
declare function findState<T, K extends Canonical, Key extends K>(token: WritableFamilyToken$1<T, K>, key: Key): WritableToken$1<T, K>;
|
|
662
405
|
/**
|
|
663
|
-
* @public
|
|
664
406
|
* Finds a {@link MutableAtomToken} in the store, without accessing its value.
|
|
665
407
|
*
|
|
666
408
|
* In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
|
|
@@ -678,7 +420,6 @@ declare function findState<T, K extends Canonical, Key extends K>(token: Readabl
|
|
|
678
420
|
//#endregion
|
|
679
421
|
//#region src/main/get-state.d.ts
|
|
680
422
|
/**
|
|
681
|
-
* @public
|
|
682
423
|
* Read or compute the current value of a state
|
|
683
424
|
* @param token - The token of the state to get
|
|
684
425
|
* @return The current value of the state
|
|
@@ -687,7 +428,6 @@ declare function findState<T, K extends Canonical, Key extends K>(token: Readabl
|
|
|
687
428
|
*/
|
|
688
429
|
declare function getState<T>(token: ReadableToken<T>): T;
|
|
689
430
|
/**
|
|
690
|
-
* @public
|
|
691
431
|
* Read or compute the current value of a state
|
|
692
432
|
* @param token - The token of a state family
|
|
693
433
|
* @param key - The unique key of the state to get
|
|
@@ -697,7 +437,6 @@ declare function getState<T>(token: ReadableToken<T>): T;
|
|
|
697
437
|
declare function getState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): T;
|
|
698
438
|
//#endregion
|
|
699
439
|
//#region src/main/join.d.ts
|
|
700
|
-
/** @public */
|
|
701
440
|
type JoinOptions<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Flat<JunctionSchemaBase<ASide, BSide> & {
|
|
702
441
|
/** Unique identifier of the join */
|
|
703
442
|
readonly key: string;
|
|
@@ -708,7 +447,6 @@ type JoinOptions<ASide extends string, AType extends string, BSide extends strin
|
|
|
708
447
|
/** Type guard for the type of the right side */
|
|
709
448
|
readonly isBType: Refinement<string, BType>;
|
|
710
449
|
}> & Partial<JunctionEntriesBase<AType, BType, Content>>;
|
|
711
|
-
/** @public */
|
|
712
450
|
type JoinToken<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null = null> = {
|
|
713
451
|
/** Unique identifier of the join */
|
|
714
452
|
key: string;
|
|
@@ -728,7 +466,6 @@ type JoinToken<ASide extends string, AType extends string, BSide extends string,
|
|
|
728
466
|
__content?: Content;
|
|
729
467
|
};
|
|
730
468
|
/**
|
|
731
|
-
* @public
|
|
732
469
|
* Create a join, an interface for managing relations between two sets of keys.
|
|
733
470
|
*
|
|
734
471
|
* Use joins when it is important to view relationships from either side.
|
|
@@ -742,28 +479,37 @@ type JoinToken<ASide extends string, AType extends string, BSide extends string,
|
|
|
742
479
|
* @overload No Content
|
|
743
480
|
*/
|
|
744
481
|
declare function join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>, defaultContent?: undefined): JoinToken<ASide, AType, BSide, BType, Cardinality, null>;
|
|
745
|
-
declare function join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>;
|
|
746
|
-
/** @public */
|
|
747
|
-
type JoinStates<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? { readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<[AType, Content] | null, BType> } & { readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<[BType, Content] | null, AType> } : {}) & { readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<AType | null, BType> } & { readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<BType | null, AType> } : Cardinality extends `1:n` ? (Content extends Json.Object ? { readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<[AType, Content] | null, BType> } & { readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<[BType, Content][], AType> } : {}) & { readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<AType | null, BType> } & { readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<BType[], AType> } : Cardinality extends `n:n` ? (Content extends Json.Object ? { readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<[AType, Content][], BType> } & { readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<[BType, Content][], AType> } : {}) & { readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<AType[], BType> } & { readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<BType[], AType> } : never;
|
|
748
482
|
/**
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
* @
|
|
756
|
-
|
|
757
|
-
|
|
483
|
+
* Create a join, an interface for managing relations between two sets of keys.
|
|
484
|
+
*
|
|
485
|
+
* Use joins when it is important to view relationships from either side.
|
|
486
|
+
*
|
|
487
|
+
* Under the hood, joins coordinate changes of multiple atoms to support that the desired relationships stay consistent.
|
|
488
|
+
*
|
|
489
|
+
* @param options - {@link JoinOptions}
|
|
490
|
+
* @param defaultContent - The default value for the content of each relation
|
|
491
|
+
* @returns
|
|
492
|
+
* A reference to the join created: a {@link JoinToken}
|
|
493
|
+
* @overload With Content
|
|
494
|
+
*/
|
|
495
|
+
declare function join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>;
|
|
496
|
+
type JoinStates<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? { readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<[AType, Content] | null, BType> } & { readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<[BType, Content] | null, AType> } : {}) & { readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<AType | null, BType> } & { readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<BType | null, AType> } : Cardinality extends `1:n` ? (Content extends Json.Object ? { readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<[AType, Content] | null, BType> } & { readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<[BType, Content][], AType> } : {}) & { readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<AType | null, BType> } & { readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<BType[], AType> } : Cardinality extends `n:n` ? (Content extends Json.Object ? { readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<[AType, Content][], BType> } & { readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<[BType, Content][], AType> } : {}) & { readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlyPureSelectorToken$1<AType[], BType> } & { readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlyPureSelectorToken$1<BType[], AType> } : never;
|
|
497
|
+
/**
|
|
498
|
+
* Find the current value of a relation owned by a {@link join}
|
|
499
|
+
* @param token - The token of the join
|
|
500
|
+
* @param key - The key of the relation to find
|
|
501
|
+
* @returns
|
|
502
|
+
* A {@link JoinStates} interface to access the relation
|
|
503
|
+
* @overload Default
|
|
504
|
+
*/
|
|
505
|
+
declare function findRelations<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, key: AType | BType): JoinStates<ASide, AType, BSide, BType, Cardinality, Content>;
|
|
758
506
|
/**
|
|
759
|
-
* @public
|
|
760
507
|
* Change one or multiple relations owned by a {@link join}
|
|
761
508
|
* @param token - The token of the join
|
|
762
509
|
* @param change - A function that takes a {@link Junction} interface to edit the relations
|
|
763
510
|
*/
|
|
764
511
|
declare function editRelations<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void): void;
|
|
765
512
|
/**
|
|
766
|
-
* @public
|
|
767
513
|
* @param token - The token of the join
|
|
768
514
|
* @returns
|
|
769
515
|
* A {@link MutableAtomFamilyToken} to access the internal relations
|
|
@@ -927,53 +673,380 @@ type ExclusiveFealty = {
|
|
|
927
673
|
above: TypedKey | `root`;
|
|
928
674
|
below: Scope;
|
|
929
675
|
};
|
|
930
|
-
type Fealty = ExclusiveFealty | MutualFealty;
|
|
931
|
-
type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
|
|
932
|
-
type Vassal<H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
|
|
933
|
-
below: Array<infer V>;
|
|
934
|
-
} ? V extends TypedKey ? V : never : never }[keyof H];
|
|
935
|
-
type Above<TK extends TypedKey, H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
|
|
936
|
-
below: Array<infer V>;
|
|
937
|
-
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never }[keyof H];
|
|
938
|
-
type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`] ? H[K][`below`] : TK extends H[K][`above`][number] ? H[K][`below`] : never : H[K] extends {
|
|
939
|
-
above: infer V;
|
|
940
|
-
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`below`][number] : never : never : never }[keyof H];
|
|
941
|
-
type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`][number] ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]] : never : never }[keyof H];
|
|
942
|
-
type CompoundFrom<H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never }[keyof H];
|
|
943
|
-
//#endregion
|
|
944
|
-
//#region src/main/
|
|
676
|
+
type Fealty = ExclusiveFealty | MutualFealty;
|
|
677
|
+
type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
|
|
678
|
+
type Vassal<H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
|
|
679
|
+
below: Array<infer V>;
|
|
680
|
+
} ? V extends TypedKey ? V : never : never }[keyof H];
|
|
681
|
+
type Above<TK extends TypedKey, H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
|
|
682
|
+
below: Array<infer V>;
|
|
683
|
+
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never }[keyof H];
|
|
684
|
+
type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`] ? H[K][`below`] : TK extends H[K][`above`][number] ? H[K][`below`] : never : H[K] extends {
|
|
685
|
+
above: infer V;
|
|
686
|
+
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`below`][number] : never : never : never }[keyof H];
|
|
687
|
+
type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`][number] ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]] : never : never }[keyof H];
|
|
688
|
+
type CompoundFrom<H extends Hierarchy> = { [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never }[keyof H];
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region src/main/reset-state.d.ts
|
|
691
|
+
/**
|
|
692
|
+
* Set the value of a state into the implicit store back to its default value.
|
|
693
|
+
* @param token - An atom or writable selector token.
|
|
694
|
+
* @overload Default
|
|
695
|
+
* @default
|
|
696
|
+
*/
|
|
697
|
+
declare function resetState(token: WritableToken<any>): void;
|
|
698
|
+
/**
|
|
699
|
+
* Set the value of a state into the implicit store back to its default value.
|
|
700
|
+
* @param token - An atom family or writable selector family token.
|
|
701
|
+
* @param key - The unique key of the state to set.
|
|
702
|
+
* @overload Streamlined
|
|
703
|
+
*/
|
|
704
|
+
declare function resetState<K extends Canonical>(token: WritableFamilyToken<any, K>, key: K): void;
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/main/subscribe.d.ts
|
|
707
|
+
type StateUpdate<T> = {
|
|
708
|
+
newValue: T;
|
|
709
|
+
oldValue: T;
|
|
710
|
+
};
|
|
711
|
+
type KeyedStateUpdate<T> = Flat<StateUpdate<T> & {
|
|
712
|
+
key: string;
|
|
713
|
+
type: `atom_update` | `selector_update`;
|
|
714
|
+
family?: FamilyMetadata;
|
|
715
|
+
}>;
|
|
716
|
+
type UpdateHandler<T> = (update: StateUpdate<T>) => void;
|
|
717
|
+
type TransactionUpdateHandler<F extends Func> = (data: TransactionUpdate<F>) => void;
|
|
718
|
+
/**
|
|
719
|
+
* Subscribe to a state in the implicit store
|
|
720
|
+
* @param token - The token of the state to subscribe to
|
|
721
|
+
* @param handleUpdate - A function that will be called when the state is updated
|
|
722
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
723
|
+
* @returns A function that can be called to unsubscribe from the state
|
|
724
|
+
* @overload State
|
|
725
|
+
*/
|
|
726
|
+
declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key?: string): () => void;
|
|
727
|
+
/**
|
|
728
|
+
* Subscribe to a transaction in the implicit store
|
|
729
|
+
* @param token - The token of the transaction to subscribe to
|
|
730
|
+
* @param handleUpdate - A function that will be called when the transaction succeeds
|
|
731
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
732
|
+
* @returns A function that can be called to unsubscribe from the transaction
|
|
733
|
+
* @overload Transaction
|
|
734
|
+
*/
|
|
735
|
+
declare function subscribe<F extends Func>(token: TransactionToken<F>, handleUpdate: TransactionUpdateHandler<F>, key?: string): () => void;
|
|
736
|
+
/**
|
|
737
|
+
* Subscribe to a timeline in the implicit store
|
|
738
|
+
* @param token - The token of the timeline to subscribe to
|
|
739
|
+
* @param handleUpdate - A function that will be called when a new update is available
|
|
740
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
741
|
+
* @returns A function that can be called to unsubscribe from the timeline
|
|
742
|
+
* @overload Timeline
|
|
743
|
+
*/
|
|
744
|
+
declare function subscribe<M extends TimelineManageable>(token: TimelineToken<M>, handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void, key?: string): () => void;
|
|
745
|
+
//#endregion
|
|
746
|
+
//#region src/main/validators.d.ts
|
|
747
|
+
type TokenType<Comparison extends ReadableFamilyToken<any, any> | ReadableToken<any>> = Comparison extends ReadableToken<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamilyToken<infer RepresentedValue, any> ? RepresentedValue : never;
|
|
748
|
+
declare function isToken<KnownToken extends RegularAtomToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is RegularAtomToken<TokenType<KnownToken>>;
|
|
749
|
+
declare function isToken<KnownToken extends MutableAtomToken<any, any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is MutableAtomToken<TokenType<KnownToken>, any>;
|
|
750
|
+
declare function isToken<KnownToken extends WritablePureSelectorToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is WritablePureSelectorToken<TokenType<KnownToken>>;
|
|
751
|
+
declare function isToken<KnownToken extends ReadonlyPureSelectorToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is ReadonlyPureSelectorToken<TokenType<KnownToken>>;
|
|
752
|
+
declare function isToken<KnownToken extends WritableToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is WritableToken<TokenType<KnownToken>>;
|
|
753
|
+
declare function isToken<KnownToken extends ReadableToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is ReadableToken<TokenType<KnownToken>>;
|
|
754
|
+
declare function belongsTo<Family extends RegularAtomFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is RegularAtomToken<TokenType<Family>>;
|
|
755
|
+
declare function belongsTo<Family extends MutableAtomFamilyToken<any, any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is MutableAtomToken<TokenType<Family>, any>;
|
|
756
|
+
declare function belongsTo<Family extends WritablePureSelectorFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is WritablePureSelectorToken<TokenType<Family>>;
|
|
757
|
+
declare function belongsTo<Family extends ReadonlyPureSelectorFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is ReadonlyPureSelectorToken<TokenType<Family>>;
|
|
758
|
+
declare function belongsTo<Family extends WritableFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is WritableToken<TokenType<Family>>;
|
|
759
|
+
declare function belongsTo<Family extends ReadableFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is ReadableToken<TokenType<Family>>;
|
|
760
|
+
//#endregion
|
|
761
|
+
//#region src/main/transaction.d.ts
|
|
762
|
+
type StateCreation<Token extends ReadableToken<any>> = {
|
|
763
|
+
type: `state_creation`;
|
|
764
|
+
token: Token;
|
|
765
|
+
};
|
|
766
|
+
type StateDisposal<Token extends ReadableToken<any>> = AtomDisposal<Token> | SelectorDisposal<Token>;
|
|
767
|
+
type AtomDisposal<Token extends ReadableToken<any>> = {
|
|
768
|
+
type: `state_disposal`;
|
|
769
|
+
subType: `atom`;
|
|
770
|
+
token: Token;
|
|
771
|
+
value: TokenType<Token>;
|
|
772
|
+
};
|
|
773
|
+
type SelectorDisposal<Token extends ReadableToken<any>> = {
|
|
774
|
+
type: `state_disposal`;
|
|
775
|
+
subType: `selector`;
|
|
776
|
+
token: Token;
|
|
777
|
+
};
|
|
778
|
+
type MoleculeCreation = {
|
|
779
|
+
type: `molecule_creation`;
|
|
780
|
+
key: Canonical;
|
|
781
|
+
provenance: Canonical;
|
|
782
|
+
};
|
|
783
|
+
type MoleculeDisposal = {
|
|
784
|
+
type: `molecule_disposal`;
|
|
785
|
+
key: Canonical;
|
|
786
|
+
provenance: stringified<Canonical>[];
|
|
787
|
+
values: [key: string, value: any][];
|
|
788
|
+
};
|
|
789
|
+
type MoleculeTransfer = {
|
|
790
|
+
type: `molecule_transfer`;
|
|
791
|
+
key: Canonical;
|
|
792
|
+
from: Canonical[];
|
|
793
|
+
to: Canonical[];
|
|
794
|
+
};
|
|
795
|
+
type TransactionUpdateContent = KeyedStateUpdate<unknown> | MoleculeCreation | MoleculeDisposal | MoleculeTransfer | StateCreation<ReadableToken<unknown>> | StateDisposal<ReadableToken<unknown>> | TransactionUpdate<Func>;
|
|
796
|
+
type TransactionUpdate<F extends Func> = {
|
|
797
|
+
type: `transaction_update`;
|
|
798
|
+
key: string;
|
|
799
|
+
id: string;
|
|
800
|
+
epoch: number;
|
|
801
|
+
updates: TransactionUpdateContent[];
|
|
802
|
+
params: Parameters<F>;
|
|
803
|
+
output: ReturnType<F>;
|
|
804
|
+
};
|
|
805
|
+
type ReaderToolkit = Pick<ActorToolkit, `find` | `get` | `json`>;
|
|
806
|
+
type WriterToolkit = Pick<ActorToolkit, `find` | `get` | `json` | `set`>;
|
|
807
|
+
type ActorToolkit = Readonly<{
|
|
808
|
+
get: typeof getState;
|
|
809
|
+
set: typeof setState;
|
|
810
|
+
reset: typeof resetState;
|
|
811
|
+
find: typeof findState;
|
|
812
|
+
json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritablePureSelectorToken<J>;
|
|
813
|
+
dispose: typeof disposeState;
|
|
814
|
+
run: typeof runTransaction;
|
|
815
|
+
env: () => EnvironmentData;
|
|
816
|
+
}>;
|
|
817
|
+
type Read<F extends Func> = (toolkit: ReaderToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
|
|
818
|
+
type Write<F extends Func> = (toolkit: WriterToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
|
|
819
|
+
type Transact<F extends Func> = (toolkit: ActorToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
|
|
820
|
+
type TransactionIO<Token extends TransactionToken<any>> = Token extends TransactionToken<infer F> ? F : never;
|
|
821
|
+
type TransactionOptions<F extends Func> = {
|
|
822
|
+
/** The unique identifier of the transaction */
|
|
823
|
+
key: string;
|
|
824
|
+
/** The operation to perform */
|
|
825
|
+
do: Transact<F>;
|
|
826
|
+
};
|
|
827
|
+
/**
|
|
828
|
+
* Create a transaction, a mechanism for batching updates multiple states in a single, all-or-nothing operation
|
|
829
|
+
* @param options - {@link TransactionOptions}
|
|
830
|
+
* @returns A reference to the transaction created: a {@link TransactionToken}
|
|
831
|
+
*/
|
|
832
|
+
declare function transaction<F extends Func>(options: TransactionOptions<F>): TransactionToken<F>;
|
|
833
|
+
/**
|
|
834
|
+
* Execute a {@link transaction}
|
|
835
|
+
* @param token - A {@link TransactionToken}
|
|
836
|
+
* @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
|
|
837
|
+
* @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
|
|
838
|
+
*/
|
|
839
|
+
declare function runTransaction<F extends Func>(token: TransactionToken<F>, id?: string): (...parameters: Parameters<F>) => ReturnType<F>;
|
|
840
|
+
//#endregion
|
|
841
|
+
//#region src/main/selector.d.ts
|
|
842
|
+
type WritablePureSelectorOptions<T> = {
|
|
843
|
+
/** The unique identifier of the selector */
|
|
844
|
+
key: string;
|
|
845
|
+
/** For each instantiated selector, a function that computes its value */
|
|
846
|
+
get: Read<() => T>;
|
|
847
|
+
/** For each instantiated selector, a function that sets its value */
|
|
848
|
+
set: Write<(newValue: T) => void>;
|
|
849
|
+
};
|
|
850
|
+
type ReadonlyPureSelectorOptions<T> = {
|
|
851
|
+
/** The unique identifier of the selector */
|
|
852
|
+
key: string;
|
|
853
|
+
/** For each instantiated selector, a function that computes its value */
|
|
854
|
+
get: Read<() => T>;
|
|
855
|
+
};
|
|
856
|
+
type ReadonlyHeldSelectorOptions<T extends object> = {
|
|
857
|
+
/** The unique identifier of the selector */
|
|
858
|
+
key: string;
|
|
859
|
+
/** For each instantiated selector, a constant reference to a value that will not be replaced */
|
|
860
|
+
const: T;
|
|
861
|
+
/** For each instantiated selector, a function that computes its value */
|
|
862
|
+
get: Read<(permanent: T) => void>;
|
|
863
|
+
};
|
|
864
|
+
type WritableHeldSelectorOptions<T extends object> = {
|
|
865
|
+
/** The unique identifier of the selector */
|
|
866
|
+
key: string;
|
|
867
|
+
/** For each instantiated selector, a constant reference to a value that will not be replaced */
|
|
868
|
+
const: T;
|
|
869
|
+
/** For each instantiated selector, a function that computes its value */
|
|
870
|
+
get: Read<(permanent: T) => void>;
|
|
871
|
+
/** For each instantiated selector, a function that sets its value */
|
|
872
|
+
set: Write<(newValue: T) => void>;
|
|
873
|
+
};
|
|
874
|
+
/**
|
|
875
|
+
* Declare a selector. The value of a selector should depend
|
|
876
|
+
* on the value of atoms or other selectors in the store, and
|
|
877
|
+
* should be recycled when a root atom of the selector is set.
|
|
878
|
+
*
|
|
879
|
+
* A held selector's value must be some object.
|
|
880
|
+
* The reference to that object is permanent and will not be replaced.
|
|
881
|
+
*
|
|
882
|
+
* A writable selector can be "set" to a new value.
|
|
883
|
+
* It is strongly advised to set its dependencies to values
|
|
884
|
+
* that would produce the new value of the selector.
|
|
885
|
+
*
|
|
886
|
+
* @param options - {@link WritableHeldSelectorOptions}.
|
|
887
|
+
* @returns
|
|
888
|
+
* The token for your selector.
|
|
889
|
+
* @overload WritableHeld
|
|
890
|
+
*/
|
|
891
|
+
declare function selector<T extends object>(options: WritableHeldSelectorOptions<T>): WritableHeldSelectorToken<T>;
|
|
892
|
+
/**
|
|
893
|
+
* Declare a selector. The value of a selector should depend
|
|
894
|
+
* on the value of atoms or other selectors in the store,
|
|
895
|
+
* and should be recycled when a root atom of the selector is set.
|
|
896
|
+
*
|
|
897
|
+
* A held selector's value must be some object.
|
|
898
|
+
* The reference to that object is permanent and will not be replaced.
|
|
899
|
+
*
|
|
900
|
+
* A readonly selector can be "gotten" but not "set".
|
|
901
|
+
*
|
|
902
|
+
* @param options - {@link ReadonlyHeldSelectorOptions}.
|
|
903
|
+
* @returns
|
|
904
|
+
* The token for your selector.
|
|
905
|
+
* @overload ReadonlyHeld
|
|
906
|
+
*/
|
|
907
|
+
declare function selector<T extends object>(options: ReadonlyHeldSelectorOptions<T>): ReadonlyHeldSelectorToken<T>;
|
|
908
|
+
/**
|
|
909
|
+
* Declare a selector. The value of a selector should depend
|
|
910
|
+
* on the value of atoms or other selectors in the store.
|
|
911
|
+
*
|
|
912
|
+
* A pure selector's current value is evicted from the store
|
|
913
|
+
* in order to be garbage collected when a root atom of the selector is set.
|
|
914
|
+
*
|
|
915
|
+
* A writable selector can be "set" to a new value.
|
|
916
|
+
* It is strongly advised to set its dependencies to values
|
|
917
|
+
* that would produce the new value of the selector.
|
|
918
|
+
*
|
|
919
|
+
* @param options - {@link TransientWritableSelectorOptions}.
|
|
920
|
+
* @returns
|
|
921
|
+
* The token for your selector.
|
|
922
|
+
* @overload WritablePure
|
|
923
|
+
*/
|
|
924
|
+
declare function selector<T>(options: WritablePureSelectorOptions<T>): WritablePureSelectorToken<T>;
|
|
925
|
+
/**
|
|
926
|
+
* Declare a selector. The value of a selector should depend
|
|
927
|
+
* on the value of atoms or other selectors in the store.
|
|
928
|
+
*
|
|
929
|
+
* A pure selector's current value is evicted from the store
|
|
930
|
+
* in order to be garbage collected when a root atom of the selector is set.
|
|
931
|
+
*
|
|
932
|
+
* A readonly selector can be "gotten" but not "set".
|
|
933
|
+
*
|
|
934
|
+
* @param options - {@link ReadonlyPureSelectorOptions}.
|
|
935
|
+
* @returns
|
|
936
|
+
* The token for your selector.
|
|
937
|
+
* @overload ReadonlyPure
|
|
938
|
+
*/
|
|
939
|
+
declare function selector<T>(options: ReadonlyPureSelectorOptions<T>): ReadonlyPureSelectorToken<T>;
|
|
940
|
+
type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
941
|
+
/** The unique identifier of the family */
|
|
942
|
+
key: string;
|
|
943
|
+
/** For each instantiated family member, a function that computes its value */
|
|
944
|
+
get: (key: K) => Read<() => T>;
|
|
945
|
+
/** For each instantiated family member, a function that sets its value */
|
|
946
|
+
set: (key: K) => Write<(newValue: T) => void>;
|
|
947
|
+
};
|
|
948
|
+
type ReadonlyPureSelectorFamilyOptions<T, K extends Canonical> = {
|
|
949
|
+
/** The unique identifier of the family */
|
|
950
|
+
key: string;
|
|
951
|
+
/** For each instantiated family member, a function that computes its value */
|
|
952
|
+
get: (key: K) => Read<() => T>;
|
|
953
|
+
};
|
|
954
|
+
type WritableHeldSelectorFamilyOptions<T extends object, K extends Canonical> = {
|
|
955
|
+
/** The unique identifier of the family */
|
|
956
|
+
key: string;
|
|
957
|
+
/** For each instantiated family member, a constant reference to a value that will not be replaced */
|
|
958
|
+
const: (key: K) => T;
|
|
959
|
+
/** For each instantiated family member, a function that computes its value */
|
|
960
|
+
get: (key: K) => Read<(permanent: T) => void>;
|
|
961
|
+
/** For each instantiated family member, a function that sets its value */
|
|
962
|
+
set: (key: K) => Write<(newValue: T) => void>;
|
|
963
|
+
};
|
|
964
|
+
type ReadonlyHeldSelectorFamilyOptions<T extends object, K extends Canonical> = {
|
|
965
|
+
/** The unique identifier of the family */
|
|
966
|
+
key: string;
|
|
967
|
+
/** For each instantiated family member, a constant reference to a value that will not be replaced */
|
|
968
|
+
const: (key: K) => T;
|
|
969
|
+
/** For each instantiated family member, a function that computes its value */
|
|
970
|
+
get: (key: K) => Read<(permanent: T) => void>;
|
|
971
|
+
};
|
|
945
972
|
/**
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
973
|
+
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
974
|
+
*
|
|
975
|
+
* The value of a held selector should depend on the value of atoms or other selectors in the store,
|
|
976
|
+
* and should be recycled when a root atom of the selector is set.
|
|
977
|
+
*
|
|
978
|
+
* A held selector's value must be some object.
|
|
979
|
+
* The reference to that object is permanent and will not be replaced.
|
|
980
|
+
*
|
|
981
|
+
* A writable selector can be "set" to a new value.
|
|
982
|
+
* It is advised to set its dependencies to values
|
|
983
|
+
* that would produce the new value of the selector.
|
|
984
|
+
*
|
|
985
|
+
* @param options - {@link WritableHeldSelectorFamilyOptions}.
|
|
949
986
|
* @returns
|
|
950
|
-
*
|
|
987
|
+
* A reference to the selector family created: a {@link WritableHeldSelectorFamilyToken}
|
|
988
|
+
* @overload WritableHeld
|
|
951
989
|
*/
|
|
952
|
-
|
|
990
|
+
declare function selectorFamily<T extends object, K extends Canonical>(options: WritableHeldSelectorFamilyOptions<T, K>): WritableHeldSelectorFamilyToken<T, K>;
|
|
953
991
|
/**
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
-
*
|
|
959
|
-
*
|
|
992
|
+
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
993
|
+
*
|
|
994
|
+
* The value of a held selector should depend on the value of atoms or other selectors in the store,
|
|
995
|
+
* and should be recycled when a root atom of the selector is set.
|
|
996
|
+
*
|
|
997
|
+
* A held selector's value must be some object.
|
|
998
|
+
* The reference to that object is permanent and will not be replaced.
|
|
999
|
+
*
|
|
1000
|
+
* A readonly selector can be "gotten" but not "set".
|
|
1001
|
+
*
|
|
1002
|
+
* @param options - {@link ReadonlyHeldSelectorFamilyOptions}.
|
|
1003
|
+
* @returns
|
|
1004
|
+
* A reference to the selector family created: a {@link ReadonlyHeldSelectorFamilyToken}
|
|
1005
|
+
* @overload ReadonlyHeld
|
|
960
1006
|
*/
|
|
961
|
-
declare function
|
|
1007
|
+
declare function selectorFamily<T extends object, K extends Canonical>(options: ReadonlyHeldSelectorFamilyOptions<T, K>): ReadonlyHeldSelectorFamilyToken<T, K>;
|
|
962
1008
|
/**
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
*
|
|
1009
|
+
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
1010
|
+
*
|
|
1011
|
+
* The value of a selector should depend on the value of atoms or other selectors in the store.
|
|
1012
|
+
*
|
|
1013
|
+
* A pure selector's current value is evicted from the store
|
|
1014
|
+
* in order to be garbage collected when a root atom of the selector is set.
|
|
1015
|
+
*
|
|
1016
|
+
* A writable selector can be "set" to a new value.
|
|
1017
|
+
* It is advised to set its dependencies to values
|
|
1018
|
+
* that would produce the new value of the selector.
|
|
1019
|
+
*
|
|
1020
|
+
* @param options - {@link TransientWritableSelectorFamilyOptions}.
|
|
1021
|
+
* @returns
|
|
1022
|
+
* A reference to the selector family created: a {@link TransientWritableSelectorFamilyToken}
|
|
1023
|
+
* @overload WritablePure
|
|
969
1024
|
*/
|
|
970
|
-
declare function
|
|
1025
|
+
declare function selectorFamily<T, K extends Canonical>(options: WritablePureSelectorFamilyOptions<T, K>): WritablePureSelectorFamilyToken<T, K>;
|
|
1026
|
+
/**
|
|
1027
|
+
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
1028
|
+
*
|
|
1029
|
+
* The value of a selector should depend on the value of atoms or other selectors in the store.
|
|
1030
|
+
*
|
|
1031
|
+
* A pure selector's current value is evicted from the store
|
|
1032
|
+
* in order to be garbage collected when a root atom of the selector is set.
|
|
1033
|
+
*
|
|
1034
|
+
* A readonly selector can be "gotten" but not "set".
|
|
1035
|
+
*
|
|
1036
|
+
* @param options - {@link ReadonlyPureSelectorFamilyOptions}.
|
|
1037
|
+
* @returns
|
|
1038
|
+
* A reference to the selector family created: a {@link ReadonlyPureSelectorFamilyToken}
|
|
1039
|
+
* @overload ReadonlyPure
|
|
1040
|
+
*/
|
|
1041
|
+
declare function selectorFamily<T, K extends Canonical>(options: ReadonlyPureSelectorFamilyOptions<T, K>): ReadonlyPureSelectorFamilyToken<T, K>;
|
|
971
1042
|
//#endregion
|
|
972
1043
|
//#region src/main/silo.d.ts
|
|
973
1044
|
declare class Silo {
|
|
974
1045
|
store: Store;
|
|
975
1046
|
atom: typeof atom;
|
|
1047
|
+
mutableAtom: typeof mutableAtom;
|
|
976
1048
|
atomFamily: typeof atomFamily;
|
|
1049
|
+
mutableAtomFamily: typeof mutableAtomFamily;
|
|
977
1050
|
selector: typeof selector;
|
|
978
1051
|
selectorFamily: typeof selectorFamily;
|
|
979
1052
|
transaction: typeof transaction;
|
|
@@ -991,194 +1064,37 @@ declare class Silo {
|
|
|
991
1064
|
constructor(config: Store[`config`], fromStore?: Store | null);
|
|
992
1065
|
}
|
|
993
1066
|
//#endregion
|
|
994
|
-
//#region src/main/
|
|
995
|
-
|
|
996
|
-
type
|
|
997
|
-
newValue: T;
|
|
998
|
-
oldValue: T;
|
|
999
|
-
};
|
|
1000
|
-
/** @public */
|
|
1001
|
-
type KeyedStateUpdate<T> = Flat<StateUpdate<T> & {
|
|
1002
|
-
key: string;
|
|
1003
|
-
type: `atom_update` | `selector_update`;
|
|
1004
|
-
family?: FamilyMetadata;
|
|
1005
|
-
}>;
|
|
1006
|
-
/** @public */
|
|
1007
|
-
type UpdateHandler<T> = (update: StateUpdate<T>) => void;
|
|
1008
|
-
/** @public */
|
|
1009
|
-
type TransactionUpdateHandler<F extends Func> = (data: TransactionUpdate<F>) => void;
|
|
1010
|
-
/**
|
|
1011
|
-
* @public
|
|
1012
|
-
* Subscribe to a state in the implicit store
|
|
1013
|
-
* @param token - The token of the state to subscribe to
|
|
1014
|
-
* @param handleUpdate - A function that will be called when the state is updated
|
|
1015
|
-
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
1016
|
-
* @returns A function that can be called to unsubscribe from the state
|
|
1017
|
-
* @overload State
|
|
1018
|
-
*/
|
|
1019
|
-
declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key?: string): () => void;
|
|
1020
|
-
/**
|
|
1021
|
-
* @public
|
|
1022
|
-
* Subscribe to a transaction in the implicit store
|
|
1023
|
-
* @param token - The token of the transaction to subscribe to
|
|
1024
|
-
* @param handleUpdate - A function that will be called when the transaction succeeds
|
|
1025
|
-
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
1026
|
-
* @returns A function that can be called to unsubscribe from the transaction
|
|
1027
|
-
* @overload Transaction
|
|
1028
|
-
*/
|
|
1029
|
-
declare function subscribe<F extends Func>(token: TransactionToken<F>, handleUpdate: TransactionUpdateHandler<F>, key?: string): () => void;
|
|
1067
|
+
//#region src/main/timeline.d.ts
|
|
1068
|
+
type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
|
|
1069
|
+
type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
|
|
1030
1070
|
/**
|
|
1031
|
-
* @
|
|
1032
|
-
*
|
|
1033
|
-
* @param token - The token of the timeline to subscribe to
|
|
1034
|
-
* @param handleUpdate - A function that will be called when a new update is available
|
|
1035
|
-
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
1036
|
-
* @returns A function that can be called to unsubscribe from the timeline
|
|
1037
|
-
* @overload Timeline
|
|
1071
|
+
* 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
|
|
1072
|
+
* @param timeline - A {@link TimelineToken}
|
|
1038
1073
|
*/
|
|
1039
|
-
declare
|
|
1040
|
-
//#endregion
|
|
1041
|
-
//#region src/main/validators.d.ts
|
|
1042
|
-
type TokenType<Comparison extends ReadableFamilyToken$1<any, any> | ReadableToken$1<any>> = Comparison extends ReadableToken$1<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamilyToken$1<infer RepresentedValue, any> ? RepresentedValue : never;
|
|
1043
|
-
declare function isToken<KnownToken extends RegularAtomToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is RegularAtomToken$1<TokenType<KnownToken>>;
|
|
1044
|
-
declare function isToken<KnownToken extends MutableAtomToken$1<any, any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is MutableAtomToken$1<TokenType<KnownToken>, any>;
|
|
1045
|
-
declare function isToken<KnownToken extends WritablePureSelectorToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is WritablePureSelectorToken$1<TokenType<KnownToken>>;
|
|
1046
|
-
declare function isToken<KnownToken extends ReadonlyPureSelectorToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is ReadonlyPureSelectorToken$1<TokenType<KnownToken>>;
|
|
1047
|
-
declare function isToken<KnownToken extends WritableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is WritableToken$1<TokenType<KnownToken>>;
|
|
1048
|
-
declare function isToken<KnownToken extends ReadableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is ReadableToken$1<TokenType<KnownToken>>;
|
|
1049
|
-
declare function belongsTo<Family extends RegularAtomFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is RegularAtomToken$1<TokenType<Family>>;
|
|
1050
|
-
declare function belongsTo<Family extends MutableAtomFamilyToken$1<any, any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is MutableAtomToken$1<TokenType<Family>, any>;
|
|
1051
|
-
declare function belongsTo<Family extends WritablePureSelectorFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is WritablePureSelectorToken$1<TokenType<Family>>;
|
|
1052
|
-
declare function belongsTo<Family extends ReadonlyPureSelectorFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is ReadonlyPureSelectorToken$1<TokenType<Family>>;
|
|
1053
|
-
declare function belongsTo<Family extends WritableFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is WritableToken$1<TokenType<Family>>;
|
|
1054
|
-
declare function belongsTo<Family extends ReadableFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is ReadableToken$1<TokenType<Family>>;
|
|
1055
|
-
//#endregion
|
|
1056
|
-
//#region src/main/index.d.ts
|
|
1074
|
+
declare const redo: (timeline: TimelineToken<any>) => void;
|
|
1057
1075
|
/**
|
|
1058
|
-
* @
|
|
1059
|
-
*
|
|
1060
|
-
*
|
|
1061
|
-
* While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
|
|
1062
|
-
*
|
|
1063
|
-
* Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
|
|
1064
|
-
*
|
|
1065
|
-
* Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
|
|
1066
|
-
*
|
|
1067
|
-
* Tokens are fully serializable, so they can be passed between processes.
|
|
1076
|
+
* Reverse the last update on the {@link timeline} and move the cursor to the previous update
|
|
1077
|
+
* @param timeline - A {@link TimelineToken}
|
|
1068
1078
|
*/
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
type
|
|
1072
|
-
/** The unique identifier of the
|
|
1073
|
-
key: string;
|
|
1074
|
-
/** Discriminator. */
|
|
1075
|
-
type: `atom`;
|
|
1076
|
-
/** Present if the atom belongs to a family. */
|
|
1077
|
-
family?: FamilyMetadata<K>;
|
|
1078
|
-
/** Never present. This is a marker that preserves the type of the atom's value. */
|
|
1079
|
-
__T?: T;
|
|
1080
|
-
};
|
|
1081
|
-
/** @public */
|
|
1082
|
-
type MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical = any> = {
|
|
1083
|
-
/** The unique identifier of the atom. */
|
|
1084
|
-
key: string;
|
|
1085
|
-
/** Discriminator. */
|
|
1086
|
-
type: `mutable_atom`;
|
|
1087
|
-
/** Present if the atom belongs to a family. */
|
|
1088
|
-
family?: FamilyMetadata<K>;
|
|
1089
|
-
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
1090
|
-
__J?: J;
|
|
1091
|
-
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
1092
|
-
__U?: T extends Transceiver<infer Update> ? Update : never;
|
|
1093
|
-
};
|
|
1094
|
-
/** @public */
|
|
1095
|
-
type AtomToken<T, K extends Canonical = any> = MutableAtomToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomToken<T, K>;
|
|
1096
|
-
/** @public */
|
|
1097
|
-
type WritablePureSelectorToken<T, K extends Canonical = any> = {
|
|
1098
|
-
/** The unique identifier of the selector. */
|
|
1099
|
-
key: string;
|
|
1100
|
-
/** Discriminator. */
|
|
1101
|
-
type: `writable_pure_selector`;
|
|
1102
|
-
/** Present if the selector belongs to a family. */
|
|
1103
|
-
family?: FamilyMetadata<K>;
|
|
1104
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
1105
|
-
__T?: T;
|
|
1106
|
-
};
|
|
1107
|
-
/** @public */
|
|
1108
|
-
type WritableHeldSelectorToken<T, K extends Canonical = any> = {
|
|
1109
|
-
/** The unique identifier of the selector. */
|
|
1110
|
-
key: string;
|
|
1111
|
-
/** Discriminator. */
|
|
1112
|
-
type: `writable_held_selector`;
|
|
1113
|
-
/** Present if the selector belongs to a family. */
|
|
1114
|
-
family?: FamilyMetadata<K>;
|
|
1115
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
1116
|
-
__T?: T;
|
|
1117
|
-
};
|
|
1118
|
-
/** @public */
|
|
1119
|
-
type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
|
|
1120
|
-
/** The unique identifier of the selector. */
|
|
1121
|
-
key: string;
|
|
1122
|
-
/** Discriminator. */
|
|
1123
|
-
type: `readonly_pure_selector`;
|
|
1124
|
-
/** Present if the selector belongs to a family. */
|
|
1125
|
-
family?: FamilyMetadata<K>;
|
|
1126
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
1127
|
-
__T?: T;
|
|
1128
|
-
};
|
|
1129
|
-
/** @public */
|
|
1130
|
-
type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
|
|
1131
|
-
/** The unique identifier of the selector. */
|
|
1079
|
+
declare const undo: (timeline: TimelineToken<any>) => void;
|
|
1080
|
+
type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation | TimelineMoleculeDisposal | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
|
|
1081
|
+
type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
1082
|
+
/** The unique identifier of the timeline */
|
|
1132
1083
|
key: string;
|
|
1133
|
-
/**
|
|
1134
|
-
|
|
1135
|
-
/**
|
|
1136
|
-
|
|
1137
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
1138
|
-
__T?: T;
|
|
1084
|
+
/** The managed atoms (and families of atoms) to record */
|
|
1085
|
+
scope: ManagedAtom[];
|
|
1086
|
+
/** A function that determines whether a given update should be recorded */
|
|
1087
|
+
shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
|
|
1139
1088
|
};
|
|
1140
|
-
/** @public */
|
|
1141
|
-
type PureSelectorToken<T, K extends Canonical = any> = ReadonlyPureSelectorToken<T, K> | WritablePureSelectorToken<T, K>;
|
|
1142
|
-
/** @public */
|
|
1143
|
-
type HeldSelectorToken<T, K extends Canonical = any> = ReadonlyHeldSelectorToken<T, K> | WritableHeldSelectorToken<T, K>;
|
|
1144
|
-
/** @public */
|
|
1145
|
-
type ReadonlySelectorToken<T, K extends Canonical = any> = ReadonlyHeldSelectorToken<T, K> | ReadonlyPureSelectorToken<T, K>;
|
|
1146
|
-
/** @public */
|
|
1147
|
-
type WritableSelectorToken<T, K extends Canonical = any> = WritableHeldSelectorToken<T, K> | WritablePureSelectorToken<T, K>;
|
|
1148
|
-
/** @public */
|
|
1149
|
-
type SelectorToken<T, K extends Canonical = any> = ReadonlyHeldSelectorToken<T, K> | ReadonlyPureSelectorToken<T, K> | WritableHeldSelectorToken<T, K> | WritablePureSelectorToken<T, K>;
|
|
1150
|
-
/**
|
|
1151
|
-
* @public
|
|
1152
|
-
* These states can be set.
|
|
1153
|
-
*/
|
|
1154
|
-
type WritableToken<T, K extends Canonical = any> = AtomToken<T, K> | WritableSelectorToken<T, K>;
|
|
1155
|
-
/**
|
|
1156
|
-
* @public
|
|
1157
|
-
* These states cannot be set.
|
|
1158
|
-
*/
|
|
1159
|
-
type ReadableToken<T, K extends Canonical = any> = AtomToken<T, K> | SelectorToken<T, K>;
|
|
1160
|
-
/**
|
|
1161
|
-
* @public
|
|
1162
|
-
* States belonging to this family can be set.
|
|
1163
|
-
*/
|
|
1164
|
-
type WritableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
|
|
1165
|
-
/**
|
|
1166
|
-
* @public
|
|
1167
|
-
* States belonging to this family cannot be set.
|
|
1168
|
-
*/
|
|
1169
|
-
type ReadableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
|
|
1170
1089
|
/**
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
1090
|
+
* Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms
|
|
1091
|
+
* @param options - {@link TimelineOptions}
|
|
1092
|
+
* @returns A reference to the timeline created: a {@link TimelineToken}
|
|
1173
1093
|
*/
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
/** The family member's unique identifier, in the form of a string. */
|
|
1178
|
-
subKey: stringified<K>;
|
|
1179
|
-
};
|
|
1094
|
+
declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region src/main/index.d.ts
|
|
1180
1097
|
/**
|
|
1181
|
-
* @public
|
|
1182
1098
|
* Loadable is used to type atoms or selectors that may at some point be initialized to or set to a {@link Promise}.
|
|
1183
1099
|
*
|
|
1184
1100
|
* 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.
|
|
@@ -1187,5 +1103,5 @@ type FamilyMetadata<K extends Canonical = any> = {
|
|
|
1187
1103
|
*/
|
|
1188
1104
|
type Loadable<T> = Promise<T> | T;
|
|
1189
1105
|
//#endregion
|
|
1190
|
-
export { $claim, Above, ActorToolkit, Anarchy, AtomDisposal, AtomEffect, AtomFamilyToken, AtomIOLogger, AtomIOToken, AtomOnly, AtomToken, Below, Claim, CompoundFrom, CompoundTypedKey, Effectors, FamilyMetadata,
|
|
1106
|
+
export { $claim, Above, ActorToolkit, Anarchy, AtomDisposal, AtomEffect, AtomFamilyToken, AtomIOLogger, AtomIOToken, AtomOnly, AtomToken, Below, Claim, CompoundFrom, CompoundTypedKey, Effectors, FamilyMetadata, HeldSelectorFamilyToken, HeldSelectorToken, Hierarchy, JoinOptions, JoinStates, JoinToken, KeyedStateUpdate, LOG_LEVELS, Loadable, LogFilter, LogFn, LogLevel, Logger, LoggerIcon, MoleculeCreation, MoleculeDisposal, MoleculeTransfer, MutableAtomFamilyOptions, MutableAtomFamilyToken, MutableAtomOptions, MutableAtomToken, Mutuals, PureSelectorFamilyToken, PureSelectorToken, Read, ReadableFamilyToken, ReadableToken, ReaderToolkit, ReadonlyHeldSelectorFamilyOptions, ReadonlyHeldSelectorFamilyToken, ReadonlyHeldSelectorOptions, ReadonlyHeldSelectorToken, ReadonlyPureSelectorFamilyOptions, ReadonlyPureSelectorFamilyToken, ReadonlyPureSelectorOptions, ReadonlyPureSelectorToken, ReadonlySelectorFamilyToken, ReadonlySelectorToken, Realm, RegularAtomFamilyOptions, RegularAtomFamilyToken, RegularAtomOptions, RegularAtomToken, SelectorDisposal, SelectorFamilyToken, SelectorToken, Setter, Silo, SingularTypedKey, StateCreation, StateDisposal, StateUpdate, T$, TimelineManageable, TimelineOptions, TimelineToken, TimelineUpdate, TokenDenomination, TokenType, Transact, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateContent, TransactionUpdateHandler, TypeTag, TypedKey, UpdateHandler, Vassal, WritableFamilyToken, WritableHeldSelectorFamilyOptions, WritableHeldSelectorFamilyToken, WritableHeldSelectorOptions, WritableHeldSelectorToken, WritablePureSelectorFamilyOptions, WritablePureSelectorFamilyToken, WritablePureSelectorOptions, WritablePureSelectorToken, WritableSelectorFamilyToken, WritableSelectorToken, WritableToken, Write, WriterToolkit, atom, atomFamily, belongsTo, disposeState, editRelations, findRelations, findState, getInternalRelations, getState, isToken, join, mutableAtom, mutableAtomFamily, redo, resetState, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
|
1191
1107
|
//# sourceMappingURL=index.d.ts.map
|