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
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { ReadableToken } from "atom.io"
|
|
1
|
+
import type { ReadableToken, ViewOf } from "atom.io"
|
|
2
2
|
import { type Canonical, stringifyJson } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { ReadableFamily } from ".."
|
|
5
5
|
import type { Store } from "../store"
|
|
6
6
|
|
|
7
|
-
export function getFallback<T, K extends Canonical>(
|
|
7
|
+
export function getFallback<T, K extends Canonical, E>(
|
|
8
8
|
store: Store,
|
|
9
|
-
token: ReadableToken<T, K>,
|
|
10
|
-
family: ReadableFamily<T, K>,
|
|
9
|
+
token: ReadableToken<T, K, E>,
|
|
10
|
+
family: ReadableFamily<T, K, E>,
|
|
11
11
|
subKey: K,
|
|
12
|
-
): T {
|
|
12
|
+
): ViewOf<E | T> {
|
|
13
13
|
const disposal = store.disposalTraces.buffer.find(
|
|
14
14
|
(item) => item?.key === stringifyJson(subKey),
|
|
15
15
|
)
|
|
@@ -31,7 +31,7 @@ export function getFallback<T, K extends Canonical>(
|
|
|
31
31
|
}
|
|
32
32
|
const defaultValue = new family.class()
|
|
33
33
|
store.defaults.set(family.key, defaultValue)
|
|
34
|
-
return defaultValue
|
|
34
|
+
return defaultValue.READONLY_VIEW
|
|
35
35
|
}
|
|
36
36
|
case `atom_family`: {
|
|
37
37
|
if (store.defaults.has(family.key)) {
|
|
@@ -40,7 +40,7 @@ export function getFallback<T, K extends Canonical>(
|
|
|
40
40
|
const def = family.default as (key: K) => T
|
|
41
41
|
const defaultValue = def(subKey)
|
|
42
42
|
store.defaults.set(family.key, defaultValue)
|
|
43
|
-
return defaultValue
|
|
43
|
+
return defaultValue as ViewOf<T>
|
|
44
44
|
}
|
|
45
45
|
case `readonly_pure_selector_family`:
|
|
46
46
|
case `writable_pure_selector_family`:
|
|
@@ -51,7 +51,7 @@ export function getFallback<T, K extends Canonical>(
|
|
|
51
51
|
}
|
|
52
52
|
const defaultValue = family.default(subKey)
|
|
53
53
|
store.defaults.set(family.key, defaultValue)
|
|
54
|
-
return defaultValue
|
|
54
|
+
return defaultValue as ViewOf<T>
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReadableFamilyToken, ReadableToken } from "atom.io"
|
|
1
|
+
import type { ReadableFamilyToken, ReadableToken, ViewOf } from "atom.io"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import { type Store, withdraw } from "../store"
|
|
@@ -8,25 +8,30 @@ import { reduceReference } from "./reduce-reference"
|
|
|
8
8
|
|
|
9
9
|
export function getFromStore<T>(store: Store, token: ReadableToken<T>): T
|
|
10
10
|
|
|
11
|
-
export function getFromStore<T,
|
|
11
|
+
export function getFromStore<T, E>(
|
|
12
12
|
store: Store,
|
|
13
|
-
token:
|
|
13
|
+
token: ReadableToken<T, any, E>,
|
|
14
|
+
): E | T
|
|
15
|
+
|
|
16
|
+
export function getFromStore<T, K extends Canonical, E>(
|
|
17
|
+
store: Store,
|
|
18
|
+
token: ReadableFamilyToken<T, K, E>,
|
|
14
19
|
key: K,
|
|
15
|
-
): T
|
|
20
|
+
): ViewOf<E | T>
|
|
16
21
|
|
|
17
|
-
export function getFromStore<T, K extends Canonical, Key extends K>(
|
|
22
|
+
export function getFromStore<T, K extends Canonical, Key extends K, E>(
|
|
18
23
|
store: Store,
|
|
19
24
|
...params:
|
|
20
|
-
| [token: ReadableFamilyToken<T, K>, key: Key]
|
|
21
|
-
| [token: ReadableToken<T>]
|
|
22
|
-
): T
|
|
25
|
+
| [token: ReadableFamilyToken<T, K, E>, key: Key]
|
|
26
|
+
| [token: ReadableToken<T, any, E>]
|
|
27
|
+
): ViewOf<E | T>
|
|
23
28
|
|
|
24
|
-
export function getFromStore<T, K extends Canonical, Key extends K>(
|
|
29
|
+
export function getFromStore<T, K extends Canonical, Key extends K, E>(
|
|
25
30
|
store: Store,
|
|
26
31
|
...params:
|
|
27
|
-
| [token: ReadableFamilyToken<T, K>, key: Key]
|
|
28
|
-
| [token: ReadableToken<T>]
|
|
29
|
-
):
|
|
32
|
+
| [token: ReadableFamilyToken<T, K, E>, key: Key]
|
|
33
|
+
| [token: ReadableToken<T, any, E>]
|
|
34
|
+
): ViewOf<E | T> {
|
|
30
35
|
const { token, family, subKey } = reduceReference(store, ...params)
|
|
31
36
|
|
|
32
37
|
if (`counterfeit` in token && family && subKey) {
|
|
@@ -5,21 +5,21 @@ import { readFromCache, writeToCache } from "../caching"
|
|
|
5
5
|
import { isFn } from "../is-fn"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
|
|
8
|
-
export function readOrComputeValue<T>(
|
|
8
|
+
export function readOrComputeValue<T, E>(
|
|
9
9
|
target: Store,
|
|
10
|
-
state: ReadableState<T>,
|
|
10
|
+
state: ReadableState<T, E>,
|
|
11
11
|
mut?: undefined,
|
|
12
|
-
): ViewOf<T>
|
|
13
|
-
export function readOrComputeValue<T>(
|
|
12
|
+
): ViewOf<E | T>
|
|
13
|
+
export function readOrComputeValue<T, E>(
|
|
14
14
|
target: Store,
|
|
15
|
-
state: ReadableState<T>,
|
|
15
|
+
state: ReadableState<T, E>,
|
|
16
16
|
mut: `mut`,
|
|
17
|
-
): T
|
|
18
|
-
export function readOrComputeValue<T>(
|
|
17
|
+
): E | T
|
|
18
|
+
export function readOrComputeValue<T, E>(
|
|
19
19
|
target: Store,
|
|
20
|
-
state: ReadableState<T>,
|
|
20
|
+
state: ReadableState<T, E>,
|
|
21
21
|
mut: `mut` | undefined,
|
|
22
|
-
): T {
|
|
22
|
+
): E | T {
|
|
23
23
|
if (target.valueMap.has(state.key)) {
|
|
24
24
|
return readFromCache(target, state, mut)
|
|
25
25
|
}
|
|
@@ -27,16 +27,80 @@ export function readOrComputeValue<T>(
|
|
|
27
27
|
const { key } = state
|
|
28
28
|
switch (state.type) {
|
|
29
29
|
case `readonly_held_selector`:
|
|
30
|
-
case `readonly_pure_selector`:
|
|
31
30
|
case `writable_held_selector`:
|
|
32
|
-
case `writable_pure_selector`:
|
|
33
31
|
target.logger.info(`🧮`, state.type, key, `computing value`)
|
|
34
32
|
return state.getFrom(target)
|
|
33
|
+
case `readonly_pure_selector`:
|
|
34
|
+
case `writable_pure_selector`: {
|
|
35
|
+
let val: E | T
|
|
36
|
+
target.logger.info(`🧮`, state.type, key, `computing value`)
|
|
37
|
+
try {
|
|
38
|
+
val = state.getFrom(target)
|
|
39
|
+
if (val instanceof Promise) {
|
|
40
|
+
return (val as Promise<E & T>).catch((e) => {
|
|
41
|
+
target.logger.error(`💥`, state.type, key, `rejected:`, e)
|
|
42
|
+
if (state.catch) {
|
|
43
|
+
for (const Class of state.catch) {
|
|
44
|
+
if (e instanceof Class) {
|
|
45
|
+
return writeToCache(target, state, e)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw e
|
|
50
|
+
}) as E | T
|
|
51
|
+
}
|
|
52
|
+
} catch (e) {
|
|
53
|
+
target.logger.error(`💥`, state.type, key, `rejected:`, e)
|
|
54
|
+
if (state.catch) {
|
|
55
|
+
for (const Class of state.catch) {
|
|
56
|
+
if (e instanceof Class) {
|
|
57
|
+
return writeToCache(target, state, e)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw e
|
|
62
|
+
}
|
|
63
|
+
const cachedValue = writeToCache(target, state, val)
|
|
64
|
+
return cachedValue
|
|
65
|
+
}
|
|
35
66
|
case `atom`: {
|
|
36
|
-
let def: T
|
|
67
|
+
let def: E | T
|
|
37
68
|
if (isFn(state.default)) {
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
try {
|
|
70
|
+
def = state.default()
|
|
71
|
+
if (def instanceof Promise) {
|
|
72
|
+
def = (def as Promise<T> & T).catch<E | T>((e) => {
|
|
73
|
+
target.logger.error(`💥`, state.type, key, `rejected:`, e)
|
|
74
|
+
if (state.catch) {
|
|
75
|
+
for (const Class of state.catch) {
|
|
76
|
+
if (e instanceof Class) {
|
|
77
|
+
def = writeToCache(target, state, e)
|
|
78
|
+
return def
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
throw e
|
|
83
|
+
}) as E | T
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {
|
|
86
|
+
target.logger.error(`💥`, state.type, key, `rejected:`, e)
|
|
87
|
+
if (state.catch) {
|
|
88
|
+
for (const Class of state.catch) {
|
|
89
|
+
if (e instanceof Class) {
|
|
90
|
+
def = writeToCache(target, state, e)
|
|
91
|
+
target.logger.info(
|
|
92
|
+
`✨`,
|
|
93
|
+
state.type,
|
|
94
|
+
key,
|
|
95
|
+
`computed default`,
|
|
96
|
+
def,
|
|
97
|
+
)
|
|
98
|
+
return def
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw e
|
|
103
|
+
}
|
|
40
104
|
} else {
|
|
41
105
|
def = state.default
|
|
42
106
|
target.logger.info(`✨`, state.type, key, `using static default`, def)
|
|
@@ -13,27 +13,27 @@ import { mintInStore, MUST_CREATE } from "../families/mint-in-store"
|
|
|
13
13
|
import type { Store } from "../store"
|
|
14
14
|
import { withdraw } from "../store"
|
|
15
15
|
|
|
16
|
-
export function reduceReference<T, K extends Canonical>(
|
|
16
|
+
export function reduceReference<T, K extends Canonical, E>(
|
|
17
17
|
store: Store,
|
|
18
18
|
...params:
|
|
19
|
-
| [token: ReadableFamilyToken<T, K>, key: K]
|
|
20
|
-
| [token: ReadableToken<T>]
|
|
19
|
+
| [token: ReadableFamilyToken<T, K, E>, key: K]
|
|
20
|
+
| [token: ReadableToken<T, K, E>]
|
|
21
21
|
): {
|
|
22
|
-
token: ReadableToken<T, K>
|
|
23
|
-
family: ReadableFamily<T, K> | undefined
|
|
22
|
+
token: ReadableToken<T, K, E>
|
|
23
|
+
family: ReadableFamily<T, K, E> | undefined
|
|
24
24
|
subKey: K | undefined
|
|
25
25
|
isNew: boolean
|
|
26
26
|
} {
|
|
27
|
-
let existingToken: ReadableToken<T> | undefined
|
|
28
|
-
let brandNewToken: ReadableToken<T> | undefined
|
|
29
|
-
let family: ReadableFamily<T, K> | undefined
|
|
27
|
+
let existingToken: ReadableToken<T, K, E> | undefined
|
|
28
|
+
let brandNewToken: ReadableToken<T, K, E> | undefined
|
|
29
|
+
let family: ReadableFamily<T, K, E> | undefined
|
|
30
30
|
let subKey: K | undefined
|
|
31
|
-
let token: ReadableToken<T, K>
|
|
31
|
+
let token: ReadableToken<T, K, E>
|
|
32
32
|
if (params.length === 1) {
|
|
33
33
|
token = params[0]
|
|
34
34
|
if (`family` in token) {
|
|
35
35
|
const familyToken = getFamilyOfToken(store, token)
|
|
36
|
-
family = withdraw(store, familyToken) as ReadableFamily<T, K>
|
|
36
|
+
family = withdraw(store, familyToken) as ReadableFamily<T, K, E>
|
|
37
37
|
subKey = parseJson(token.family.subKey)
|
|
38
38
|
existingToken = seekInStore(store, familyToken, subKey)
|
|
39
39
|
if (`counterfeit` in token) {
|
package/src/internal/index.ts
CHANGED
|
@@ -61,12 +61,13 @@ export type AtomIOState = {
|
|
|
61
61
|
install: (store: RootStore) => void
|
|
62
62
|
subject: Subject<StateUpdate<any>>
|
|
63
63
|
}
|
|
64
|
-
export type RegularAtom<T> = Flat<
|
|
64
|
+
export type RegularAtom<T, E> = Flat<
|
|
65
65
|
AtomIOState & {
|
|
66
66
|
type: `atom`
|
|
67
67
|
default: T | (() => T)
|
|
68
68
|
cleanup?: () => void
|
|
69
69
|
internalRoles?: internalRole[]
|
|
70
|
+
catch?: readonly (new () => E)[]
|
|
70
71
|
}
|
|
71
72
|
>
|
|
72
73
|
export type MutableAtom<T extends Transceiver<any, any, any>> = Flat<
|
|
@@ -76,8 +77,8 @@ export type MutableAtom<T extends Transceiver<any, any, any>> = Flat<
|
|
|
76
77
|
cleanup?: () => void
|
|
77
78
|
}
|
|
78
79
|
>
|
|
79
|
-
export type Atom<T> =
|
|
80
|
-
| RegularAtom<T>
|
|
80
|
+
export type Atom<T, E> =
|
|
81
|
+
| RegularAtom<T, E>
|
|
81
82
|
| (T extends Transceiver<any, any, any> ? MutableAtom<T> : never)
|
|
82
83
|
|
|
83
84
|
export type WritableHeldSelector<T> = Flat<
|
|
@@ -95,48 +96,52 @@ export type ReadonlyHeldSelector<T> = Flat<
|
|
|
95
96
|
getFrom: (target: Store) => T
|
|
96
97
|
}
|
|
97
98
|
>
|
|
98
|
-
export type WritablePureSelector<T> = Flat<
|
|
99
|
+
export type WritablePureSelector<T, E> = Flat<
|
|
99
100
|
AtomIOState & {
|
|
100
101
|
type: `writable_pure_selector`
|
|
101
|
-
getFrom: (target: Store) => T
|
|
102
|
+
getFrom: (target: Store) => E | T
|
|
102
103
|
setSelf: (newValue: T) => void
|
|
104
|
+
catch?: readonly (new () => E)[]
|
|
103
105
|
}
|
|
104
106
|
>
|
|
105
|
-
export type ReadonlyPureSelector<T> = Flat<
|
|
107
|
+
export type ReadonlyPureSelector<T, E> = Flat<
|
|
106
108
|
AtomIOState & {
|
|
107
109
|
type: `readonly_pure_selector`
|
|
108
|
-
getFrom: (target: Store) => T
|
|
110
|
+
getFrom: (target: Store) => E | T
|
|
111
|
+
catch?: readonly (new () => E)[]
|
|
109
112
|
}
|
|
110
113
|
>
|
|
111
|
-
export type ReadonlySelector<T> =
|
|
114
|
+
export type ReadonlySelector<T, E> =
|
|
112
115
|
| ReadonlyHeldSelector<T>
|
|
113
|
-
| ReadonlyPureSelector<T>
|
|
114
|
-
export type WritableSelector<T> =
|
|
116
|
+
| ReadonlyPureSelector<T, E>
|
|
117
|
+
export type WritableSelector<T, E> =
|
|
115
118
|
| WritableHeldSelector<T>
|
|
116
|
-
| WritablePureSelector<T>
|
|
119
|
+
| WritablePureSelector<T, E>
|
|
117
120
|
export type HeldSelector<T> = ReadonlyHeldSelector<T> | WritableHeldSelector<T>
|
|
118
|
-
export type PureSelector<T> =
|
|
119
|
-
|
|
121
|
+
export type PureSelector<T, E> =
|
|
122
|
+
| ReadonlyPureSelector<T, E>
|
|
123
|
+
| WritablePureSelector<T, E>
|
|
124
|
+
export type Selector<T, E> =
|
|
120
125
|
| ReadonlyHeldSelector<T>
|
|
121
|
-
| ReadonlyPureSelector<T>
|
|
126
|
+
| ReadonlyPureSelector<T, E>
|
|
122
127
|
| WritableHeldSelector<T>
|
|
123
|
-
| WritablePureSelector<T>
|
|
128
|
+
| WritablePureSelector<T, E>
|
|
124
129
|
|
|
125
|
-
export type WritableState<T> = Atom<T> | WritableSelector<T>
|
|
126
|
-
export type ReadableState<T> = Atom<T> | Selector<T>
|
|
130
|
+
export type WritableState<T, E> = Atom<T, E> | WritableSelector<T, E>
|
|
131
|
+
export type ReadableState<T, E> = Atom<T, E> | Selector<T, E>
|
|
127
132
|
|
|
128
133
|
// biome-ignore format: intersection
|
|
129
|
-
export type RegularAtomFamily<T, K extends Canonical> =
|
|
134
|
+
export type RegularAtomFamily<T, K extends Canonical, E = never> =
|
|
130
135
|
& Flat<
|
|
131
|
-
& RegularAtomFamilyToken<T, K>
|
|
136
|
+
& RegularAtomFamilyToken<T, K, E>
|
|
132
137
|
& {
|
|
133
138
|
default: T | ((key: K) => T)
|
|
134
139
|
install: (store: RootStore) => void
|
|
135
140
|
internalRoles: string[] | undefined
|
|
136
|
-
subject: Subject<StateLifecycleEvent<RegularAtomToken<T>>>
|
|
141
|
+
subject: Subject<StateLifecycleEvent<RegularAtomToken<T, K, E>>>
|
|
137
142
|
}
|
|
138
143
|
>
|
|
139
|
-
& ((key:
|
|
144
|
+
& (<Key extends K>(key: Key) => RegularAtomToken<T, Key, E>)
|
|
140
145
|
|
|
141
146
|
// biome-ignore format: intersection
|
|
142
147
|
export type MutableAtomFamily<
|
|
@@ -152,24 +157,24 @@ export type MutableAtomFamily<
|
|
|
152
157
|
subject: Subject<StateLifecycleEvent<MutableAtomToken<T>>>
|
|
153
158
|
}
|
|
154
159
|
>
|
|
155
|
-
& ((key:
|
|
160
|
+
& (<Key extends K>(key: Key) => MutableAtomToken<T, Key>)
|
|
156
161
|
|
|
157
|
-
export type AtomFamily<T, K extends Canonical
|
|
162
|
+
export type AtomFamily<T, K extends Canonical, E> =
|
|
158
163
|
| MutableAtomFamily<T extends Transceiver<any, any, any> ? T : never, K>
|
|
159
|
-
| RegularAtomFamily<T, K>
|
|
164
|
+
| RegularAtomFamily<T, K, E>
|
|
160
165
|
|
|
161
166
|
// biome-ignore format: intersection
|
|
162
|
-
export type WritablePureSelectorFamily<T, K extends Canonical> =
|
|
167
|
+
export type WritablePureSelectorFamily<T, K extends Canonical, E> =
|
|
163
168
|
& Flat<
|
|
164
|
-
& WritablePureSelectorFamilyToken<T, K>
|
|
169
|
+
& WritablePureSelectorFamilyToken<T, K, E>
|
|
165
170
|
& {
|
|
166
171
|
default: (key: K) => T,
|
|
167
172
|
install: (store: RootStore) => void
|
|
168
173
|
internalRoles: string[] | undefined
|
|
169
|
-
subject: Subject<StateLifecycleEvent<WritablePureSelectorToken<T>>>
|
|
174
|
+
subject: Subject<StateLifecycleEvent<WritablePureSelectorToken<T, K, E>>>
|
|
170
175
|
}
|
|
171
176
|
>
|
|
172
|
-
& ((key:
|
|
177
|
+
& (<Key extends K>(key: Key) => WritablePureSelectorToken<T, Key, E>)
|
|
173
178
|
|
|
174
179
|
// biome-ignore format: intersection
|
|
175
180
|
export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
@@ -179,23 +184,23 @@ export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
|
179
184
|
default: (key: K) => T,
|
|
180
185
|
install: (store: RootStore) => void
|
|
181
186
|
internalRoles: string[] | undefined
|
|
182
|
-
subject: Subject<StateLifecycleEvent<WritableHeldSelectorToken<T>>>
|
|
187
|
+
subject: Subject<StateLifecycleEvent<WritableHeldSelectorToken<T, K>>>
|
|
183
188
|
}
|
|
184
189
|
>
|
|
185
|
-
& ((key:
|
|
190
|
+
& (<Key extends K>(key: Key) => WritableHeldSelectorToken<T, Key>)
|
|
186
191
|
|
|
187
192
|
// biome-ignore format: intersection
|
|
188
|
-
export type ReadonlyPureSelectorFamily<T, K extends Canonical> =
|
|
193
|
+
export type ReadonlyPureSelectorFamily<T, K extends Canonical, E> =
|
|
189
194
|
& Flat<
|
|
190
|
-
& ReadonlyPureSelectorFamilyToken<T, K>
|
|
195
|
+
& ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
191
196
|
& {
|
|
192
197
|
default: (key: K) => T,
|
|
193
198
|
install: (store: RootStore) => void
|
|
194
199
|
internalRoles: string[] | undefined
|
|
195
|
-
subject: Subject<StateLifecycleEvent<ReadonlyPureSelectorToken<T>>>
|
|
200
|
+
subject: Subject<StateLifecycleEvent<ReadonlyPureSelectorToken<T, K, E>>>
|
|
196
201
|
}
|
|
197
202
|
>
|
|
198
|
-
& ((key:
|
|
203
|
+
& (<Key extends K>(key: Key) => ReadonlyPureSelectorToken<T, Key, E>)
|
|
199
204
|
|
|
200
205
|
// biome-ignore format: intersection
|
|
201
206
|
export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
|
|
@@ -208,37 +213,37 @@ export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
|
|
|
208
213
|
subject: Subject<StateLifecycleEvent<ReadonlyHeldSelectorToken<T>>>
|
|
209
214
|
}
|
|
210
215
|
>
|
|
211
|
-
& ((key:
|
|
216
|
+
& (<Key extends K>(key: Key) => ReadonlyHeldSelectorToken<T, Key>)
|
|
212
217
|
|
|
213
|
-
export type PureSelectorFamily<T, K extends Canonical> =
|
|
214
|
-
| ReadonlyPureSelectorFamily<T, K>
|
|
215
|
-
| WritablePureSelectorFamily<T, K>
|
|
218
|
+
export type PureSelectorFamily<T, K extends Canonical, E> =
|
|
219
|
+
| ReadonlyPureSelectorFamily<T, K, E>
|
|
220
|
+
| WritablePureSelectorFamily<T, K, E>
|
|
216
221
|
|
|
217
222
|
export type HeldSelectorFamily<T, K extends Canonical> =
|
|
218
223
|
| ReadonlyHeldSelectorFamily<T, K>
|
|
219
224
|
| WritableHeldSelectorFamily<T, K>
|
|
220
225
|
|
|
221
|
-
export type ReadonlySelectorFamily<T, K extends Canonical> =
|
|
226
|
+
export type ReadonlySelectorFamily<T, K extends Canonical, E> =
|
|
222
227
|
| ReadonlyHeldSelectorFamily<T, K>
|
|
223
|
-
| ReadonlyPureSelectorFamily<T, K>
|
|
228
|
+
| ReadonlyPureSelectorFamily<T, K, E>
|
|
224
229
|
|
|
225
|
-
export type WritableSelectorFamily<T, K extends Canonical> =
|
|
230
|
+
export type WritableSelectorFamily<T, K extends Canonical, E> =
|
|
226
231
|
| WritableHeldSelectorFamily<T, K>
|
|
227
|
-
| WritablePureSelectorFamily<T, K>
|
|
232
|
+
| WritablePureSelectorFamily<T, K, E>
|
|
228
233
|
|
|
229
|
-
export type SelectorFamily<T, K extends Canonical> =
|
|
234
|
+
export type SelectorFamily<T, K extends Canonical, E> =
|
|
230
235
|
| HeldSelectorFamily<T, K>
|
|
231
|
-
| PureSelectorFamily<T, K>
|
|
236
|
+
| PureSelectorFamily<T, K, E>
|
|
232
237
|
|
|
233
|
-
export type WritableFamily<T, K extends Canonical> =
|
|
234
|
-
| AtomFamily<T, K>
|
|
235
|
-
|
|
|
236
|
-
export type ReadableFamily<T, K extends Canonical> =
|
|
237
|
-
| AtomFamily<T, K>
|
|
238
|
-
| SelectorFamily<T, K>
|
|
238
|
+
export type WritableFamily<T, K extends Canonical, E> =
|
|
239
|
+
| AtomFamily<T, K, E>
|
|
240
|
+
| WritableSelectorFamily<T, K, E>
|
|
241
|
+
export type ReadableFamily<T, K extends Canonical, E> =
|
|
242
|
+
| AtomFamily<T, K, E>
|
|
243
|
+
| SelectorFamily<T, K, E>
|
|
239
244
|
|
|
240
245
|
export type AtomIOInternalResource =
|
|
241
|
-
| ReadableFamily<any, any>
|
|
242
|
-
| ReadableState<any>
|
|
246
|
+
| ReadableFamily<any, any, any>
|
|
247
|
+
| ReadableState<any, any>
|
|
243
248
|
| Timeline<any>
|
|
244
249
|
| Transaction<any>
|
|
@@ -199,7 +199,8 @@ export class Join<
|
|
|
199
199
|
this.core = { relatedKeysAtoms }
|
|
200
200
|
const getRelatedKeys: Read<
|
|
201
201
|
(key: string) => SetRTX<AType> | SetRTX<BType>
|
|
202
|
-
> = ({ get }, key) =>
|
|
202
|
+
> = ({ get }, key) =>
|
|
203
|
+
get(relatedKeysAtoms, key) as SetRTX<AType> | SetRTX<BType>
|
|
203
204
|
const addRelation: Write<(a: string, b: string) => void> = (
|
|
204
205
|
{ set },
|
|
205
206
|
a,
|
|
@@ -331,7 +332,7 @@ export class Join<
|
|
|
331
332
|
let contentAtoms: RegularAtomFamilyToken<Content, string>
|
|
332
333
|
|
|
333
334
|
if (defaultContent) {
|
|
334
|
-
contentAtoms = createRegularAtomFamily<Content, ContentKey>(
|
|
335
|
+
contentAtoms = createRegularAtomFamily<Content, ContentKey, never>(
|
|
335
336
|
store,
|
|
336
337
|
{
|
|
337
338
|
key: `${options.key}/content`,
|
|
@@ -398,7 +399,7 @@ export class Join<
|
|
|
398
399
|
)
|
|
399
400
|
|
|
400
401
|
const createSingleKeySelectorFamily = () =>
|
|
401
|
-
createReadonlyPureSelectorFamily<string | null, string>(
|
|
402
|
+
createReadonlyPureSelectorFamily<string | null, string, never>(
|
|
402
403
|
store,
|
|
403
404
|
{
|
|
404
405
|
key: `${options.key}/singleRelatedKey`,
|
|
@@ -415,7 +416,7 @@ export class Join<
|
|
|
415
416
|
[`join`, `keys`],
|
|
416
417
|
)
|
|
417
418
|
const getMultipleKeySelectorFamily = () => {
|
|
418
|
-
return createReadonlyPureSelectorFamily<string[], string>(
|
|
419
|
+
return createReadonlyPureSelectorFamily<string[], string, never>(
|
|
419
420
|
store,
|
|
420
421
|
{
|
|
421
422
|
key: `${options.key}/multipleRelatedKeys`,
|
|
@@ -431,7 +432,11 @@ export class Join<
|
|
|
431
432
|
)
|
|
432
433
|
}
|
|
433
434
|
const createSingleEntrySelectorFamily = () =>
|
|
434
|
-
createReadonlyPureSelectorFamily<
|
|
435
|
+
createReadonlyPureSelectorFamily<
|
|
436
|
+
[string, ViewOf<Content>] | null,
|
|
437
|
+
string,
|
|
438
|
+
never
|
|
439
|
+
>(
|
|
435
440
|
store,
|
|
436
441
|
{
|
|
437
442
|
key: `${options.key}/singleRelatedEntry`,
|
|
@@ -454,7 +459,11 @@ export class Join<
|
|
|
454
459
|
[`join`, `entries`],
|
|
455
460
|
)
|
|
456
461
|
const getMultipleEntrySelectorFamily = () =>
|
|
457
|
-
createReadonlyPureSelectorFamily<
|
|
462
|
+
createReadonlyPureSelectorFamily<
|
|
463
|
+
[string, ViewOf<Content>][],
|
|
464
|
+
string,
|
|
465
|
+
never
|
|
466
|
+
>(
|
|
458
467
|
store,
|
|
459
468
|
{
|
|
460
469
|
key: `${options.key}/multipleRelatedEntries`,
|
|
@@ -12,12 +12,13 @@ export const getJsonFamily = <
|
|
|
12
12
|
>(
|
|
13
13
|
mutableAtomFamily: MutableAtomFamilyToken<Core, Key>,
|
|
14
14
|
store: Store,
|
|
15
|
-
): WritablePureSelectorFamily<ReturnType<Core[`toJSON`]>, Key> => {
|
|
15
|
+
): WritablePureSelectorFamily<ReturnType<Core[`toJSON`]>, Key, never> => {
|
|
16
16
|
const target = newest(store)
|
|
17
17
|
const key = `${mutableAtomFamily.key}:JSON`
|
|
18
18
|
const jsonFamily = target.families.get(key) as WritablePureSelectorFamily<
|
|
19
19
|
ReturnType<Core[`toJSON`]>,
|
|
20
|
-
Key
|
|
20
|
+
Key,
|
|
21
|
+
never
|
|
21
22
|
>
|
|
22
23
|
return jsonFamily
|
|
23
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MutableAtomFamilyToken } from "atom.io"
|
|
2
2
|
import type { Json } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { RegularAtomFamily } from ".."
|
|
5
5
|
import { newest } from "../lineage"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
import type { SignalFrom, Transceiver } from "./transceiver"
|
|
@@ -12,11 +12,13 @@ export const getUpdateFamily = <
|
|
|
12
12
|
>(
|
|
13
13
|
mutableAtomFamily: MutableAtomFamilyToken<T, K>,
|
|
14
14
|
store: Store,
|
|
15
|
-
):
|
|
15
|
+
): RegularAtomFamily<SignalFrom<T>, K, never> => {
|
|
16
16
|
const target = newest(store)
|
|
17
17
|
const key = `*${mutableAtomFamily.key}`
|
|
18
|
-
const updateFamily
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const updateFamily = target.families.get(key) as RegularAtomFamily<
|
|
19
|
+
SignalFrom<T>,
|
|
20
|
+
K,
|
|
21
|
+
never
|
|
22
|
+
>
|
|
21
23
|
return updateFamily
|
|
22
24
|
}
|
|
@@ -18,7 +18,11 @@ export class FamilyTracker<
|
|
|
18
18
|
public readonly mutableAtoms: MutableAtomFamily<T, K>
|
|
19
19
|
|
|
20
20
|
public constructor(mutableAtoms: MutableAtomFamily<T, K>, store: RootStore) {
|
|
21
|
-
const latestSignalAtoms = createRegularAtomFamily<
|
|
21
|
+
const latestSignalAtoms = createRegularAtomFamily<
|
|
22
|
+
SignalFrom<T> | null,
|
|
23
|
+
K,
|
|
24
|
+
never
|
|
25
|
+
>(
|
|
22
26
|
store,
|
|
23
27
|
{
|
|
24
28
|
key: `*${mutableAtoms.key}`,
|
|
@@ -31,7 +31,11 @@ export class Tracker<T extends Transceiver<any, any, any>> {
|
|
|
31
31
|
subKey: mutableState.family.subKey,
|
|
32
32
|
}
|
|
33
33
|
: undefined
|
|
34
|
-
const latestSignalState = createRegularAtom<
|
|
34
|
+
const latestSignalState = createRegularAtom<
|
|
35
|
+
SignalFrom<T> | null,
|
|
36
|
+
any,
|
|
37
|
+
never
|
|
38
|
+
>(
|
|
35
39
|
store,
|
|
36
40
|
{
|
|
37
41
|
key: latestSignalStateKey,
|
|
@@ -8,7 +8,9 @@ export type OperationProgress =
|
|
|
8
8
|
| {
|
|
9
9
|
open: false
|
|
10
10
|
}
|
|
11
|
-
export type OpenOperation<
|
|
11
|
+
export type OpenOperation<
|
|
12
|
+
R extends ReadableToken<any, any> = ReadableToken<any, any>,
|
|
13
|
+
> = {
|
|
12
14
|
open: true
|
|
13
15
|
token: R
|
|
14
16
|
done: Set<string>
|
|
@@ -19,7 +21,7 @@ export type OpenOperation<R extends ReadableToken<any> = ReadableToken<any>> = {
|
|
|
19
21
|
|
|
20
22
|
export function openOperation(
|
|
21
23
|
store: Store,
|
|
22
|
-
token: ReadableToken<any>,
|
|
24
|
+
token: ReadableToken<any, any, any>,
|
|
23
25
|
): number | (Store & { operation: OpenOperation }) {
|
|
24
26
|
if (store.operation.open) {
|
|
25
27
|
const rejectionTime = performance.now()
|
|
@@ -2,7 +2,9 @@ import type {
|
|
|
2
2
|
FamilyMetadata,
|
|
3
3
|
ReadonlyPureSelectorOptions,
|
|
4
4
|
ReadonlyPureSelectorToken,
|
|
5
|
+
StateUpdate,
|
|
5
6
|
} from "atom.io"
|
|
7
|
+
import type { Canonical } from "atom.io/json"
|
|
6
8
|
|
|
7
9
|
import type { ReadonlyPureSelector, RootStore } from ".."
|
|
8
10
|
import { writeToCache } from "../caching"
|
|
@@ -11,13 +13,13 @@ import type { Store } from "../store"
|
|
|
11
13
|
import { Subject } from "../subject"
|
|
12
14
|
import { registerSelector } from "./register-selector"
|
|
13
15
|
|
|
14
|
-
export function createReadonlyPureSelector<T>(
|
|
16
|
+
export function createReadonlyPureSelector<T, K extends Canonical, E>(
|
|
15
17
|
store: Store,
|
|
16
|
-
options: ReadonlyPureSelectorOptions<T>,
|
|
17
|
-
family: FamilyMetadata | undefined,
|
|
18
|
-
): ReadonlyPureSelectorToken<T> {
|
|
18
|
+
options: ReadonlyPureSelectorOptions<T, E>,
|
|
19
|
+
family: FamilyMetadata<K> | undefined,
|
|
20
|
+
): ReadonlyPureSelectorToken<T, K, E> {
|
|
19
21
|
const target = newest(store)
|
|
20
|
-
const subject = new Subject<
|
|
22
|
+
const subject = new Subject<StateUpdate<E | T>>()
|
|
21
23
|
const covered = new Set<string>()
|
|
22
24
|
const key = options.key
|
|
23
25
|
const type = `readonly_pure_selector` as const
|
|
@@ -43,7 +45,7 @@ export function createReadonlyPureSelector<T>(
|
|
|
43
45
|
return cached
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
const readonlySelector: ReadonlyPureSelector<T> = {
|
|
48
|
+
const readonlySelector: ReadonlyPureSelector<T, E> = {
|
|
47
49
|
...options,
|
|
48
50
|
type,
|
|
49
51
|
subject,
|