atom.io 0.40.0 → 0.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data/index.d.ts +1 -1
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/internal/index.d.ts +205 -196
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +145 -107
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +6 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +93 -66
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +16 -13
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +14 -14
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.js +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +3 -3
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/data/struct.ts +2 -2
- package/src/internal/atom/create-regular-atom.ts +11 -9
- package/src/internal/atom/dispose-atom.ts +11 -8
- package/src/internal/atom/has-role.ts +1 -1
- package/src/internal/caching.ts +15 -15
- package/src/internal/events/ingest-creation-disposal.ts +1 -1
- package/src/internal/families/create-readonly-held-selector-family.ts +3 -4
- package/src/internal/families/create-readonly-pure-selector-family.ts +25 -23
- package/src/internal/families/create-regular-atom-family.ts +21 -15
- package/src/internal/families/create-selector-family.ts +15 -15
- package/src/internal/families/create-writable-held-selector-family.ts +2 -2
- package/src/internal/families/create-writable-pure-selector-family.ts +25 -21
- package/src/internal/families/dispose-from-store.ts +17 -7
- package/src/internal/families/find-in-store.ts +23 -23
- package/src/internal/families/get-family-of-token.ts +17 -17
- package/src/internal/families/mint-in-store.ts +10 -10
- package/src/internal/families/seek-in-store.ts +26 -26
- package/src/internal/get-state/get-fallback.ts +8 -8
- package/src/internal/get-state/get-from-store.ts +20 -8
- package/src/internal/get-state/read-or-compute-value.ts +78 -14
- package/src/internal/get-state/reduce-reference.ts +10 -10
- package/src/internal/index.ts +65 -60
- package/src/internal/install-into-store.ts +2 -1
- package/src/internal/join/create-join.ts +2 -2
- package/src/internal/join/find-relations-in-store.ts +2 -2
- package/src/internal/join/get-internal-relations-from-store.ts +2 -2
- package/src/internal/join/get-join.ts +5 -2
- package/src/internal/join/join-internal.ts +30 -26
- package/src/internal/lineage.ts +12 -1
- package/src/internal/molecule.ts +64 -36
- package/src/internal/mutable/create-mutable-atom-family.ts +5 -5
- package/src/internal/mutable/create-mutable-atom.ts +2 -2
- package/src/internal/mutable/get-json-family.ts +3 -2
- package/src/internal/mutable/get-update-family.ts +7 -5
- package/src/internal/mutable/tracker-family.ts +8 -4
- package/src/internal/mutable/tracker.ts +5 -1
- package/src/internal/operation.ts +4 -2
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +10 -8
- package/src/internal/selector/create-standalone-selector.ts +10 -10
- package/src/internal/selector/create-writable-held-selector.ts +2 -2
- package/src/internal/selector/create-writable-pure-selector.ts +11 -9
- package/src/internal/selector/dispose-selector.ts +2 -2
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/internal/selector/trace-selector-atoms.ts +3 -3
- package/src/internal/selector/update-selector-atoms.ts +1 -1
- package/src/internal/set-state/become.ts +1 -3
- package/src/internal/set-state/dispatch-state-update.ts +10 -6
- package/src/internal/set-state/evict-downstream.ts +4 -1
- package/src/internal/set-state/operate-on-store.ts +16 -10
- package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
- package/src/internal/set-state/reset-in-store.ts +17 -16
- package/src/internal/set-state/set-atom-or-selector.ts +1 -1
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/set-state/set-into-store.ts +34 -7
- package/src/internal/set-state/set-selector.ts +1 -1
- package/src/internal/store/deposit.ts +38 -30
- package/src/internal/store/mint-or-counterfeit.ts +23 -23
- package/src/internal/store/store.ts +23 -21
- package/src/internal/store/withdraw.ts +68 -62
- package/src/internal/subscribe/recall-state.ts +4 -1
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
- package/src/internal/subscribe/subscribe-to-state.ts +4 -4
- package/src/internal/timeline/create-timeline.ts +11 -10
- package/src/internal/timeline/time-travel.ts +4 -3
- package/src/internal/transaction/abort-transaction.ts +3 -15
- package/src/internal/transaction/act-upon-store.ts +1 -5
- package/src/internal/transaction/apply-transaction.ts +3 -15
- package/src/internal/transaction/assign-transaction-to-continuity.ts +2 -7
- package/src/internal/transaction/build-transaction.ts +2 -3
- package/src/internal/transaction/create-transaction.ts +5 -6
- package/src/internal/transaction/get-epoch-number.ts +1 -7
- package/src/internal/transaction/set-epoch-number.ts +4 -12
- package/src/introspection/attach-atom-index.ts +2 -2
- package/src/introspection/attach-introspection-states.ts +4 -2
- package/src/introspection/attach-selector-index.ts +4 -2
- package/src/introspection/attach-timeline-family.ts +15 -13
- package/src/introspection/attach-timeline-index.ts +1 -1
- package/src/introspection/attach-transaction-index.ts +1 -1
- package/src/introspection/attach-transaction-logs.ts +6 -4
- package/src/introspection/attach-type-selectors.ts +4 -3
- package/src/introspection/index.ts +3 -5
- package/src/main/atom.ts +14 -8
- package/src/main/dispose-state.ts +1 -5
- package/src/main/events.ts +26 -26
- package/src/main/get-state.ts +10 -11
- package/src/main/realm.ts +36 -12
- package/src/main/reset-state.ts +5 -9
- package/src/main/selector.ts +40 -24
- package/src/main/set-state.ts +8 -11
- package/src/main/silo.ts +4 -3
- package/src/main/timeline.ts +5 -3
- package/src/main/tokens.ts +72 -44
- package/src/main/validators.ts +4 -4
- package/src/react/parse-state-overloads.ts +10 -10
- package/src/react/store-context.tsx +3 -3
- package/src/react/use-i.ts +6 -6
- package/src/react/use-loadable.ts +15 -15
- package/src/react/use-o.ts +9 -9
- package/src/react-devtools/Button.tsx +3 -2
- package/src/react-devtools/StateEditor.tsx +5 -3
- package/src/react-devtools/StateIndex.tsx +6 -4
- package/src/react-devtools/TimelineIndex.tsx +0 -2
- package/src/react-devtools/Updates.tsx +1 -1
- package/src/react-devtools/store.ts +18 -9
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +4 -8
- package/src/realtime-client/sync-continuity.ts +2 -2
- package/src/realtime-server/index.ts +2 -2
package/src/main/silo.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { findState } from "atom.io"
|
|
2
|
+
import type { RootStore } from "atom.io/internal"
|
|
2
3
|
import {
|
|
3
4
|
actUponStore,
|
|
4
5
|
arbitrary,
|
|
@@ -38,7 +39,7 @@ import type { selector, selectorFamily } from "./selector"
|
|
|
38
39
|
import type { runTransaction, transaction } from "./transaction"
|
|
39
40
|
|
|
40
41
|
export class Silo {
|
|
41
|
-
public store:
|
|
42
|
+
public store: RootStore
|
|
42
43
|
public atom: typeof atom
|
|
43
44
|
public mutableAtom: typeof mutableAtom
|
|
44
45
|
public atomFamily: typeof atomFamily
|
|
@@ -56,10 +57,10 @@ export class Silo {
|
|
|
56
57
|
public undo: typeof undo
|
|
57
58
|
public redo: typeof redo
|
|
58
59
|
public runTransaction: typeof runTransaction
|
|
59
|
-
public install: (tokens: AtomIOToken[], store?:
|
|
60
|
+
public install: (tokens: AtomIOToken[], store?: RootStore) => void
|
|
60
61
|
|
|
61
62
|
public constructor(config: Store[`config`], fromStore: Store | null = null) {
|
|
62
|
-
const s = (this.store = new Store(config, fromStore))
|
|
63
|
+
const s = (this.store = new Store(config, fromStore) as RootStore)
|
|
63
64
|
this.atom = ((options: Parameters<typeof atom>[0]) =>
|
|
64
65
|
createRegularAtom(s, options, undefined)) as typeof atom
|
|
65
66
|
this.mutableAtom = ((options: Parameters<typeof mutableAtom>[0]) =>
|
package/src/main/timeline.ts
CHANGED
|
@@ -2,13 +2,15 @@ import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
|
|
|
2
2
|
|
|
3
3
|
import type { AtomFamilyToken, AtomToken, TimelineToken } from "."
|
|
4
4
|
|
|
5
|
-
export type TimelineManageable =
|
|
5
|
+
export type TimelineManageable =
|
|
6
|
+
| AtomFamilyToken<any, any, any>
|
|
7
|
+
| AtomToken<any, any, any>
|
|
6
8
|
export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
|
|
7
9
|
any,
|
|
8
10
|
any
|
|
9
11
|
>
|
|
10
|
-
? AtomToken<any>
|
|
11
|
-
: M extends AtomToken<any>
|
|
12
|
+
? AtomToken<any, any, any>
|
|
13
|
+
: M extends AtomToken<any, any, any>
|
|
12
14
|
? M
|
|
13
15
|
: never
|
|
14
16
|
|
package/src/main/tokens.ts
CHANGED
|
@@ -13,31 +13,31 @@ import type { Canonical, stringified } from "atom.io/json"
|
|
|
13
13
|
* Tokens are fully serializable, so they can be passed between processes.
|
|
14
14
|
*/
|
|
15
15
|
export type AtomIOToken =
|
|
16
|
-
| ReadableFamilyToken<any, any>
|
|
17
|
-
| ReadableToken<any>
|
|
16
|
+
| ReadableFamilyToken<any, any, any>
|
|
17
|
+
| ReadableToken<any, any, any>
|
|
18
18
|
| TimelineToken<any>
|
|
19
19
|
| TransactionToken<any>
|
|
20
20
|
|
|
21
|
-
export type ReadableToken<T, K extends Canonical = any> =
|
|
22
|
-
| AtomToken<T, K>
|
|
23
|
-
| SelectorToken<T, K>
|
|
21
|
+
export type ReadableToken<T, K extends Canonical = any, E = never> =
|
|
22
|
+
| AtomToken<T, K, E>
|
|
23
|
+
| SelectorToken<T, K, E>
|
|
24
24
|
|
|
25
|
-
export type WritableToken<T, K extends Canonical = any> =
|
|
26
|
-
| AtomToken<T, K>
|
|
27
|
-
| WritableSelectorToken<T, K>
|
|
25
|
+
export type WritableToken<T, K extends Canonical = any, E = never> =
|
|
26
|
+
| AtomToken<T, K, E>
|
|
27
|
+
| WritableSelectorToken<T, K, E>
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* States belonging to this family can be read from the store.
|
|
31
31
|
*/
|
|
32
|
-
export type ReadableFamilyToken<T, K extends Canonical> =
|
|
33
|
-
| AtomFamilyToken<T, K>
|
|
34
|
-
| SelectorFamilyToken<T, K>
|
|
32
|
+
export type ReadableFamilyToken<T, K extends Canonical, E = never> =
|
|
33
|
+
| AtomFamilyToken<T, K, E>
|
|
34
|
+
| SelectorFamilyToken<T, K, E>
|
|
35
35
|
/**
|
|
36
36
|
* States belonging to this family can be written directly.
|
|
37
37
|
*/
|
|
38
|
-
export type WritableFamilyToken<T, K extends Canonical> =
|
|
39
|
-
| AtomFamilyToken<T, K>
|
|
40
|
-
| WritableSelectorFamilyToken<T, K>
|
|
38
|
+
export type WritableFamilyToken<T, K extends Canonical, E = never> =
|
|
39
|
+
| AtomFamilyToken<T, K, E>
|
|
40
|
+
| WritableSelectorFamilyToken<T, K, E>
|
|
41
41
|
|
|
42
42
|
export type TimelineToken<M> = {
|
|
43
43
|
/** The unique identifier of the timeline */
|
|
@@ -57,10 +57,10 @@ export type TransactionToken<F extends Fn> = {
|
|
|
57
57
|
__F?: F
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export type AtomToken<T, K extends Canonical = any> =
|
|
60
|
+
export type AtomToken<T, K extends Canonical = any, E = never> =
|
|
61
61
|
| MutableAtomToken<T extends Transceiver<any, any, any> ? T : never, K>
|
|
62
|
-
| RegularAtomToken<T, K>
|
|
63
|
-
export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
62
|
+
| RegularAtomToken<T, K, E>
|
|
63
|
+
export type RegularAtomToken<T, K extends Canonical = any, E = never> = {
|
|
64
64
|
/** The unique identifier of the atom. */
|
|
65
65
|
key: string
|
|
66
66
|
/** Discriminator. */
|
|
@@ -69,6 +69,8 @@ export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
|
69
69
|
family?: FamilyMetadata<K>
|
|
70
70
|
/** Never present. This is a marker that preserves the type of the atom's value. */
|
|
71
71
|
__T?: T
|
|
72
|
+
/** Never present. This is a marker that preserves the type of errors this atom is capable of catching and setting as its value. */
|
|
73
|
+
__E?: E
|
|
72
74
|
}
|
|
73
75
|
export type MutableAtomToken<
|
|
74
76
|
T extends Transceiver<any, any, any>,
|
|
@@ -84,23 +86,27 @@ export type MutableAtomToken<
|
|
|
84
86
|
__J?: AsJSON<T>
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
export type SelectorToken<T, K extends Canonical = any> =
|
|
88
|
-
| ReadonlySelectorToken<T, K>
|
|
89
|
-
| WritableSelectorToken<T, K>
|
|
90
|
-
export type ReadonlySelectorToken<T, K extends Canonical = any> =
|
|
89
|
+
export type SelectorToken<T, K extends Canonical = any, E = never> =
|
|
90
|
+
| ReadonlySelectorToken<T, K, E>
|
|
91
|
+
| WritableSelectorToken<T, K, E>
|
|
92
|
+
export type ReadonlySelectorToken<T, K extends Canonical = any, E = never> =
|
|
91
93
|
| ReadonlyHeldSelectorToken<T, K>
|
|
92
|
-
| ReadonlyPureSelectorToken<T, K>
|
|
93
|
-
export type WritableSelectorToken<T, K extends Canonical = any> =
|
|
94
|
+
| ReadonlyPureSelectorToken<T, K, E>
|
|
95
|
+
export type WritableSelectorToken<T, K extends Canonical = any, E = never> =
|
|
94
96
|
| WritableHeldSelectorToken<T, K>
|
|
95
|
-
| WritablePureSelectorToken<T, K>
|
|
96
|
-
export type PureSelectorToken<T, K extends Canonical = any> =
|
|
97
|
-
| ReadonlyPureSelectorToken<T, K>
|
|
98
|
-
| WritablePureSelectorToken<T, K>
|
|
97
|
+
| WritablePureSelectorToken<T, K, E>
|
|
98
|
+
export type PureSelectorToken<T, K extends Canonical = any, E = never> =
|
|
99
|
+
| ReadonlyPureSelectorToken<T, K, E>
|
|
100
|
+
| WritablePureSelectorToken<T, K, E>
|
|
99
101
|
export type HeldSelectorToken<T, K extends Canonical = any> =
|
|
100
102
|
| ReadonlyHeldSelectorToken<T, K>
|
|
101
103
|
| WritableHeldSelectorToken<T, K>
|
|
102
104
|
|
|
103
|
-
export type WritablePureSelectorToken<
|
|
105
|
+
export type WritablePureSelectorToken<
|
|
106
|
+
T,
|
|
107
|
+
K extends Canonical = any,
|
|
108
|
+
E = never,
|
|
109
|
+
> = {
|
|
104
110
|
/** The unique identifier of the selector. */
|
|
105
111
|
key: string
|
|
106
112
|
/** Discriminator. */
|
|
@@ -109,6 +115,8 @@ export type WritablePureSelectorToken<T, K extends Canonical = any> = {
|
|
|
109
115
|
family?: FamilyMetadata<K>
|
|
110
116
|
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
111
117
|
__T?: T
|
|
118
|
+
/** Never present. This is a marker that preserves the type of errors this selector is capable of catching and setting as its value. */
|
|
119
|
+
__E?: E
|
|
112
120
|
}
|
|
113
121
|
export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
|
|
114
122
|
/** The unique identifier of the selector. */
|
|
@@ -120,7 +128,11 @@ export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
|
|
|
120
128
|
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
121
129
|
__T?: T
|
|
122
130
|
}
|
|
123
|
-
export type ReadonlyPureSelectorToken<
|
|
131
|
+
export type ReadonlyPureSelectorToken<
|
|
132
|
+
T,
|
|
133
|
+
K extends Canonical = any,
|
|
134
|
+
E = never,
|
|
135
|
+
> = {
|
|
124
136
|
/** The unique identifier of the selector. */
|
|
125
137
|
key: string
|
|
126
138
|
/** Discriminator. */
|
|
@@ -129,6 +141,8 @@ export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
|
|
|
129
141
|
family?: FamilyMetadata<K>
|
|
130
142
|
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
131
143
|
__T?: T
|
|
144
|
+
/** Never present. This is a marker that preserves the type of errors this selector is capable of catching and setting as its value. */
|
|
145
|
+
__E?: E
|
|
132
146
|
}
|
|
133
147
|
export type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
|
|
134
148
|
/** The unique identifier of the selector. */
|
|
@@ -151,10 +165,10 @@ export type FamilyMetadata<K extends Canonical = any> = {
|
|
|
151
165
|
subKey: stringified<K>
|
|
152
166
|
}
|
|
153
167
|
|
|
154
|
-
export type AtomFamilyToken<T, K extends Canonical = Canonical> =
|
|
168
|
+
export type AtomFamilyToken<T, K extends Canonical = Canonical, E = never> =
|
|
155
169
|
| MutableAtomFamilyToken<T extends Transceiver<any, any, any> ? T : never, K>
|
|
156
|
-
| RegularAtomFamilyToken<T, K>
|
|
157
|
-
export type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
170
|
+
| RegularAtomFamilyToken<T, K, E>
|
|
171
|
+
export type RegularAtomFamilyToken<T, K extends Canonical, E = never> = {
|
|
158
172
|
/** The unique identifier of the atom family */
|
|
159
173
|
key: string
|
|
160
174
|
/** Discriminator */
|
|
@@ -163,6 +177,8 @@ export type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
|
163
177
|
__T?: T
|
|
164
178
|
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
165
179
|
__K?: K
|
|
180
|
+
/** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */
|
|
181
|
+
__E?: E
|
|
166
182
|
}
|
|
167
183
|
export type MutableAtomFamilyToken<
|
|
168
184
|
T extends Transceiver<any, any, any>,
|
|
@@ -178,23 +194,27 @@ export type MutableAtomFamilyToken<
|
|
|
178
194
|
__K?: K
|
|
179
195
|
}
|
|
180
196
|
|
|
181
|
-
export type SelectorFamilyToken<T, K extends Canonical> =
|
|
182
|
-
| ReadonlySelectorFamilyToken<T, K>
|
|
183
|
-
| WritableSelectorFamilyToken<T, K>
|
|
184
|
-
export type ReadonlySelectorFamilyToken<T, K extends Canonical> =
|
|
197
|
+
export type SelectorFamilyToken<T, K extends Canonical, E = never> =
|
|
198
|
+
| ReadonlySelectorFamilyToken<T, K, E>
|
|
199
|
+
| WritableSelectorFamilyToken<T, K, E>
|
|
200
|
+
export type ReadonlySelectorFamilyToken<T, K extends Canonical, E = never> =
|
|
185
201
|
| ReadonlyHeldSelectorFamilyToken<T, K>
|
|
186
|
-
| ReadonlyPureSelectorFamilyToken<T, K>
|
|
187
|
-
export type WritableSelectorFamilyToken<T, K extends Canonical> =
|
|
202
|
+
| ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
203
|
+
export type WritableSelectorFamilyToken<T, K extends Canonical, E = never> =
|
|
188
204
|
| WritableHeldSelectorFamilyToken<T, K>
|
|
189
|
-
| WritablePureSelectorFamilyToken<T, K>
|
|
190
|
-
export type PureSelectorFamilyToken<T, K extends Canonical> =
|
|
191
|
-
| ReadonlyPureSelectorFamilyToken<T, K>
|
|
192
|
-
| WritablePureSelectorFamilyToken<T, K>
|
|
205
|
+
| WritablePureSelectorFamilyToken<T, K, E>
|
|
206
|
+
export type PureSelectorFamilyToken<T, K extends Canonical, E = never> =
|
|
207
|
+
| ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
208
|
+
| WritablePureSelectorFamilyToken<T, K, E>
|
|
193
209
|
export type HeldSelectorFamilyToken<T, K extends Canonical> =
|
|
194
210
|
| ReadonlyHeldSelectorFamilyToken<T, K>
|
|
195
211
|
| WritableHeldSelectorFamilyToken<T, K>
|
|
196
212
|
|
|
197
|
-
export type WritablePureSelectorFamilyToken<
|
|
213
|
+
export type WritablePureSelectorFamilyToken<
|
|
214
|
+
T,
|
|
215
|
+
K extends Canonical,
|
|
216
|
+
E = never,
|
|
217
|
+
> = {
|
|
198
218
|
/** The unique identifier of the family */
|
|
199
219
|
key: string
|
|
200
220
|
/** Discriminator */
|
|
@@ -203,8 +223,14 @@ export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
|
|
|
203
223
|
__T?: T
|
|
204
224
|
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
205
225
|
__K?: K
|
|
226
|
+
/** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */
|
|
227
|
+
__E?: E
|
|
206
228
|
}
|
|
207
|
-
export type ReadonlyPureSelectorFamilyToken<
|
|
229
|
+
export type ReadonlyPureSelectorFamilyToken<
|
|
230
|
+
T,
|
|
231
|
+
K extends Canonical,
|
|
232
|
+
E = never,
|
|
233
|
+
> = {
|
|
208
234
|
/** The unique identifier of the family */
|
|
209
235
|
key: string
|
|
210
236
|
/** Discriminator */
|
|
@@ -213,6 +239,8 @@ export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
|
|
|
213
239
|
__T?: T
|
|
214
240
|
/** Never present. This is a marker that preserves the type of keys used for each family member */
|
|
215
241
|
__K?: K
|
|
242
|
+
/** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */
|
|
243
|
+
__E?: E
|
|
216
244
|
}
|
|
217
245
|
export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
|
|
218
246
|
/** The unique identifier of the family */
|
package/src/main/validators.ts
CHANGED
|
@@ -16,8 +16,8 @@ import type {
|
|
|
16
16
|
|
|
17
17
|
export type TokenType<
|
|
18
18
|
Comparison extends
|
|
19
|
-
| ReadableFamilyToken<any, any>
|
|
20
|
-
| ReadableToken<any>
|
|
19
|
+
| ReadableFamilyToken<any, any, any>
|
|
20
|
+
| ReadableToken<any, any, any>
|
|
21
21
|
| TransactionToken<any>,
|
|
22
22
|
> = Comparison extends ReadableToken<infer RepresentedValue>
|
|
23
23
|
? RepresentedValue
|
|
@@ -27,9 +27,9 @@ export type TokenType<
|
|
|
27
27
|
? Fn
|
|
28
28
|
: never
|
|
29
29
|
|
|
30
|
-
export function isToken<KnownToken extends RegularAtomToken<any>>(
|
|
30
|
+
export function isToken<KnownToken extends RegularAtomToken<any, any, any>>(
|
|
31
31
|
knownToken: KnownToken,
|
|
32
|
-
unknownToken: ReadableToken<any>,
|
|
32
|
+
unknownToken: ReadableToken<any, any, any>,
|
|
33
33
|
): unknownToken is RegularAtomToken<TokenType<KnownToken>>
|
|
34
34
|
export function isToken<KnownToken extends MutableAtomToken<any, any>>(
|
|
35
35
|
knownToken: KnownToken,
|
|
@@ -8,21 +8,21 @@ import type { Store } from "atom.io/internal"
|
|
|
8
8
|
import { findInStore } from "atom.io/internal"
|
|
9
9
|
import type { Canonical } from "atom.io/json"
|
|
10
10
|
|
|
11
|
-
export function parseStateOverloads<T, K extends Canonical>(
|
|
11
|
+
export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
|
|
12
12
|
store: Store,
|
|
13
|
-
...rest: [WritableFamilyToken<T, K>,
|
|
14
|
-
): WritableToken<T>
|
|
13
|
+
...rest: [WritableFamilyToken<T, K, E>, Key] | [WritableToken<T, any, E>]
|
|
14
|
+
): WritableToken<T, K, E>
|
|
15
15
|
|
|
16
|
-
export function parseStateOverloads<T, K extends Canonical>(
|
|
16
|
+
export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
|
|
17
17
|
store: Store,
|
|
18
|
-
...rest: [ReadableFamilyToken<T, K>,
|
|
19
|
-
): ReadableToken<T>
|
|
18
|
+
...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
|
|
19
|
+
): ReadableToken<T, K, E>
|
|
20
20
|
|
|
21
|
-
export function parseStateOverloads<T, K extends Canonical>(
|
|
21
|
+
export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
|
|
22
22
|
store: Store,
|
|
23
|
-
...rest: [ReadableFamilyToken<T, K>,
|
|
24
|
-
): ReadableToken<T> {
|
|
25
|
-
let token: ReadableToken<any>
|
|
23
|
+
...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
|
|
24
|
+
): ReadableToken<T, K, E> {
|
|
25
|
+
let token: ReadableToken<any, any, any>
|
|
26
26
|
if (rest.length === 2) {
|
|
27
27
|
const family = rest[0]
|
|
28
28
|
const key = rest[1]
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RootStore } from "atom.io/internal"
|
|
2
2
|
import { IMPLICIT } from "atom.io/internal"
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
|
|
5
|
-
export const StoreContext: React.Context<
|
|
5
|
+
export const StoreContext: React.Context<RootStore> = React.createContext(
|
|
6
6
|
IMPLICIT.STORE,
|
|
7
7
|
)
|
|
8
8
|
|
|
9
9
|
export const StoreProvider: React.FC<{
|
|
10
10
|
children: React.ReactNode
|
|
11
|
-
store?:
|
|
11
|
+
store?: RootStore
|
|
12
12
|
}> = ({ children, store = IMPLICIT.STORE }) => (
|
|
13
13
|
<StoreContext.Provider value={store}>{children}</StoreContext.Provider>
|
|
14
14
|
)
|
package/src/react/use-i.ts
CHANGED
|
@@ -7,16 +7,16 @@ import { parseStateOverloads } from "./parse-state-overloads"
|
|
|
7
7
|
import { StoreContext } from "./store-context"
|
|
8
8
|
|
|
9
9
|
export function useI<T>(
|
|
10
|
-
token: WritableToken<T>,
|
|
10
|
+
token: WritableToken<T, any, any>,
|
|
11
11
|
): <New extends T>(next: New | ((old: T) => New)) => void
|
|
12
12
|
|
|
13
|
-
export function useI<T, K extends Canonical>(
|
|
14
|
-
token: WritableFamilyToken<T, K>,
|
|
15
|
-
key:
|
|
13
|
+
export function useI<T, K extends Canonical, Key extends K>(
|
|
14
|
+
token: WritableFamilyToken<T, K, any>,
|
|
15
|
+
key: Key,
|
|
16
16
|
): <New extends T>(next: New | ((old: T) => New)) => void
|
|
17
17
|
|
|
18
|
-
export function useI<T, K extends Canonical>(
|
|
19
|
-
...params: [WritableFamilyToken<T, K>,
|
|
18
|
+
export function useI<T, K extends Canonical, Key extends K>(
|
|
19
|
+
...params: [WritableFamilyToken<T, K, any>, Key] | [WritableToken<T, any, any>]
|
|
20
20
|
): <New extends T>(next: New | ((old: T) => New)) => void {
|
|
21
21
|
const store = React.useContext(StoreContext)
|
|
22
22
|
const token = parseStateOverloads(store, ...params)
|
|
@@ -4,32 +4,32 @@ import type { Canonical } from "atom.io/json"
|
|
|
4
4
|
import { useO } from "atom.io/react"
|
|
5
5
|
import React from "react"
|
|
6
6
|
|
|
7
|
-
export function useLoadable<T>(
|
|
8
|
-
token: ReadableToken<Loadable<T
|
|
9
|
-
): `LOADING` | { loading: boolean; value: T }
|
|
7
|
+
export function useLoadable<T, E>(
|
|
8
|
+
token: ReadableToken<Loadable<T>, any, E>,
|
|
9
|
+
): `LOADING` | { loading: boolean; value: E | T }
|
|
10
10
|
|
|
11
|
-
export function useLoadable<T, K extends Canonical>(
|
|
12
|
-
token: ReadableFamilyToken<Loadable<T>, K>,
|
|
11
|
+
export function useLoadable<T, K extends Canonical, E>(
|
|
12
|
+
token: ReadableFamilyToken<Loadable<T>, K, E>,
|
|
13
13
|
key: K,
|
|
14
|
-
): `LOADING` | { loading: boolean; value: T }
|
|
14
|
+
): `LOADING` | { loading: boolean; value: E | T }
|
|
15
15
|
|
|
16
|
-
export function useLoadable<T, F extends T>(
|
|
17
|
-
token: ReadableToken<Loadable<T
|
|
16
|
+
export function useLoadable<T, F extends T, E>(
|
|
17
|
+
token: ReadableToken<Loadable<T>, any, E>,
|
|
18
18
|
fallback: F,
|
|
19
19
|
): { loading: boolean; value: T }
|
|
20
20
|
|
|
21
|
-
export function useLoadable<T, K extends Canonical, F extends T>(
|
|
22
|
-
token: ReadableFamilyToken<Loadable<T>, K>,
|
|
21
|
+
export function useLoadable<T, K extends Canonical, F extends T, E>(
|
|
22
|
+
token: ReadableFamilyToken<Loadable<T>, K, E>,
|
|
23
23
|
key: K,
|
|
24
24
|
fallback: F,
|
|
25
|
-
): { loading: boolean; value: T }
|
|
25
|
+
): { loading: boolean; value: E | T }
|
|
26
26
|
|
|
27
27
|
export function useLoadable(
|
|
28
28
|
...params:
|
|
29
|
-
| readonly [ReadableFamilyToken<any, Canonical>, Canonical, unknown]
|
|
30
|
-
| readonly [ReadableFamilyToken<any, Canonical>, Canonical]
|
|
31
|
-
| readonly [ReadableToken<any>, unknown]
|
|
32
|
-
| readonly [ReadableToken<any>]
|
|
29
|
+
| readonly [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]
|
|
30
|
+
| readonly [ReadableFamilyToken<any, Canonical, any>, Canonical]
|
|
31
|
+
| readonly [ReadableToken<any, any, any>, unknown]
|
|
32
|
+
| readonly [ReadableToken<any, any, any>]
|
|
33
33
|
): `LOADING` | { loading: boolean; value: unknown } {
|
|
34
34
|
let state: unknown
|
|
35
35
|
let fallback: unknown
|
package/src/react/use-o.ts
CHANGED
|
@@ -6,20 +6,20 @@ import * as React from "react"
|
|
|
6
6
|
import { parseStateOverloads } from "./parse-state-overloads"
|
|
7
7
|
import { StoreContext } from "./store-context"
|
|
8
8
|
|
|
9
|
-
export function useO<T>(token: ReadableToken<T>): T
|
|
9
|
+
export function useO<T, E>(token: ReadableToken<T, any, E>): E | T
|
|
10
10
|
|
|
11
|
-
export function useO<T, K extends Canonical>(
|
|
12
|
-
token: ReadableFamilyToken<T, K>,
|
|
13
|
-
key:
|
|
14
|
-
): T
|
|
11
|
+
export function useO<T, K extends Canonical, Key extends K, E>(
|
|
12
|
+
token: ReadableFamilyToken<T, K, E>,
|
|
13
|
+
key: Key,
|
|
14
|
+
): E | T
|
|
15
15
|
|
|
16
|
-
export function useO<T, K extends Canonical>(
|
|
17
|
-
...params: [ReadableFamilyToken<T, K>,
|
|
18
|
-
): T {
|
|
16
|
+
export function useO<T, K extends Canonical, Key extends K, E>(
|
|
17
|
+
...params: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
|
|
18
|
+
): E | T {
|
|
19
19
|
const store = React.useContext(StoreContext)
|
|
20
20
|
const token = parseStateOverloads(store, ...params)
|
|
21
21
|
const id = React.useId()
|
|
22
|
-
return React.useSyncExternalStore<T>(
|
|
22
|
+
return React.useSyncExternalStore<E | T>(
|
|
23
23
|
(dispatch) => subscribeToState(store, token, `use-o:${id}`, dispatch),
|
|
24
24
|
() => getFromStore(store, token),
|
|
25
25
|
() => getFromStore(store, token),
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { Modify } from "atom.io/internal"
|
|
2
1
|
import type { FC } from "react"
|
|
3
2
|
|
|
4
3
|
export const OpenClose: FC<{
|
|
5
4
|
isOpen: boolean
|
|
6
|
-
setIsOpen?:
|
|
5
|
+
setIsOpen?:
|
|
6
|
+
| ((next: boolean | ((prev: boolean) => boolean)) => void)
|
|
7
|
+
| undefined
|
|
7
8
|
onShiftClick?: (
|
|
8
9
|
event: React.MouseEvent<HTMLButtonElement, MouseEvent>,
|
|
9
10
|
) => boolean
|
|
@@ -5,7 +5,7 @@ import type { FC } from "react"
|
|
|
5
5
|
import { JsonEditor } from "./json-editor"
|
|
6
6
|
|
|
7
7
|
export const StateEditor: FC<{
|
|
8
|
-
token: WritableToken<unknown>
|
|
8
|
+
token: WritableToken<unknown, any, unknown>
|
|
9
9
|
}> = ({ token }) => {
|
|
10
10
|
const set = useI(token)
|
|
11
11
|
const data = useO(token)
|
|
@@ -23,7 +23,7 @@ export const StateEditor: FC<{
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const ReadonlySelectorViewer: FC<{
|
|
26
|
-
token: ReadonlySelectorToken<unknown>
|
|
26
|
+
token: ReadonlySelectorToken<unknown, any, unknown>
|
|
27
27
|
}> = ({ token }) => {
|
|
28
28
|
const data = useO(token)
|
|
29
29
|
const metaPath = token.family
|
|
@@ -41,7 +41,9 @@ export const ReadonlySelectorViewer: FC<{
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export const StoreEditor: FC<{
|
|
44
|
-
token:
|
|
44
|
+
token:
|
|
45
|
+
| ReadonlySelectorToken<unknown, any, unknown>
|
|
46
|
+
| WritableToken<unknown, any, unknown>
|
|
45
47
|
}> = ({ token }) => {
|
|
46
48
|
switch (token.type) {
|
|
47
49
|
case `readonly_pure_selector`:
|
|
@@ -25,7 +25,7 @@ import { DevtoolsContext } from "./store"
|
|
|
25
25
|
/* eslint-disable no-console */
|
|
26
26
|
|
|
27
27
|
export const StateIndexLeafNode: FC<{
|
|
28
|
-
node: ReadableToken<unknown>
|
|
28
|
+
node: ReadableToken<unknown, any, unknown>
|
|
29
29
|
isOpenState: RegularAtomToken<boolean>
|
|
30
30
|
typeState: ReadonlyPureSelectorToken<Loadable<string>>
|
|
31
31
|
dispose?: (() => void) | undefined
|
|
@@ -95,7 +95,7 @@ export const StateIndexLeafNode: FC<{
|
|
|
95
95
|
)
|
|
96
96
|
}
|
|
97
97
|
export const StateIndexTreeNode: FC<{
|
|
98
|
-
node: FamilyNode<ReadableToken<unknown>>
|
|
98
|
+
node: FamilyNode<ReadableToken<unknown, any, unknown>>
|
|
99
99
|
isOpenState: RegularAtomToken<boolean>
|
|
100
100
|
}> = ({ node, isOpenState }) => {
|
|
101
101
|
const setIsOpen = useI(isOpenState)
|
|
@@ -147,7 +147,9 @@ export const StateIndexTreeNode: FC<{
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
export const StateIndexNode: FC<{
|
|
150
|
-
node:
|
|
150
|
+
node:
|
|
151
|
+
| FamilyNode<ReadableToken<unknown, any, unknown>>
|
|
152
|
+
| ReadableToken<unknown, any, unknown>
|
|
151
153
|
isOpenState: RegularAtomToken<boolean>
|
|
152
154
|
typeState: ReadonlyPureSelectorToken<Loadable<string>>
|
|
153
155
|
dispose?: () => void
|
|
@@ -169,7 +171,7 @@ export const StateIndexNode: FC<{
|
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
export const StateIndex: FC<{
|
|
172
|
-
tokenIndex: AtomToken<WritableTokenIndex<ReadableToken<unknown>>>
|
|
174
|
+
tokenIndex: AtomToken<WritableTokenIndex<ReadableToken<unknown, any, unknown>>>
|
|
173
175
|
}> = ({ tokenIndex }) => {
|
|
174
176
|
const tokenIds = useO(tokenIndex)
|
|
175
177
|
|
|
@@ -64,8 +64,6 @@ export const TimelineLog: FC<{
|
|
|
64
64
|
{isOpen ? (
|
|
65
65
|
<main>
|
|
66
66
|
{timeline.history.map((update, index) =>
|
|
67
|
-
update.type !== `molecule_creation` &&
|
|
68
|
-
update.type !== `molecule_disposal` &&
|
|
69
67
|
update.type !== `state_creation` &&
|
|
70
68
|
update.type !== `state_disposal` ? (
|
|
71
69
|
<Fragment key={update.token.key + index + timeline.at}>
|
|
@@ -5,11 +5,11 @@ import type {
|
|
|
5
5
|
SelectorToken,
|
|
6
6
|
TransactionToken,
|
|
7
7
|
} from "atom.io"
|
|
8
|
+
import type { RootStore, Store } from "atom.io/internal"
|
|
8
9
|
import {
|
|
9
10
|
createRegularAtom,
|
|
10
11
|
createRegularAtomFamily,
|
|
11
12
|
createTransaction,
|
|
12
|
-
type Store,
|
|
13
13
|
} from "atom.io/internal"
|
|
14
14
|
import type {
|
|
15
15
|
IntrospectionStates,
|
|
@@ -34,12 +34,12 @@ export type DevtoolsStates = {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function attachDevtoolsStates(
|
|
37
|
-
store:
|
|
37
|
+
store: RootStore,
|
|
38
38
|
hideByDefault = false,
|
|
39
39
|
): DevtoolsStates & IntrospectionStates & { store: Store } {
|
|
40
40
|
const introspectionStates = attachIntrospectionStates(store)
|
|
41
41
|
|
|
42
|
-
const devtoolsAreHiddenAtom = createRegularAtom<boolean>(
|
|
42
|
+
const devtoolsAreHiddenAtom = createRegularAtom<boolean, never, never>(
|
|
43
43
|
store,
|
|
44
44
|
{
|
|
45
45
|
key: `🔍 Devtools Are Hidden`,
|
|
@@ -62,7 +62,7 @@ export function attachDevtoolsStates(
|
|
|
62
62
|
undefined,
|
|
63
63
|
)
|
|
64
64
|
|
|
65
|
-
const devtoolsAreOpenAtom = createRegularAtom<boolean>(
|
|
65
|
+
const devtoolsAreOpenAtom = createRegularAtom<boolean, never, never>(
|
|
66
66
|
store,
|
|
67
67
|
{
|
|
68
68
|
key: `🔍 Devtools Are Open`,
|
|
@@ -75,7 +75,11 @@ export function attachDevtoolsStates(
|
|
|
75
75
|
undefined,
|
|
76
76
|
)
|
|
77
77
|
|
|
78
|
-
const devtoolsViewSelectionAtom = createRegularAtom<
|
|
78
|
+
const devtoolsViewSelectionAtom = createRegularAtom<
|
|
79
|
+
DevtoolsView,
|
|
80
|
+
never,
|
|
81
|
+
never
|
|
82
|
+
>(
|
|
79
83
|
store,
|
|
80
84
|
{
|
|
81
85
|
key: `🔍 Devtools View Selection`,
|
|
@@ -88,7 +92,11 @@ export function attachDevtoolsStates(
|
|
|
88
92
|
undefined,
|
|
89
93
|
)
|
|
90
94
|
|
|
91
|
-
const devtoolsViewOptionsAtom = createRegularAtom<
|
|
95
|
+
const devtoolsViewOptionsAtom = createRegularAtom<
|
|
96
|
+
DevtoolsView[],
|
|
97
|
+
never,
|
|
98
|
+
never
|
|
99
|
+
>(
|
|
92
100
|
store,
|
|
93
101
|
{
|
|
94
102
|
key: `🔍 Devtools View Options`,
|
|
@@ -103,7 +111,8 @@ export function attachDevtoolsStates(
|
|
|
103
111
|
|
|
104
112
|
const viewIsOpenAtoms = createRegularAtomFamily<
|
|
105
113
|
boolean,
|
|
106
|
-
readonly (number | string)[]
|
|
114
|
+
readonly (number | string)[],
|
|
115
|
+
never
|
|
107
116
|
>(store, {
|
|
108
117
|
key: `🔍 Devtools View Is Open`,
|
|
109
118
|
default: false,
|
|
@@ -122,8 +131,8 @@ export function attachDevtoolsStates(
|
|
|
122
131
|
do: ({ get, set }, path, current) => {
|
|
123
132
|
const currentView = get(devtoolsViewSelectionAtom)
|
|
124
133
|
let states:
|
|
125
|
-
| WritableTokenIndex<AtomToken<unknown>>
|
|
126
|
-
| WritableTokenIndex<SelectorToken<unknown>>
|
|
134
|
+
| WritableTokenIndex<AtomToken<unknown, any, any>>
|
|
135
|
+
| WritableTokenIndex<SelectorToken<unknown, any, any>>
|
|
127
136
|
switch (currentView) {
|
|
128
137
|
case `atoms`:
|
|
129
138
|
states = get(introspectionStates.atomIndex)
|