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
|
@@ -4,7 +4,10 @@ import type { Store, Subject } from ".."
|
|
|
4
4
|
import { getUpdateToken, hasRole, isChildStore, newest, withdraw } from ".."
|
|
5
5
|
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
6
6
|
|
|
7
|
-
export function disposeAtom(
|
|
7
|
+
export function disposeAtom(
|
|
8
|
+
store: Store,
|
|
9
|
+
atomToken: AtomToken<any, any, any>,
|
|
10
|
+
): void {
|
|
8
11
|
const target = newest(store)
|
|
9
12
|
const { key, family } = atomToken
|
|
10
13
|
const atom = withdraw(target, atomToken)
|
|
@@ -16,10 +19,10 @@ export function disposeAtom(store: Store, atomToken: AtomToken<any>): void {
|
|
|
16
19
|
const familyToken = getFamilyOfToken(store, atomToken)
|
|
17
20
|
const atomFamily = withdraw(store, familyToken)
|
|
18
21
|
const subject = atomFamily.subject as Subject<
|
|
19
|
-
StateLifecycleEvent<AtomToken<any>>
|
|
22
|
+
StateLifecycleEvent<AtomToken<any, any, any>>
|
|
20
23
|
>
|
|
21
24
|
|
|
22
|
-
const disposalEvent: AtomDisposalEvent<AtomToken<any>> = {
|
|
25
|
+
const disposalEvent: AtomDisposalEvent<AtomToken<any, any, any>> = {
|
|
23
26
|
type: `state_disposal`,
|
|
24
27
|
subType: `atom`,
|
|
25
28
|
token: atomToken,
|
|
@@ -3,7 +3,7 @@ import type { Atom } from ".."
|
|
|
3
3
|
export const INTERNAL_ROLES = [`tracker:signal`] as const
|
|
4
4
|
export type internalRole = (typeof INTERNAL_ROLES)[number]
|
|
5
5
|
|
|
6
|
-
export function hasRole(atom: Atom<any>, role: internalRole): boolean {
|
|
6
|
+
export function hasRole(atom: Atom<any, any>, role: internalRole): boolean {
|
|
7
7
|
if (`internalRoles` in atom === false) {
|
|
8
8
|
return false
|
|
9
9
|
}
|
package/src/internal/caching.ts
CHANGED
|
@@ -7,21 +7,21 @@ import {
|
|
|
7
7
|
} from "./set-state/evict-downstream"
|
|
8
8
|
import type { Store } from "./store"
|
|
9
9
|
|
|
10
|
-
export function writeToCache<T>(
|
|
10
|
+
export function writeToCache<T, E>(
|
|
11
11
|
target: Store,
|
|
12
|
-
state: ReadableState<T>,
|
|
13
|
-
value: T,
|
|
14
|
-
): T
|
|
15
|
-
export function writeToCache<T extends Promise<any
|
|
12
|
+
state: ReadableState<T, E>,
|
|
13
|
+
value: E | T,
|
|
14
|
+
): E | T
|
|
15
|
+
export function writeToCache<T extends Promise<any>, E>(
|
|
16
16
|
target: Store,
|
|
17
|
-
state: ReadableState<T>,
|
|
17
|
+
state: ReadableState<T, E>,
|
|
18
18
|
value: T,
|
|
19
|
-
): Future<Awaited<T>>
|
|
20
|
-
export function writeToCache<T>(
|
|
19
|
+
): Future<Awaited<E | T>>
|
|
20
|
+
export function writeToCache<T, E>(
|
|
21
21
|
target: Store,
|
|
22
|
-
state: ReadableState<T>,
|
|
23
|
-
value: T,
|
|
24
|
-
): Future<T> | T {
|
|
22
|
+
state: ReadableState<T, E>,
|
|
23
|
+
value: E | T,
|
|
24
|
+
): E | Future<E | T> | T {
|
|
25
25
|
const { key, subject, type } = state
|
|
26
26
|
const currentValue = target.valueMap.get(key)
|
|
27
27
|
if (currentValue instanceof Future && !currentValue.done) {
|
|
@@ -74,13 +74,13 @@ export function writeToCache<T>(
|
|
|
74
74
|
* @param mut - whether the value is intended to be mutable
|
|
75
75
|
* @returns the state's current value
|
|
76
76
|
*/
|
|
77
|
-
export function readFromCache<T>(
|
|
77
|
+
export function readFromCache<T, E>(
|
|
78
78
|
target: Store,
|
|
79
|
-
state: ReadableState<T>,
|
|
79
|
+
state: ReadableState<T, E>,
|
|
80
80
|
mut: `mut` | undefined,
|
|
81
|
-
): T {
|
|
81
|
+
): E | T {
|
|
82
82
|
target.logger.info(`📖`, state.type, state.key, `reading cached value`)
|
|
83
|
-
let value = target.valueMap.get(state.key) as T
|
|
83
|
+
let value = target.valueMap.get(state.key) as E | T
|
|
84
84
|
|
|
85
85
|
const mayNeedToBeCopied =
|
|
86
86
|
mut === `mut` && state.type === `mutable_atom` && isChildStore(target)
|
|
@@ -37,7 +37,7 @@ export function ingestCreationEvent(
|
|
|
37
37
|
|
|
38
38
|
export function ingestDisposalEvent(
|
|
39
39
|
store: Store,
|
|
40
|
-
event: StateDisposalEvent<ReadableToken<any>>,
|
|
40
|
+
event: StateDisposalEvent<ReadableToken<any, any, any>>,
|
|
41
41
|
applying: `newValue` | `oldValue`,
|
|
42
42
|
): void {
|
|
43
43
|
switch (applying) {
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
getState,
|
|
5
5
|
ReadonlyPureSelectorFamilyOptions,
|
|
6
6
|
ReadonlyPureSelectorFamilyToken,
|
|
7
|
+
ReadonlyPureSelectorOptions,
|
|
7
8
|
ReadonlyPureSelectorToken,
|
|
8
9
|
StateLifecycleEvent,
|
|
9
10
|
} from "atom.io"
|
|
@@ -17,18 +18,18 @@ import { newest } from "../lineage"
|
|
|
17
18
|
import { createReadonlyPureSelector } from "../selector"
|
|
18
19
|
import { Subject } from "../subject"
|
|
19
20
|
|
|
20
|
-
export function createReadonlyPureSelectorFamily<T, K extends Canonical>(
|
|
21
|
+
export function createReadonlyPureSelectorFamily<T, K extends Canonical, E>(
|
|
21
22
|
store: RootStore,
|
|
22
|
-
options: ReadonlyPureSelectorFamilyOptions<T, K>,
|
|
23
|
+
options: ReadonlyPureSelectorFamilyOptions<T, K, E>,
|
|
23
24
|
internalRoles?: string[],
|
|
24
|
-
): ReadonlyPureSelectorFamilyToken<T, K> {
|
|
25
|
+
): ReadonlyPureSelectorFamilyToken<T, K, E> {
|
|
25
26
|
const familyKey = options.key
|
|
26
27
|
const type = `readonly_pure_selector_family`
|
|
27
28
|
|
|
28
29
|
const familyToken = {
|
|
29
30
|
key: familyKey,
|
|
30
31
|
type,
|
|
31
|
-
} as const satisfies ReadonlyPureSelectorFamilyToken<T, K>
|
|
32
|
+
} as const satisfies ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
32
33
|
|
|
33
34
|
const existing = store.families.get(familyKey)
|
|
34
35
|
if (existing) {
|
|
@@ -41,25 +42,30 @@ export function createReadonlyPureSelectorFamily<T, K extends Canonical>(
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const subject = new Subject<
|
|
44
|
-
StateLifecycleEvent<ReadonlyPureSelectorToken<T>>
|
|
45
|
+
StateLifecycleEvent<ReadonlyPureSelectorToken<T, K, E>>
|
|
45
46
|
>()
|
|
46
47
|
|
|
47
|
-
const familyFunction =
|
|
48
|
+
const familyFunction = <Key extends K>(
|
|
49
|
+
key: Key,
|
|
50
|
+
): ReadonlyPureSelectorToken<T, Key, E> => {
|
|
48
51
|
const subKey = stringifyJson(key)
|
|
49
|
-
const family: FamilyMetadata = { key: familyKey, subKey }
|
|
52
|
+
const family: FamilyMetadata<Key> = { key: familyKey, subKey }
|
|
50
53
|
const fullKey = `${familyKey}(${subKey})`
|
|
51
54
|
const target = newest(store)
|
|
55
|
+
const individualOptions: ReadonlyPureSelectorOptions<T, E> = {
|
|
56
|
+
key: fullKey,
|
|
57
|
+
get: options.get(key),
|
|
58
|
+
}
|
|
59
|
+
if (options.catch) {
|
|
60
|
+
individualOptions.catch = options.catch
|
|
61
|
+
}
|
|
52
62
|
|
|
53
|
-
const token = createReadonlyPureSelector(
|
|
63
|
+
const token = createReadonlyPureSelector<T, Key, E>(
|
|
54
64
|
target,
|
|
55
|
-
|
|
56
|
-
key: fullKey,
|
|
57
|
-
get: options.get(key),
|
|
58
|
-
},
|
|
65
|
+
individualOptions,
|
|
59
66
|
family,
|
|
60
67
|
)
|
|
61
68
|
|
|
62
|
-
// subject.next({ type: `state_creation`, token, timestamp: Date.now() })
|
|
63
69
|
return token
|
|
64
70
|
}
|
|
65
71
|
|
|
@@ -77,7 +83,8 @@ export function createReadonlyPureSelectorFamily<T, K extends Canonical>(
|
|
|
77
83
|
json: (token) => getJsonToken(store, token),
|
|
78
84
|
})
|
|
79
85
|
},
|
|
80
|
-
|
|
86
|
+
...(options.catch ? { catch: options.catch } : {}),
|
|
87
|
+
}) satisfies ReadonlyPureSelectorFamily<T, K, E>
|
|
81
88
|
|
|
82
89
|
store.families.set(familyKey, readonlySelectorFamily)
|
|
83
90
|
return familyToken
|
|
@@ -16,15 +16,15 @@ import { isFn } from "../is-fn"
|
|
|
16
16
|
import { newest } from "../lineage"
|
|
17
17
|
import { Subject } from "../subject"
|
|
18
18
|
|
|
19
|
-
export function createRegularAtomFamily<T, K extends Canonical>(
|
|
19
|
+
export function createRegularAtomFamily<T, K extends Canonical, E>(
|
|
20
20
|
store: RootStore,
|
|
21
|
-
options: RegularAtomFamilyOptions<T, K>,
|
|
21
|
+
options: RegularAtomFamilyOptions<T, K, E>,
|
|
22
22
|
internalRoles?: string[],
|
|
23
|
-
): RegularAtomFamilyToken<T, K> {
|
|
24
|
-
const familyToken = {
|
|
23
|
+
): RegularAtomFamilyToken<T, K, E> {
|
|
24
|
+
const familyToken: RegularAtomFamilyToken<T, K, E> = {
|
|
25
25
|
key: options.key,
|
|
26
26
|
type: `atom_family`,
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
28
|
|
|
29
29
|
const existing = store.families.get(options.key)
|
|
30
30
|
if (existing) {
|
|
@@ -36,22 +36,27 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
36
36
|
)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const subject = new Subject<StateLifecycleEvent<RegularAtomToken<T>>>()
|
|
39
|
+
const subject = new Subject<StateLifecycleEvent<RegularAtomToken<T, K, E>>>()
|
|
40
40
|
|
|
41
|
-
const familyFunction =
|
|
41
|
+
const familyFunction = <Key extends K>(
|
|
42
|
+
key: Key,
|
|
43
|
+
): RegularAtomToken<T, Key, E> => {
|
|
42
44
|
const subKey = stringifyJson(key)
|
|
43
|
-
const family: FamilyMetadata = { key: options.key, subKey }
|
|
45
|
+
const family: FamilyMetadata<Key> = { key: options.key, subKey }
|
|
44
46
|
const fullKey = `${options.key}(${subKey})`
|
|
45
47
|
const target = newest(store)
|
|
46
48
|
|
|
47
49
|
const def = options.default
|
|
48
|
-
const individualOptions: RegularAtomOptions<T> = {
|
|
50
|
+
const individualOptions: RegularAtomOptions<T, E> = {
|
|
49
51
|
key: fullKey,
|
|
50
52
|
default: isFn(def) ? () => def(key) : def,
|
|
51
53
|
}
|
|
52
54
|
if (options.effects) {
|
|
53
55
|
individualOptions.effects = options.effects(key)
|
|
54
56
|
}
|
|
57
|
+
if (options.catch) {
|
|
58
|
+
individualOptions.catch = options.catch
|
|
59
|
+
}
|
|
55
60
|
|
|
56
61
|
const token = createRegularAtom(target, individualOptions, family)
|
|
57
62
|
|
|
@@ -59,12 +64,14 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
59
64
|
return token
|
|
60
65
|
}
|
|
61
66
|
|
|
62
|
-
const atomFamily = Object.assign(familyFunction,
|
|
67
|
+
const atomFamily: RegularAtomFamily<T, K, E> = Object.assign(familyFunction, {
|
|
68
|
+
...familyToken,
|
|
63
69
|
default: options.default,
|
|
64
70
|
subject,
|
|
65
71
|
install: (s: RootStore) => createRegularAtomFamily(s, options),
|
|
66
72
|
internalRoles,
|
|
67
|
-
|
|
73
|
+
...(options.catch ? { catch: options.catch } : {}),
|
|
74
|
+
})
|
|
68
75
|
|
|
69
76
|
store.families.set(options.key, atomFamily)
|
|
70
77
|
if (isFn(options.default) === false) {
|
|
@@ -25,22 +25,22 @@ export function createSelectorFamily<T extends object, K extends Canonical>(
|
|
|
25
25
|
store: RootStore,
|
|
26
26
|
options: ReadonlyHeldSelectorFamilyOptions<T, K>,
|
|
27
27
|
): ReadonlyHeldSelectorFamilyToken<T, K>
|
|
28
|
-
export function createSelectorFamily<T, K extends Canonical>(
|
|
28
|
+
export function createSelectorFamily<T, K extends Canonical, E>(
|
|
29
29
|
store: RootStore,
|
|
30
|
-
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
31
|
-
): WritablePureSelectorFamilyToken<T, K>
|
|
32
|
-
export function createSelectorFamily<T, K extends Canonical>(
|
|
30
|
+
options: WritablePureSelectorFamilyOptions<T, K, E>,
|
|
31
|
+
): WritablePureSelectorFamilyToken<T, K, E>
|
|
32
|
+
export function createSelectorFamily<T, K extends Canonical, E>(
|
|
33
33
|
store: RootStore,
|
|
34
|
-
options: ReadonlyPureSelectorFamilyOptions<T, K>,
|
|
35
|
-
): ReadonlyPureSelectorFamilyToken<T, K>
|
|
34
|
+
options: ReadonlyPureSelectorFamilyOptions<T, K, E>,
|
|
35
|
+
): ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
36
36
|
export function createSelectorFamily(
|
|
37
37
|
store: RootStore,
|
|
38
38
|
options:
|
|
39
39
|
| ReadonlyHeldSelectorFamilyOptions<any, any>
|
|
40
|
-
| ReadonlyPureSelectorFamilyOptions<any, any>
|
|
40
|
+
| ReadonlyPureSelectorFamilyOptions<any, any, any>
|
|
41
41
|
| WritableHeldSelectorFamilyOptions<any, any>
|
|
42
|
-
| WritablePureSelectorFamilyOptions<any, any>,
|
|
43
|
-
): SelectorFamilyToken<any, any> {
|
|
42
|
+
| WritablePureSelectorFamilyOptions<any, any, any>,
|
|
43
|
+
): SelectorFamilyToken<any, any, any> {
|
|
44
44
|
const isWritable = `set` in options
|
|
45
45
|
const isHeld = `const` in options
|
|
46
46
|
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
StateLifecycleEvent,
|
|
6
6
|
WritablePureSelectorFamilyOptions,
|
|
7
7
|
WritablePureSelectorFamilyToken,
|
|
8
|
+
WritablePureSelectorOptions,
|
|
8
9
|
WritablePureSelectorToken,
|
|
9
10
|
} from "atom.io"
|
|
10
11
|
import { PRETTY_TOKEN_TYPES } from "atom.io"
|
|
@@ -18,18 +19,18 @@ import { createWritablePureSelector } from "../selector"
|
|
|
18
19
|
import type { Store } from "../store"
|
|
19
20
|
import { Subject } from "../subject"
|
|
20
21
|
|
|
21
|
-
export function createWritablePureSelectorFamily<T, K extends Canonical>(
|
|
22
|
+
export function createWritablePureSelectorFamily<T, K extends Canonical, E>(
|
|
22
23
|
store: Store,
|
|
23
|
-
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
24
|
+
options: WritablePureSelectorFamilyOptions<T, K, E>,
|
|
24
25
|
internalRoles?: string[],
|
|
25
|
-
): WritablePureSelectorFamilyToken<T, K> {
|
|
26
|
+
): WritablePureSelectorFamilyToken<T, K, E> {
|
|
26
27
|
const familyKey = options.key
|
|
27
28
|
const type = `writable_pure_selector_family`
|
|
28
29
|
|
|
29
30
|
const familyToken = {
|
|
30
31
|
key: familyKey,
|
|
31
32
|
type,
|
|
32
|
-
} as const satisfies WritablePureSelectorFamilyToken<T, K>
|
|
33
|
+
} as const satisfies WritablePureSelectorFamilyToken<T, K, E>
|
|
33
34
|
|
|
34
35
|
const existing = store.families.get(familyKey)
|
|
35
36
|
if (existing) {
|
|
@@ -41,22 +42,28 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
|
|
|
41
42
|
)
|
|
42
43
|
}
|
|
43
44
|
const subject = new Subject<
|
|
44
|
-
StateLifecycleEvent<WritablePureSelectorToken<T>>
|
|
45
|
+
StateLifecycleEvent<WritablePureSelectorToken<T, K, E>>
|
|
45
46
|
>()
|
|
46
47
|
|
|
47
|
-
const familyFunction =
|
|
48
|
+
const familyFunction = <Key extends K>(
|
|
49
|
+
key: Key,
|
|
50
|
+
): WritablePureSelectorToken<T, Key, E> => {
|
|
48
51
|
const subKey = stringifyJson(key)
|
|
49
|
-
const family: FamilyMetadata = { key: familyKey, subKey }
|
|
52
|
+
const family: FamilyMetadata<Key> = { key: familyKey, subKey }
|
|
50
53
|
const fullKey = `${familyKey}(${subKey})`
|
|
51
54
|
const target = newest(store)
|
|
55
|
+
const individualOptions: WritablePureSelectorOptions<T, E> = {
|
|
56
|
+
key: fullKey,
|
|
57
|
+
get: options.get(key),
|
|
58
|
+
set: options.set(key),
|
|
59
|
+
}
|
|
60
|
+
if (options.catch) {
|
|
61
|
+
individualOptions.catch = options.catch
|
|
62
|
+
}
|
|
52
63
|
|
|
53
|
-
const token = createWritablePureSelector(
|
|
64
|
+
const token = createWritablePureSelector<T, Key, E>(
|
|
54
65
|
target,
|
|
55
|
-
|
|
56
|
-
key: fullKey,
|
|
57
|
-
get: options.get(key),
|
|
58
|
-
set: options.set(key),
|
|
59
|
-
},
|
|
66
|
+
individualOptions,
|
|
60
67
|
family,
|
|
61
68
|
)
|
|
62
69
|
|
|
@@ -78,7 +85,8 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
|
|
|
78
85
|
json: (token) => getJsonToken(store, token),
|
|
79
86
|
})
|
|
80
87
|
},
|
|
81
|
-
|
|
88
|
+
...(options.catch ? { catch: options.catch } : {}),
|
|
89
|
+
}) satisfies WritablePureSelectorFamily<T, K, E>
|
|
82
90
|
|
|
83
91
|
store.families.set(familyKey, selectorFamily)
|
|
84
92
|
return familyToken
|
|
@@ -6,28 +6,31 @@ import { disposeSelector } from "../selector"
|
|
|
6
6
|
import { type Store, withdraw } from "../store"
|
|
7
7
|
import { findInStore } from "./find-in-store"
|
|
8
8
|
|
|
9
|
-
export function disposeFromStore(
|
|
9
|
+
export function disposeFromStore(
|
|
10
|
+
store: Store,
|
|
11
|
+
token: ReadableToken<any, any, any>,
|
|
12
|
+
): void
|
|
10
13
|
|
|
11
14
|
export function disposeFromStore<K extends Canonical, Key extends K>(
|
|
12
15
|
store: Store,
|
|
13
|
-
token: ReadableFamilyToken<any, K>,
|
|
16
|
+
token: ReadableFamilyToken<any, K, any>,
|
|
14
17
|
key: Key,
|
|
15
18
|
): void
|
|
16
19
|
|
|
17
20
|
export function disposeFromStore<K extends Canonical, Key extends K>(
|
|
18
21
|
store: Store,
|
|
19
22
|
...params:
|
|
20
|
-
| [token: ReadableFamilyToken<any, K>, key: Key]
|
|
21
|
-
| [token: ReadableToken<any>]
|
|
23
|
+
| [token: ReadableFamilyToken<any, K, any>, key: Key]
|
|
24
|
+
| [token: ReadableToken<any, any, any>]
|
|
22
25
|
): void
|
|
23
26
|
|
|
24
27
|
export function disposeFromStore(
|
|
25
28
|
store: Store,
|
|
26
29
|
...params:
|
|
27
|
-
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
28
|
-
| [token: ReadableToken<any>]
|
|
30
|
+
| [token: ReadableFamilyToken<any, any, any>, key: Canonical]
|
|
31
|
+
| [token: ReadableToken<any, any, any>]
|
|
29
32
|
): void {
|
|
30
|
-
let token: ReadableToken<any>
|
|
33
|
+
let token: ReadableToken<any, any, any>
|
|
31
34
|
if (params.length === 1) {
|
|
32
35
|
token = params[0]
|
|
33
36
|
} else {
|
|
@@ -38,53 +38,53 @@ export function findInStore<
|
|
|
38
38
|
key: Key,
|
|
39
39
|
): MutableAtomToken<T, K>
|
|
40
40
|
|
|
41
|
-
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
41
|
+
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
42
42
|
store: Store,
|
|
43
|
-
familyToken: RegularAtomFamilyToken<T, K>,
|
|
43
|
+
familyToken: RegularAtomFamilyToken<T, K, E>,
|
|
44
44
|
key: Key,
|
|
45
|
-
): RegularAtomToken<T, K>
|
|
45
|
+
): RegularAtomToken<T, K, E>
|
|
46
46
|
|
|
47
|
-
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
47
|
+
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
48
48
|
store: Store,
|
|
49
|
-
familyToken: AtomFamilyToken<T, K>,
|
|
49
|
+
familyToken: AtomFamilyToken<T, K, E>,
|
|
50
50
|
key: Key,
|
|
51
|
-
): AtomToken<T, K>
|
|
51
|
+
): AtomToken<T, K, E>
|
|
52
52
|
|
|
53
|
-
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
53
|
+
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
54
54
|
store: Store,
|
|
55
|
-
familyToken: WritablePureSelectorFamilyToken<T, K>,
|
|
55
|
+
familyToken: WritablePureSelectorFamilyToken<T, K, E>,
|
|
56
56
|
key: Key,
|
|
57
|
-
): WritablePureSelectorToken<T, K>
|
|
57
|
+
): WritablePureSelectorToken<T, K, E>
|
|
58
58
|
|
|
59
|
-
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
59
|
+
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
60
60
|
store: Store,
|
|
61
|
-
familyToken: ReadonlyPureSelectorFamilyToken<T, K>,
|
|
61
|
+
familyToken: ReadonlyPureSelectorFamilyToken<T, K, E>,
|
|
62
62
|
key: Key,
|
|
63
|
-
): ReadonlyPureSelectorToken<T, K>
|
|
63
|
+
): ReadonlyPureSelectorToken<T, K, E>
|
|
64
64
|
|
|
65
|
-
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
65
|
+
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
66
66
|
store: Store,
|
|
67
|
-
familyToken: SelectorFamilyToken<T, K>,
|
|
67
|
+
familyToken: SelectorFamilyToken<T, K, E>,
|
|
68
68
|
key: Key,
|
|
69
|
-
): SelectorToken<T, K>
|
|
69
|
+
): SelectorToken<T, K, E>
|
|
70
70
|
|
|
71
|
-
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
71
|
+
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
72
72
|
store: Store,
|
|
73
|
-
familyToken: WritableFamilyToken<T, K>,
|
|
73
|
+
familyToken: WritableFamilyToken<T, K, E>,
|
|
74
74
|
key: Key,
|
|
75
|
-
): WritableToken<T, K>
|
|
75
|
+
): WritableToken<T, K, E>
|
|
76
76
|
|
|
77
|
-
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
77
|
+
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
78
78
|
store: Store,
|
|
79
|
-
familyToken: ReadableFamilyToken<T, K>,
|
|
79
|
+
familyToken: ReadableFamilyToken<T, K, E>,
|
|
80
80
|
key: Key,
|
|
81
|
-
): ReadableToken<T, K>
|
|
81
|
+
): ReadableToken<T, K, E>
|
|
82
82
|
|
|
83
83
|
export function findInStore(
|
|
84
84
|
store: Store,
|
|
85
|
-
familyToken: ReadableFamilyToken<any, any>,
|
|
85
|
+
familyToken: ReadableFamilyToken<any, any, any>,
|
|
86
86
|
key: Canonical,
|
|
87
|
-
): ReadableToken<any> {
|
|
87
|
+
): ReadableToken<any, any, any> {
|
|
88
88
|
const family = withdraw(store, familyToken)
|
|
89
89
|
const existingStateToken = seekInStore(store, familyToken, key)
|
|
90
90
|
if (existingStateToken) {
|
|
@@ -24,35 +24,35 @@ export function getFamilyOfToken<
|
|
|
24
24
|
K extends Canonical,
|
|
25
25
|
>(store: Store, token: MutableAtomToken<T, K>): MutableAtomFamily<T, K>
|
|
26
26
|
|
|
27
|
-
export function getFamilyOfToken<T, K extends Canonical>(
|
|
27
|
+
export function getFamilyOfToken<T, K extends Canonical, E>(
|
|
28
28
|
store: Store,
|
|
29
|
-
token: RegularAtomToken<T, K>,
|
|
30
|
-
): RegularAtomFamily<T, K>
|
|
29
|
+
token: RegularAtomToken<T, K, E>,
|
|
30
|
+
): RegularAtomFamily<T, K, E>
|
|
31
31
|
|
|
32
|
-
export function getFamilyOfToken<T, K extends Canonical>(
|
|
32
|
+
export function getFamilyOfToken<T, K extends Canonical, E>(
|
|
33
33
|
store: Store,
|
|
34
|
-
token: WritablePureSelectorToken<T, K>,
|
|
35
|
-
): WritablePureSelectorFamily<T, K>
|
|
34
|
+
token: WritablePureSelectorToken<T, K, E>,
|
|
35
|
+
): WritablePureSelectorFamily<T, K, E>
|
|
36
36
|
|
|
37
|
-
export function getFamilyOfToken<T, K extends Canonical>(
|
|
37
|
+
export function getFamilyOfToken<T, K extends Canonical, E>(
|
|
38
38
|
store: Store,
|
|
39
|
-
token: ReadonlyPureSelectorToken<T, K>,
|
|
40
|
-
): ReadonlyPureSelectorFamily<T, K>
|
|
39
|
+
token: ReadonlyPureSelectorToken<T, K, E>,
|
|
40
|
+
): ReadonlyPureSelectorFamily<T, K, E>
|
|
41
41
|
|
|
42
|
-
export function getFamilyOfToken<T, K extends Canonical>(
|
|
42
|
+
export function getFamilyOfToken<T, K extends Canonical, E>(
|
|
43
43
|
store: Store,
|
|
44
|
-
token: WritableToken<T, K>,
|
|
45
|
-
): WritableFamily<T, K>
|
|
44
|
+
token: WritableToken<T, K, E>,
|
|
45
|
+
): WritableFamily<T, K, E>
|
|
46
46
|
|
|
47
|
-
export function getFamilyOfToken<T, K extends Canonical>(
|
|
47
|
+
export function getFamilyOfToken<T, K extends Canonical, E>(
|
|
48
48
|
store: Store,
|
|
49
|
-
token: ReadableToken<T, K>,
|
|
50
|
-
): ReadableFamily<T, K>
|
|
49
|
+
token: ReadableToken<T, K, E>,
|
|
50
|
+
): ReadableFamily<T, K, E>
|
|
51
51
|
|
|
52
52
|
export function getFamilyOfToken(
|
|
53
53
|
store: Store,
|
|
54
|
-
token: ReadableToken<any, any>,
|
|
55
|
-
): ReadableFamily<any, any> {
|
|
54
|
+
token: ReadableToken<any, any, any>,
|
|
55
|
+
): ReadableFamily<any, any, any> {
|
|
56
56
|
return withdraw(store, {
|
|
57
57
|
// biome-ignore lint/style/noNonNullAssertion: family is required
|
|
58
58
|
key: token.family!.key,
|
|
@@ -8,24 +8,24 @@ import { COUNTERFEIT, mint } from "../store"
|
|
|
8
8
|
|
|
9
9
|
export const MUST_CREATE: unique symbol = Symbol(`MUST_CREATE`)
|
|
10
10
|
|
|
11
|
-
export function mintInStore<T, K extends Canonical, Key extends K>(
|
|
11
|
+
export function mintInStore<T, K extends Canonical, Key extends K, E>(
|
|
12
12
|
store: Store,
|
|
13
|
-
family: ReadableFamily<T, K>,
|
|
13
|
+
family: ReadableFamily<T, K, E>,
|
|
14
14
|
key: Key,
|
|
15
15
|
mustCreate?: typeof MUST_CREATE,
|
|
16
|
-
): WritableToken<T,
|
|
17
|
-
export function mintInStore<T, K extends Canonical, Key extends K>(
|
|
16
|
+
): WritableToken<T, Key, E>
|
|
17
|
+
export function mintInStore<T, K extends Canonical, Key extends K, E>(
|
|
18
18
|
store: Store,
|
|
19
|
-
family: ReadableFamily<T, K>,
|
|
19
|
+
family: ReadableFamily<T, K, E>,
|
|
20
20
|
key: Key,
|
|
21
21
|
mustCreate?: typeof MUST_CREATE,
|
|
22
|
-
): ReadableToken<T,
|
|
23
|
-
export function mintInStore<T, K extends Canonical, Key extends K>(
|
|
22
|
+
): ReadableToken<T, Key, E>
|
|
23
|
+
export function mintInStore<T, K extends Canonical, Key extends K, E>(
|
|
24
24
|
store: Store,
|
|
25
|
-
family: ReadableFamily<T, K>,
|
|
25
|
+
family: ReadableFamily<T, K, E>,
|
|
26
26
|
key: Key,
|
|
27
27
|
mustCreate?: typeof MUST_CREATE,
|
|
28
|
-
): ReadableToken<T,
|
|
28
|
+
): ReadableToken<T, Key, E> {
|
|
29
29
|
const stringKey = stringifyJson(key)
|
|
30
30
|
const molecule = store.molecules.get(stringKey)
|
|
31
31
|
|
|
@@ -43,7 +43,7 @@ export function mintInStore<T, K extends Canonical, Key extends K>(
|
|
|
43
43
|
return mint(family, key, COUNTERFEIT)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
let token: ReadableToken<T,
|
|
46
|
+
let token: ReadableToken<T, Key, E>
|
|
47
47
|
if (mustCreate === MUST_CREATE) {
|
|
48
48
|
store.logger.info(
|
|
49
49
|
`👪`,
|
|
@@ -19,7 +19,7 @@ import type {
|
|
|
19
19
|
import type { Canonical } from "atom.io/json"
|
|
20
20
|
import { stringifyJson } from "atom.io/json"
|
|
21
21
|
|
|
22
|
-
import type {
|
|
22
|
+
import type { ReadableState } from ".."
|
|
23
23
|
import { newest } from "../lineage"
|
|
24
24
|
import type { Transceiver } from "../mutable"
|
|
25
25
|
import { deposit, type Store } from "../store"
|
|
@@ -32,59 +32,59 @@ export function seekInStore<
|
|
|
32
32
|
store: Store,
|
|
33
33
|
token: MutableAtomFamilyToken<T, K>,
|
|
34
34
|
key: Key,
|
|
35
|
-
): MutableAtomToken<T,
|
|
35
|
+
): MutableAtomToken<T, Key> | undefined
|
|
36
36
|
|
|
37
|
-
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
37
|
+
export function seekInStore<T, K extends Canonical, Key extends K, E>(
|
|
38
38
|
store: Store,
|
|
39
|
-
token: RegularAtomFamilyToken<T, K>,
|
|
39
|
+
token: RegularAtomFamilyToken<T, K, E>,
|
|
40
40
|
key: Key,
|
|
41
|
-
): RegularAtomToken<T,
|
|
41
|
+
): RegularAtomToken<T, Key, E> | undefined
|
|
42
42
|
|
|
43
|
-
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
43
|
+
export function seekInStore<T, K extends Canonical, Key extends K, E>(
|
|
44
44
|
store: Store,
|
|
45
|
-
token: AtomFamilyToken<T, K>,
|
|
45
|
+
token: AtomFamilyToken<T, K, E>,
|
|
46
46
|
key: Key,
|
|
47
|
-
): AtomToken<T,
|
|
47
|
+
): AtomToken<T, Key, E> | undefined
|
|
48
48
|
|
|
49
|
-
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
49
|
+
export function seekInStore<T, K extends Canonical, Key extends K, E>(
|
|
50
50
|
store: Store,
|
|
51
|
-
token: WritablePureSelectorFamilyToken<T, K>,
|
|
51
|
+
token: WritablePureSelectorFamilyToken<T, K, E>,
|
|
52
52
|
key: Key,
|
|
53
|
-
): WritablePureSelectorToken<T,
|
|
53
|
+
): WritablePureSelectorToken<T, Key, E> | undefined
|
|
54
54
|
|
|
55
|
-
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
55
|
+
export function seekInStore<T, K extends Canonical, Key extends K, E>(
|
|
56
56
|
store: Store,
|
|
57
|
-
token: ReadonlyPureSelectorFamilyToken<T, K>,
|
|
57
|
+
token: ReadonlyPureSelectorFamilyToken<T, K, E>,
|
|
58
58
|
key: Key,
|
|
59
|
-
): ReadonlyPureSelectorToken<T,
|
|
59
|
+
): ReadonlyPureSelectorToken<T, Key, E> | undefined
|
|
60
60
|
|
|
61
|
-
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
61
|
+
export function seekInStore<T, K extends Canonical, Key extends K, E>(
|
|
62
62
|
store: Store,
|
|
63
|
-
token: SelectorFamilyToken<T, K>,
|
|
63
|
+
token: SelectorFamilyToken<T, K, E>,
|
|
64
64
|
key: Key,
|
|
65
|
-
): SelectorToken<T,
|
|
65
|
+
): SelectorToken<T, Key, E> | undefined
|
|
66
66
|
|
|
67
|
-
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
67
|
+
export function seekInStore<T, K extends Canonical, Key extends K, E>(
|
|
68
68
|
store: Store,
|
|
69
|
-
token: WritableFamilyToken<T, K>,
|
|
69
|
+
token: WritableFamilyToken<T, K, E>,
|
|
70
70
|
key: Key,
|
|
71
|
-
): WritableToken<T,
|
|
71
|
+
): WritableToken<T, Key, E> | undefined
|
|
72
72
|
|
|
73
|
-
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
73
|
+
export function seekInStore<T, K extends Canonical, Key extends K, E>(
|
|
74
74
|
store: Store,
|
|
75
|
-
token: ReadableFamilyToken<T, K>,
|
|
75
|
+
token: ReadableFamilyToken<T, K, E>,
|
|
76
76
|
key: Key,
|
|
77
|
-
): ReadableToken<T,
|
|
77
|
+
): ReadableToken<T, Key, E> | undefined
|
|
78
78
|
|
|
79
79
|
export function seekInStore(
|
|
80
80
|
store: Store,
|
|
81
|
-
token: ReadableFamilyToken<any, any>,
|
|
81
|
+
token: ReadableFamilyToken<any, any, any>,
|
|
82
82
|
key: Canonical,
|
|
83
|
-
): ReadableToken<any> | undefined {
|
|
83
|
+
): ReadableToken<any, any, any> | undefined {
|
|
84
84
|
const subKey = stringifyJson(key)
|
|
85
85
|
const fullKey = `${token.key}(${subKey})`
|
|
86
86
|
const target = newest(store)
|
|
87
|
-
let state:
|
|
87
|
+
let state: ReadableState<any, any> | undefined
|
|
88
88
|
switch (token.type) {
|
|
89
89
|
case `atom_family`:
|
|
90
90
|
case `mutable_atom_family`:
|