atom.io 0.40.1 → 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 +146 -142
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +64 -14
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +4 -4
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +79 -55
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +11 -11
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/struct.ts +2 -2
- package/src/internal/atom/create-regular-atom.ts +8 -7
- package/src/internal/atom/dispose-atom.ts +6 -3
- 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-pure-selector-family.ts +21 -14
- package/src/internal/families/create-regular-atom-family.ts +18 -11
- package/src/internal/families/create-selector-family.ts +9 -9
- package/src/internal/families/create-writable-pure-selector-family.ts +22 -14
- package/src/internal/families/dispose-from-store.ts +10 -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 +17 -12
- 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 +57 -52
- package/src/internal/join/join-internal.ts +15 -6
- package/src/internal/mutable/create-mutable-atom-family.ts +1 -1
- 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 +5 -1
- package/src/internal/mutable/tracker.ts +5 -1
- package/src/internal/operation.ts +4 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +8 -6
- package/src/internal/selector/create-standalone-selector.ts +10 -10
- package/src/internal/selector/create-writable-pure-selector.ts +9 -7
- 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/dispatch-state-update.ts +9 -5
- 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 +9 -6
- 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 +10 -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 +9 -9
- 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 +5 -5
- package/src/introspection/attach-atom-index.ts +2 -2
- package/src/introspection/attach-selector-index.ts +4 -2
- package/src/introspection/attach-timeline-family.ts +13 -11
- 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 +4 -2
- package/src/introspection/attach-type-selectors.ts +2 -1
- package/src/introspection/index.ts +3 -5
- package/src/main/atom.ts +14 -8
- package/src/main/events.ts +25 -23
- package/src/main/get-state.ts +10 -8
- package/src/main/reset-state.ts +4 -4
- package/src/main/selector.ts +40 -24
- package/src/main/set-state.ts +8 -4
- 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/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/StateEditor.tsx +5 -3
- package/src/react-devtools/StateIndex.tsx +6 -4
- package/src/react-devtools/Updates.tsx +1 -1
- package/src/react-devtools/store.ts +16 -7
|
@@ -72,15 +72,18 @@ import type { Timeline } from "../timeline"
|
|
|
72
72
|
import type { Transaction } from "../transaction"
|
|
73
73
|
import type { Store } from "./store"
|
|
74
74
|
|
|
75
|
-
export function withdraw<T>(
|
|
75
|
+
export function withdraw<T, E>(
|
|
76
76
|
store: Store,
|
|
77
|
-
token: RegularAtomToken<T>,
|
|
78
|
-
): RegularAtom<T>
|
|
77
|
+
token: RegularAtomToken<T, any, E>,
|
|
78
|
+
): RegularAtom<T, E>
|
|
79
79
|
export function withdraw<T extends Transceiver<any, any, any>>(
|
|
80
80
|
store: Store,
|
|
81
81
|
token: MutableAtomToken<T, any>,
|
|
82
82
|
): MutableAtom<T>
|
|
83
|
-
export function withdraw<T
|
|
83
|
+
export function withdraw<T, E>(
|
|
84
|
+
store: Store,
|
|
85
|
+
token: AtomToken<T, any, E>,
|
|
86
|
+
): Atom<T, E>
|
|
84
87
|
export function withdraw<T>(
|
|
85
88
|
store: Store,
|
|
86
89
|
token: WritableHeldSelectorToken<T>,
|
|
@@ -89,52 +92,55 @@ export function withdraw<T>(
|
|
|
89
92
|
store: Store,
|
|
90
93
|
token: ReadonlyHeldSelectorToken<T>,
|
|
91
94
|
): ReadonlyHeldSelector<T>
|
|
92
|
-
export function withdraw<T>(
|
|
95
|
+
export function withdraw<T, E>(
|
|
93
96
|
store: Store,
|
|
94
|
-
token: WritablePureSelectorToken<T>,
|
|
95
|
-
): WritablePureSelector<T>
|
|
96
|
-
export function withdraw<T>(
|
|
97
|
+
token: WritablePureSelectorToken<T, any, E>,
|
|
98
|
+
): WritablePureSelector<T, E>
|
|
99
|
+
export function withdraw<T, E>(
|
|
97
100
|
store: Store,
|
|
98
|
-
token: ReadonlyPureSelectorToken<T>,
|
|
99
|
-
): ReadonlyPureSelector<T>
|
|
100
|
-
export function withdraw<T>(
|
|
101
|
+
token: ReadonlyPureSelectorToken<T, any, E>,
|
|
102
|
+
): ReadonlyPureSelector<T, E>
|
|
103
|
+
export function withdraw<T, E>(
|
|
101
104
|
store: Store,
|
|
102
|
-
token: ReadonlySelectorToken<T>,
|
|
103
|
-
): ReadonlySelector<T>
|
|
104
|
-
export function withdraw<T>(
|
|
105
|
+
token: ReadonlySelectorToken<T, any, E>,
|
|
106
|
+
): ReadonlySelector<T, E>
|
|
107
|
+
export function withdraw<T, E>(
|
|
105
108
|
store: Store,
|
|
106
|
-
token: WritableSelectorToken<T>,
|
|
107
|
-
): WritableSelector<T>
|
|
109
|
+
token: WritableSelectorToken<T, any, E>,
|
|
110
|
+
): WritableSelector<T, E>
|
|
108
111
|
export function withdraw<T>(
|
|
109
112
|
store: Store,
|
|
110
113
|
token: HeldSelectorToken<T>,
|
|
111
114
|
): HeldSelector<T>
|
|
112
|
-
export function withdraw<T>(
|
|
115
|
+
export function withdraw<T, E>(
|
|
113
116
|
store: Store,
|
|
114
|
-
token: PureSelectorToken<T>,
|
|
115
|
-
): PureSelector<T>
|
|
116
|
-
export function withdraw<T
|
|
117
|
-
export function withdraw<T>(
|
|
117
|
+
token: PureSelectorToken<T, any, E>,
|
|
118
|
+
): PureSelector<T, E>
|
|
119
|
+
export function withdraw<T, E>(
|
|
118
120
|
store: Store,
|
|
119
|
-
token:
|
|
120
|
-
):
|
|
121
|
-
export function withdraw<T>(
|
|
121
|
+
token: SelectorToken<T, any, E>,
|
|
122
|
+
): Selector<T, E>
|
|
123
|
+
export function withdraw<T, E>(
|
|
122
124
|
store: Store,
|
|
123
|
-
token:
|
|
124
|
-
):
|
|
125
|
+
token: WritableToken<T, any, E>,
|
|
126
|
+
): WritableState<T, E>
|
|
127
|
+
export function withdraw<T, E>(
|
|
128
|
+
store: Store,
|
|
129
|
+
token: ReadableToken<T, any, E>,
|
|
130
|
+
): ReadableState<T, E>
|
|
125
131
|
|
|
126
|
-
export function withdraw<T, K extends Canonical>(
|
|
132
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
127
133
|
store: Store,
|
|
128
|
-
token: RegularAtomFamilyToken<T, K>,
|
|
129
|
-
): RegularAtomFamily<T, K>
|
|
134
|
+
token: RegularAtomFamilyToken<T, K, E>,
|
|
135
|
+
): RegularAtomFamily<T, K, E>
|
|
130
136
|
export function withdraw<
|
|
131
137
|
T extends Transceiver<any, any, any>,
|
|
132
138
|
K extends Canonical,
|
|
133
139
|
>(store: Store, token: MutableAtomFamilyToken<T, K>): MutableAtomFamily<T, K>
|
|
134
|
-
export function withdraw<T, K extends Canonical>(
|
|
140
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
135
141
|
store: Store,
|
|
136
|
-
token: AtomFamilyToken<T, K>,
|
|
137
|
-
): AtomFamily<T, K>
|
|
142
|
+
token: AtomFamilyToken<T, K, E>,
|
|
143
|
+
): AtomFamily<T, K, E>
|
|
138
144
|
export function withdraw<T, K extends Canonical>(
|
|
139
145
|
store: Store,
|
|
140
146
|
token: ReadonlyHeldSelectorFamilyToken<T, K>,
|
|
@@ -143,42 +149,42 @@ export function withdraw<T, K extends Canonical>(
|
|
|
143
149
|
store: Store,
|
|
144
150
|
token: WritableHeldSelectorFamilyToken<T, K>,
|
|
145
151
|
): WritableHeldSelectorFamily<T, K>
|
|
146
|
-
export function withdraw<T, K extends Canonical>(
|
|
152
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
147
153
|
store: Store,
|
|
148
|
-
token: ReadonlyPureSelectorFamilyToken<T, K>,
|
|
149
|
-
): ReadonlyPureSelectorFamily<T, K>
|
|
150
|
-
export function withdraw<T, K extends Canonical>(
|
|
154
|
+
token: ReadonlyPureSelectorFamilyToken<T, K, E>,
|
|
155
|
+
): ReadonlyPureSelectorFamily<T, K, E>
|
|
156
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
151
157
|
store: Store,
|
|
152
|
-
token: WritablePureSelectorFamilyToken<T, K>,
|
|
153
|
-
): WritablePureSelectorFamily<T, K>
|
|
154
|
-
export function withdraw<T, K extends Canonical>(
|
|
158
|
+
token: WritablePureSelectorFamilyToken<T, K, E>,
|
|
159
|
+
): WritablePureSelectorFamily<T, K, E>
|
|
160
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
155
161
|
store: Store,
|
|
156
|
-
token: ReadonlySelectorFamilyToken<T, K>,
|
|
157
|
-
): ReadonlySelectorFamily<T, K>
|
|
158
|
-
export function withdraw<T, K extends Canonical>(
|
|
162
|
+
token: ReadonlySelectorFamilyToken<T, K, E>,
|
|
163
|
+
): ReadonlySelectorFamily<T, K, E>
|
|
164
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
159
165
|
store: Store,
|
|
160
|
-
token: WritableSelectorFamilyToken<T, K>,
|
|
161
|
-
): WritableSelectorFamily<T, K>
|
|
166
|
+
token: WritableSelectorFamilyToken<T, K, E>,
|
|
167
|
+
): WritableSelectorFamily<T, K, E>
|
|
162
168
|
export function withdraw<T, K extends Canonical>(
|
|
163
169
|
store: Store,
|
|
164
170
|
token: HeldSelectorFamilyToken<T, K>,
|
|
165
171
|
): HeldSelectorFamily<T, K>
|
|
166
|
-
export function withdraw<T, K extends Canonical>(
|
|
172
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
167
173
|
store: Store,
|
|
168
|
-
token: PureSelectorFamilyToken<T, K>,
|
|
169
|
-
): PureSelectorFamily<T, K>
|
|
170
|
-
export function withdraw<T, K extends Canonical>(
|
|
174
|
+
token: PureSelectorFamilyToken<T, K, E>,
|
|
175
|
+
): PureSelectorFamily<T, K, E>
|
|
176
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
171
177
|
store: Store,
|
|
172
|
-
token: SelectorFamilyToken<T, K>,
|
|
173
|
-
): SelectorFamily<T, K>
|
|
174
|
-
export function withdraw<T, K extends Canonical>(
|
|
178
|
+
token: SelectorFamilyToken<T, K, E>,
|
|
179
|
+
): SelectorFamily<T, K, E>
|
|
180
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
175
181
|
store: Store,
|
|
176
|
-
token: WritableFamilyToken<T, K>,
|
|
177
|
-
): WritableFamily<T, K>
|
|
178
|
-
export function withdraw<T, K extends Canonical>(
|
|
182
|
+
token: WritableFamilyToken<T, K, E>,
|
|
183
|
+
): WritableFamily<T, K, E>
|
|
184
|
+
export function withdraw<T, K extends Canonical, E>(
|
|
179
185
|
store: Store,
|
|
180
|
-
token: ReadableFamilyToken<T, K>,
|
|
181
|
-
): ReadableFamily<T, K>
|
|
186
|
+
token: ReadableFamilyToken<T, K, E>,
|
|
187
|
+
): ReadableFamily<T, K, E>
|
|
182
188
|
|
|
183
189
|
export function withdraw<T extends Fn>(
|
|
184
190
|
store: Store,
|
|
@@ -189,14 +195,14 @@ export function withdraw<T>(
|
|
|
189
195
|
token: TimelineToken<T>,
|
|
190
196
|
): Timeline<T extends TimelineManageable ? T : never>
|
|
191
197
|
|
|
192
|
-
export function withdraw<T>(
|
|
198
|
+
export function withdraw<T, E>(
|
|
193
199
|
store: Store,
|
|
194
|
-
token: WritableToken<T>,
|
|
195
|
-
): WritableState<T>
|
|
196
|
-
export function withdraw<T>(
|
|
200
|
+
token: WritableToken<T, any, E>,
|
|
201
|
+
): WritableState<T, E>
|
|
202
|
+
export function withdraw<T, E>(
|
|
197
203
|
store: Store,
|
|
198
|
-
token: ReadableToken<T>,
|
|
199
|
-
): ReadableState<T>
|
|
204
|
+
token: ReadableToken<T, any, E>,
|
|
205
|
+
): ReadableState<T, E>
|
|
200
206
|
|
|
201
207
|
export function withdraw(
|
|
202
208
|
store: Store,
|
|
@@ -2,7 +2,10 @@ import type { ReadableState } from ".."
|
|
|
2
2
|
import { newest } from "../lineage"
|
|
3
3
|
import type { Store } from "../store"
|
|
4
4
|
|
|
5
|
-
export const recallState = <T
|
|
5
|
+
export const recallState = <T, E>(
|
|
6
|
+
store: Store,
|
|
7
|
+
state: ReadableState<T, E>,
|
|
8
|
+
): T => {
|
|
6
9
|
const target = newest(store)
|
|
7
10
|
if (target.operation.open) {
|
|
8
11
|
return target.operation.prev.get(state.key)
|
|
@@ -5,8 +5,8 @@ import { recallState } from "./recall-state"
|
|
|
5
5
|
|
|
6
6
|
export const subscribeToRootDependency = (
|
|
7
7
|
target: Store,
|
|
8
|
-
selector: Selector<any>,
|
|
9
|
-
atom: Atom<any>,
|
|
8
|
+
selector: Selector<any, any>,
|
|
9
|
+
atom: Atom<any, any>,
|
|
10
10
|
): (() => void) => {
|
|
11
11
|
return atom.subject.subscribe(
|
|
12
12
|
`${selector.type}:${selector.key}`,
|
|
@@ -7,11 +7,11 @@ import type { Store } from "../store"
|
|
|
7
7
|
import { withdraw } from "../store"
|
|
8
8
|
import { subscribeToRootDependency } from "./subscribe-to-root-atoms"
|
|
9
9
|
|
|
10
|
-
export function subscribeToState<T>(
|
|
10
|
+
export function subscribeToState<T, E>(
|
|
11
11
|
store: Store,
|
|
12
|
-
token: ReadableToken<T>,
|
|
12
|
+
token: ReadableToken<T, any, E>,
|
|
13
13
|
key: string,
|
|
14
|
-
handleUpdate: UpdateHandler<T>,
|
|
14
|
+
handleUpdate: UpdateHandler<E | T>,
|
|
15
15
|
): () => void {
|
|
16
16
|
function safelyHandleUpdate(update: StateUpdate<any>): void {
|
|
17
17
|
if (store.operation.open) {
|
|
@@ -33,7 +33,7 @@ export function subscribeToState<T>(
|
|
|
33
33
|
state.type === `writable_pure_selector` ||
|
|
34
34
|
state.type === `readonly_pure_selector`
|
|
35
35
|
const rootSubs = new Map<string, () => void>()
|
|
36
|
-
let updateHandler: UpdateHandler<T> = safelyHandleUpdate
|
|
36
|
+
let updateHandler: UpdateHandler<E | T> = safelyHandleUpdate
|
|
37
37
|
if (isSelector) {
|
|
38
38
|
readOrComputeValue(store, state)
|
|
39
39
|
for (const [atomKey, atom] of traceRootSelectorAtoms(store, state.key)) {
|
|
@@ -63,7 +63,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
|
|
|
63
63
|
case `atom`:
|
|
64
64
|
case `mutable_atom`:
|
|
65
65
|
{
|
|
66
|
-
const atomToken: AtomToken<
|
|
66
|
+
const atomToken: AtomToken<any, any, any> = initialTopic
|
|
67
67
|
const atomKey = atomToken.key
|
|
68
68
|
let existingTimelineKey = target.timelineTopics.getRelatedKey(atomKey)
|
|
69
69
|
if (`family` in atomToken) {
|
|
@@ -95,7 +95,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
|
|
|
95
95
|
case `atom_family`:
|
|
96
96
|
case `mutable_atom_family`:
|
|
97
97
|
{
|
|
98
|
-
const familyToken: AtomFamilyToken<any, any> = initialTopic
|
|
98
|
+
const familyToken: AtomFamilyToken<any, any, any> = initialTopic
|
|
99
99
|
const familyKey = familyToken.key
|
|
100
100
|
const existingTimelineKey =
|
|
101
101
|
target.timelineTopics.getRelatedKey(familyKey)
|
|
@@ -125,7 +125,7 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
|
|
|
125
125
|
|
|
126
126
|
function addAtomToTimeline(
|
|
127
127
|
store: Store,
|
|
128
|
-
atomToken: AtomToken<any>,
|
|
128
|
+
atomToken: AtomToken<any, any, any>,
|
|
129
129
|
tl: Timeline<any>,
|
|
130
130
|
): void {
|
|
131
131
|
reduceReference(store, atomToken)
|
|
@@ -214,7 +214,7 @@ function addAtomToTimeline(
|
|
|
214
214
|
|
|
215
215
|
function addAtomFamilyToTimeline(
|
|
216
216
|
store: Store,
|
|
217
|
-
atomFamilyToken: AtomFamilyToken<any, any>,
|
|
217
|
+
atomFamilyToken: AtomFamilyToken<any, any, any>,
|
|
218
218
|
tl: Timeline<any>,
|
|
219
219
|
): void {
|
|
220
220
|
const family = withdraw(store, atomFamilyToken)
|
|
@@ -283,7 +283,7 @@ function joinTransaction(
|
|
|
283
283
|
function buildSelectorUpdate(
|
|
284
284
|
store: Store,
|
|
285
285
|
tl: Timeline<any>,
|
|
286
|
-
atomToken: AtomToken<any>,
|
|
286
|
+
atomToken: AtomToken<any, any, any>,
|
|
287
287
|
eventOrUpdate: StateCreationEvent<any> | StateUpdate<any>,
|
|
288
288
|
currentSelectorToken: WritablePureSelectorToken<any>,
|
|
289
289
|
currentSelectorTime: number,
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
|
|
9
9
|
import type { WritableTokenIndex } from "."
|
|
10
10
|
|
|
11
|
-
export type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>
|
|
11
|
+
export type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown, any, unknown>>
|
|
12
12
|
|
|
13
13
|
export const attachAtomIndex = (store: Store): AtomToken<AtomTokenIndex> => {
|
|
14
|
-
return createRegularAtom<AtomTokenIndex>(
|
|
14
|
+
return createRegularAtom<AtomTokenIndex, never, never>(
|
|
15
15
|
store,
|
|
16
16
|
{
|
|
17
17
|
key: `🔍 Atom Token Index`,
|
|
@@ -8,12 +8,14 @@ import {
|
|
|
8
8
|
|
|
9
9
|
import type { WritableTokenIndex } from "."
|
|
10
10
|
|
|
11
|
-
export type SelectorTokenIndex = WritableTokenIndex<
|
|
11
|
+
export type SelectorTokenIndex = WritableTokenIndex<
|
|
12
|
+
SelectorToken<unknown, any, any>
|
|
13
|
+
>
|
|
12
14
|
|
|
13
15
|
export const attachSelectorIndex = (
|
|
14
16
|
store: Store,
|
|
15
17
|
): AtomToken<SelectorTokenIndex> => {
|
|
16
|
-
return createRegularAtom<SelectorTokenIndex>(
|
|
18
|
+
return createRegularAtom<SelectorTokenIndex, never, never>(
|
|
17
19
|
store,
|
|
18
20
|
{
|
|
19
21
|
key: `🔍 Selector Token Index`,
|
|
@@ -11,7 +11,8 @@ export const attachTimelineFamily = (
|
|
|
11
11
|
): ReadonlyPureSelectorFamilyToken<Timeline<any>, string> => {
|
|
12
12
|
const findTimelineLogState__INTERNAL = createRegularAtomFamily<
|
|
13
13
|
Timeline<any>,
|
|
14
|
-
string
|
|
14
|
+
string,
|
|
15
|
+
never
|
|
15
16
|
>(store, {
|
|
16
17
|
key: `🔍 Timeline Update Log (Internal)`,
|
|
17
18
|
default: (key) =>
|
|
@@ -36,15 +37,16 @@ export const attachTimelineFamily = (
|
|
|
36
37
|
},
|
|
37
38
|
],
|
|
38
39
|
})
|
|
39
|
-
const findTimelineLogState = createSelectorFamily<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
const findTimelineLogState = createSelectorFamily<
|
|
41
|
+
Timeline<any>,
|
|
42
|
+
string,
|
|
43
|
+
never
|
|
44
|
+
>(store, {
|
|
45
|
+
key: `🔍 Timeline Update Log`,
|
|
46
|
+
get:
|
|
47
|
+
(key) =>
|
|
48
|
+
({ get }) =>
|
|
49
|
+
get(findTimelineLogState__INTERNAL, key),
|
|
50
|
+
})
|
|
49
51
|
return findTimelineLogState
|
|
50
52
|
}
|
|
@@ -5,7 +5,7 @@ import { createRegularAtom } from "atom.io/internal"
|
|
|
5
5
|
export const attachTimelineIndex = (
|
|
6
6
|
store: Store,
|
|
7
7
|
): AtomToken<TimelineToken<any>[]> => {
|
|
8
|
-
return createRegularAtom<TimelineToken<any>[]>(
|
|
8
|
+
return createRegularAtom<TimelineToken<any>[], never, never>(
|
|
9
9
|
store,
|
|
10
10
|
{
|
|
11
11
|
key: `🔍 Timeline Token Index`,
|
|
@@ -5,7 +5,7 @@ import { createRegularAtom, isReservedIntrospectionKey } from "atom.io/internal"
|
|
|
5
5
|
export const attachTransactionIndex = (
|
|
6
6
|
store: Store,
|
|
7
7
|
): AtomToken<TransactionToken<Fn>[]> => {
|
|
8
|
-
return createRegularAtom<TransactionToken<Fn>[]>(
|
|
8
|
+
return createRegularAtom<TransactionToken<Fn>[], never, never>(
|
|
9
9
|
store,
|
|
10
10
|
{
|
|
11
11
|
key: `🔍 Transaction Token Index`,
|
|
@@ -14,7 +14,8 @@ export const attachTransactionLogs = (
|
|
|
14
14
|
> => {
|
|
15
15
|
const transactionUpdateLogAtoms = createRegularAtomFamily<
|
|
16
16
|
TransactionOutcomeEvent<TransactionToken<any>>[],
|
|
17
|
-
string
|
|
17
|
+
string,
|
|
18
|
+
never
|
|
18
19
|
>(store, {
|
|
19
20
|
key: `🔍 Transaction Update Log (Internal)`,
|
|
20
21
|
default: () => [],
|
|
@@ -31,7 +32,8 @@ export const attachTransactionLogs = (
|
|
|
31
32
|
})
|
|
32
33
|
const findTransactionUpdateLogState = createSelectorFamily<
|
|
33
34
|
TransactionOutcomeEvent<TransactionToken<any>>[],
|
|
34
|
-
string
|
|
35
|
+
string,
|
|
36
|
+
never
|
|
35
37
|
>(store, {
|
|
36
38
|
key: `🔍 Transaction Update Log`,
|
|
37
39
|
get:
|
|
@@ -6,12 +6,10 @@ export * from "./differ"
|
|
|
6
6
|
export * from "./refinery"
|
|
7
7
|
export * from "./sprawl"
|
|
8
8
|
|
|
9
|
-
export type FamilyNode<Token extends ReadableToken<unknown>> = {
|
|
9
|
+
export type FamilyNode<Token extends ReadableToken<unknown, any, any>> = {
|
|
10
10
|
key: string
|
|
11
11
|
familyMembers: Map<string, Token>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export type WritableTokenIndex<Token extends ReadableToken<unknown>> =
|
|
15
|
-
string,
|
|
16
|
-
FamilyNode<Token> | Token
|
|
17
|
-
>
|
|
14
|
+
export type WritableTokenIndex<Token extends ReadableToken<unknown, any, any>> =
|
|
15
|
+
Map<string, FamilyNode<Token> | Token>
|
package/src/main/atom.ts
CHANGED
|
@@ -17,13 +17,15 @@ import type {
|
|
|
17
17
|
RegularAtomToken,
|
|
18
18
|
} from "./tokens"
|
|
19
19
|
|
|
20
|
-
export type RegularAtomOptions<T> = {
|
|
20
|
+
export type RegularAtomOptions<T, E = never> = {
|
|
21
21
|
/** The unique identifier of the atom */
|
|
22
22
|
key: string
|
|
23
23
|
/** The starting value of the atom */
|
|
24
24
|
default: T | (() => T)
|
|
25
25
|
/** Hooks used to run side effects when the atom is set */
|
|
26
|
-
effects?: AtomEffect<T>[]
|
|
26
|
+
effects?: readonly AtomEffect<T>[]
|
|
27
|
+
/** The classes of errors that might be thrown when deriving the atom's default value */
|
|
28
|
+
catch?: readonly (new () => E)[]
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Create a regular atom, a global reactive variable in the implicit store
|
|
@@ -31,7 +33,9 @@ export type RegularAtomOptions<T> = {
|
|
|
31
33
|
* @returns
|
|
32
34
|
* A reference to the atom created: a {@link RegularAtomToken}
|
|
33
35
|
*/
|
|
34
|
-
export function atom<T
|
|
36
|
+
export function atom<T, E = never>(
|
|
37
|
+
options: RegularAtomOptions<T, E>,
|
|
38
|
+
): RegularAtomToken<T, any, E> {
|
|
35
39
|
return createRegularAtom(IMPLICIT.STORE, options, undefined)
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -41,7 +45,7 @@ export type MutableAtomOptions<T extends Transceiver<any, any, any>> = {
|
|
|
41
45
|
/** A constructor for the atom's value */
|
|
42
46
|
class: ConstructorOf<T>
|
|
43
47
|
/** Hooks used to run side effects when the atom is set */
|
|
44
|
-
effects?: AtomEffect<T>[]
|
|
48
|
+
effects?: readonly AtomEffect<T>[]
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
51
|
* Create a mutable atom, a global reactive variable in the implicit store
|
|
@@ -79,13 +83,15 @@ export type Effectors<T> = {
|
|
|
79
83
|
onSet: (callback: (options: StateUpdate<T>) => void) => void
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
export type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
86
|
+
export type RegularAtomFamilyOptions<T, K extends Canonical, E = never> = {
|
|
83
87
|
/** The unique identifier of the atom family */
|
|
84
88
|
key: string
|
|
85
89
|
/** The starting value of the atom family */
|
|
86
90
|
default: T | ((key: K) => T)
|
|
87
91
|
/** Hooks used to run side effects when an atom in the family is set */
|
|
88
92
|
effects?: (key: K) => AtomEffect<T>[]
|
|
93
|
+
/** The classes of errors that might be thrown when deriving the atom's default value */
|
|
94
|
+
catch?: readonly (new () => E)[]
|
|
89
95
|
}
|
|
90
96
|
/**
|
|
91
97
|
* Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms.
|
|
@@ -93,9 +99,9 @@ export type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
|
93
99
|
* @returns
|
|
94
100
|
* A reference to the atom family created: a {@link RegularAtomFamilyToken}
|
|
95
101
|
*/
|
|
96
|
-
export function atomFamily<T, K extends Canonical>(
|
|
97
|
-
options: RegularAtomFamilyOptions<T, K>,
|
|
98
|
-
): RegularAtomFamilyToken<T, K> {
|
|
102
|
+
export function atomFamily<T, K extends Canonical, E = never>(
|
|
103
|
+
options: RegularAtomFamilyOptions<T, K, E>,
|
|
104
|
+
): RegularAtomFamilyToken<T, K, E> {
|
|
99
105
|
return createRegularAtomFamily(IMPLICIT.STORE, options)
|
|
100
106
|
}
|
|
101
107
|
|
package/src/main/events.ts
CHANGED
|
@@ -16,14 +16,14 @@ export type StateUpdate<T> = {
|
|
|
16
16
|
readonly newValue: ViewOf<T>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export type AtomUpdateEvent<A extends AtomToken<any>> = {
|
|
19
|
+
export type AtomUpdateEvent<A extends AtomToken<any, any, any>> = {
|
|
20
20
|
type: `atom_update`
|
|
21
21
|
token: A
|
|
22
22
|
update: StateUpdate<TokenType<A>>
|
|
23
23
|
timestamp: number
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export type SelectorUpdateSubEvent<A extends AtomToken<any>> =
|
|
26
|
+
export type SelectorUpdateSubEvent<A extends AtomToken<any, any, any>> =
|
|
27
27
|
| AtomUpdateEvent<A>
|
|
28
28
|
| StateCreationEvent<any>
|
|
29
29
|
export type TimelineSelectorUpdateEvent<A extends TimelineManageable> = {
|
|
@@ -33,36 +33,38 @@ export type TimelineSelectorUpdateEvent<A extends TimelineManageable> = {
|
|
|
33
33
|
timestamp: number
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export type StateLifecycleEvent<R extends ReadableToken<any>> =
|
|
36
|
+
export type StateLifecycleEvent<R extends ReadableToken<any, any, any>> =
|
|
37
37
|
| StateCreationEvent<R>
|
|
38
38
|
| StateDisposalEvent<R>
|
|
39
|
-
export type StateCreationEvent<R extends ReadableToken<any>> =
|
|
39
|
+
export type StateCreationEvent<R extends ReadableToken<any, any, any>> =
|
|
40
40
|
| ReadableStateCreationEvent<R>
|
|
41
41
|
| (R extends WritableToken<any> ? WritableStateCreationEvent<R> : never)
|
|
42
|
-
export type ReadableStateCreationEvent<R extends ReadableToken<any>> =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
export type ReadableStateCreationEvent<R extends ReadableToken<any, any, any>> =
|
|
43
|
+
{
|
|
44
|
+
type: `state_creation`
|
|
45
|
+
subType: `readable`
|
|
46
|
+
token: R
|
|
47
|
+
timestamp: number
|
|
48
|
+
}
|
|
49
|
+
export type WritableStateCreationEvent<W extends WritableToken<any, any, any>> =
|
|
50
|
+
{
|
|
51
|
+
type: `state_creation`
|
|
52
|
+
subType: `writable`
|
|
53
|
+
token: W
|
|
54
|
+
timestamp: number
|
|
55
|
+
value?: TokenType<W>
|
|
56
|
+
}
|
|
57
|
+
export type StateDisposalEvent<R extends ReadableToken<any, any, any>> =
|
|
56
58
|
| AtomDisposalEvent<R>
|
|
57
59
|
| SelectorDisposalEvent<R>
|
|
58
|
-
export type AtomDisposalEvent<R extends ReadableToken<any>> = {
|
|
60
|
+
export type AtomDisposalEvent<R extends ReadableToken<any, any, any>> = {
|
|
59
61
|
type: `state_disposal`
|
|
60
62
|
subType: `atom`
|
|
61
63
|
token: R
|
|
62
64
|
value: TokenType<R>
|
|
63
65
|
timestamp: number
|
|
64
66
|
}
|
|
65
|
-
export type SelectorDisposalEvent<R extends ReadableToken<any>> = {
|
|
67
|
+
export type SelectorDisposalEvent<R extends ReadableToken<any, any, any>> = {
|
|
66
68
|
type: `state_disposal`
|
|
67
69
|
subType: `selector`
|
|
68
70
|
token: R
|
|
@@ -94,12 +96,12 @@ export type MoleculeTransferEvent = {
|
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
export type TransactionSubEvent =
|
|
97
|
-
| AtomUpdateEvent<AtomToken<any>>
|
|
99
|
+
| AtomUpdateEvent<AtomToken<any, any, any>>
|
|
98
100
|
| MoleculeCreationEvent
|
|
99
101
|
| MoleculeDisposalEvent
|
|
100
102
|
| MoleculeTransferEvent
|
|
101
|
-
| StateCreationEvent<ReadableToken<unknown>>
|
|
102
|
-
| StateDisposalEvent<ReadableToken<unknown>>
|
|
103
|
+
| StateCreationEvent<ReadableToken<unknown, any, any>>
|
|
104
|
+
| StateDisposalEvent<ReadableToken<unknown, any, any>>
|
|
103
105
|
| TransactionOutcomeEvent<TransactionToken<any>>
|
|
104
106
|
|
|
105
107
|
export type TransactionOutcomeEvent<T extends TransactionToken<any>> = {
|
package/src/main/get-state.ts
CHANGED
|
@@ -11,7 +11,9 @@ import type { ReadableFamilyToken, ReadableToken } from "."
|
|
|
11
11
|
* @overload Default
|
|
12
12
|
* @default
|
|
13
13
|
*/
|
|
14
|
-
export function getState<T
|
|
14
|
+
export function getState<T, E = never>(
|
|
15
|
+
token: ReadableToken<T, any, E>,
|
|
16
|
+
): ViewOf<E | T>
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Read or compute the current value of a state
|
|
@@ -20,15 +22,15 @@ export function getState<T>(token: ReadableToken<T>): ViewOf<T>
|
|
|
20
22
|
* @return The current value of the state
|
|
21
23
|
* @overload Streamlined
|
|
22
24
|
*/
|
|
23
|
-
export function getState<T, K extends Canonical, Key extends K>(
|
|
24
|
-
token: ReadableFamilyToken<T, K>,
|
|
25
|
+
export function getState<T, K extends Canonical, Key extends K, E = never>(
|
|
26
|
+
token: ReadableFamilyToken<T, K, E>,
|
|
25
27
|
key: Key,
|
|
26
|
-
): ViewOf<T>
|
|
28
|
+
): ViewOf<E | T>
|
|
27
29
|
|
|
28
|
-
export function getState<T, K extends Canonical, Key extends K>(
|
|
30
|
+
export function getState<T, K extends Canonical, Key extends K, E = never>(
|
|
29
31
|
...params:
|
|
30
|
-
| [token: ReadableFamilyToken<T, K>, key: Key]
|
|
31
|
-
| [token: ReadableToken<T>]
|
|
32
|
-
):
|
|
32
|
+
| [token: ReadableFamilyToken<T, K, E>, key: Key]
|
|
33
|
+
| [token: ReadableToken<T, any, E>]
|
|
34
|
+
): ViewOf<E | T> {
|
|
33
35
|
return getFromStore(IMPLICIT.STORE, ...params)
|
|
34
36
|
}
|
package/src/main/reset-state.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { WritableFamilyToken, WritableToken } from "."
|
|
|
9
9
|
* @overload Default
|
|
10
10
|
* @default
|
|
11
11
|
*/
|
|
12
|
-
export function resetState(token: WritableToken<any>): void
|
|
12
|
+
export function resetState(token: WritableToken<any, any, any>): void
|
|
13
13
|
/**
|
|
14
14
|
* Set the value of a state into the implicit store back to its default value.
|
|
15
15
|
* @param token - An atom family or writable selector family token.
|
|
@@ -17,13 +17,13 @@ export function resetState(token: WritableToken<any>): void
|
|
|
17
17
|
* @overload Streamlined
|
|
18
18
|
*/
|
|
19
19
|
export function resetState<K extends Canonical>(
|
|
20
|
-
token: WritableFamilyToken<any, K>,
|
|
20
|
+
token: WritableFamilyToken<any, K, any>,
|
|
21
21
|
key: K,
|
|
22
22
|
): void
|
|
23
23
|
export function resetState(
|
|
24
24
|
...params:
|
|
25
|
-
| [token: WritableFamilyToken<any, Canonical>, key: Canonical]
|
|
26
|
-
| [token: WritableToken<any>]
|
|
25
|
+
| [token: WritableFamilyToken<any, Canonical, any>, key: Canonical]
|
|
26
|
+
| [token: WritableToken<any, any, any>]
|
|
27
27
|
): void {
|
|
28
28
|
resetInStore(IMPLICIT.STORE, ...params)
|
|
29
29
|
}
|