atom.io 0.40.0 → 0.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data/index.d.ts +1 -1
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/internal/index.d.ts +205 -196
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +145 -107
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +6 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +93 -66
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +16 -13
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +14 -14
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.js +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +3 -3
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/data/struct.ts +2 -2
- package/src/internal/atom/create-regular-atom.ts +11 -9
- package/src/internal/atom/dispose-atom.ts +11 -8
- package/src/internal/atom/has-role.ts +1 -1
- package/src/internal/caching.ts +15 -15
- package/src/internal/events/ingest-creation-disposal.ts +1 -1
- package/src/internal/families/create-readonly-held-selector-family.ts +3 -4
- package/src/internal/families/create-readonly-pure-selector-family.ts +25 -23
- package/src/internal/families/create-regular-atom-family.ts +21 -15
- package/src/internal/families/create-selector-family.ts +15 -15
- package/src/internal/families/create-writable-held-selector-family.ts +2 -2
- package/src/internal/families/create-writable-pure-selector-family.ts +25 -21
- package/src/internal/families/dispose-from-store.ts +17 -7
- package/src/internal/families/find-in-store.ts +23 -23
- package/src/internal/families/get-family-of-token.ts +17 -17
- package/src/internal/families/mint-in-store.ts +10 -10
- package/src/internal/families/seek-in-store.ts +26 -26
- package/src/internal/get-state/get-fallback.ts +8 -8
- package/src/internal/get-state/get-from-store.ts +20 -8
- package/src/internal/get-state/read-or-compute-value.ts +78 -14
- package/src/internal/get-state/reduce-reference.ts +10 -10
- package/src/internal/index.ts +65 -60
- package/src/internal/install-into-store.ts +2 -1
- package/src/internal/join/create-join.ts +2 -2
- package/src/internal/join/find-relations-in-store.ts +2 -2
- package/src/internal/join/get-internal-relations-from-store.ts +2 -2
- package/src/internal/join/get-join.ts +5 -2
- package/src/internal/join/join-internal.ts +30 -26
- package/src/internal/lineage.ts +12 -1
- package/src/internal/molecule.ts +64 -36
- package/src/internal/mutable/create-mutable-atom-family.ts +5 -5
- package/src/internal/mutable/create-mutable-atom.ts +2 -2
- package/src/internal/mutable/get-json-family.ts +3 -2
- package/src/internal/mutable/get-update-family.ts +7 -5
- package/src/internal/mutable/tracker-family.ts +8 -4
- package/src/internal/mutable/tracker.ts +5 -1
- package/src/internal/operation.ts +4 -2
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +10 -8
- package/src/internal/selector/create-standalone-selector.ts +10 -10
- package/src/internal/selector/create-writable-held-selector.ts +2 -2
- package/src/internal/selector/create-writable-pure-selector.ts +11 -9
- package/src/internal/selector/dispose-selector.ts +2 -2
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/internal/selector/trace-selector-atoms.ts +3 -3
- package/src/internal/selector/update-selector-atoms.ts +1 -1
- package/src/internal/set-state/become.ts +1 -3
- package/src/internal/set-state/dispatch-state-update.ts +10 -6
- package/src/internal/set-state/evict-downstream.ts +4 -1
- package/src/internal/set-state/operate-on-store.ts +16 -10
- package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
- package/src/internal/set-state/reset-in-store.ts +17 -16
- package/src/internal/set-state/set-atom-or-selector.ts +1 -1
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/set-state/set-into-store.ts +34 -7
- package/src/internal/set-state/set-selector.ts +1 -1
- package/src/internal/store/deposit.ts +38 -30
- package/src/internal/store/mint-or-counterfeit.ts +23 -23
- package/src/internal/store/store.ts +23 -21
- package/src/internal/store/withdraw.ts +68 -62
- package/src/internal/subscribe/recall-state.ts +4 -1
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
- package/src/internal/subscribe/subscribe-to-state.ts +4 -4
- package/src/internal/timeline/create-timeline.ts +11 -10
- package/src/internal/timeline/time-travel.ts +4 -3
- package/src/internal/transaction/abort-transaction.ts +3 -15
- package/src/internal/transaction/act-upon-store.ts +1 -5
- package/src/internal/transaction/apply-transaction.ts +3 -15
- package/src/internal/transaction/assign-transaction-to-continuity.ts +2 -7
- package/src/internal/transaction/build-transaction.ts +2 -3
- package/src/internal/transaction/create-transaction.ts +5 -6
- package/src/internal/transaction/get-epoch-number.ts +1 -7
- package/src/internal/transaction/set-epoch-number.ts +4 -12
- package/src/introspection/attach-atom-index.ts +2 -2
- package/src/introspection/attach-introspection-states.ts +4 -2
- package/src/introspection/attach-selector-index.ts +4 -2
- package/src/introspection/attach-timeline-family.ts +15 -13
- package/src/introspection/attach-timeline-index.ts +1 -1
- package/src/introspection/attach-transaction-index.ts +1 -1
- package/src/introspection/attach-transaction-logs.ts +6 -4
- package/src/introspection/attach-type-selectors.ts +4 -3
- package/src/introspection/index.ts +3 -5
- package/src/main/atom.ts +14 -8
- package/src/main/dispose-state.ts +1 -5
- package/src/main/events.ts +26 -26
- package/src/main/get-state.ts +10 -11
- package/src/main/realm.ts +36 -12
- package/src/main/reset-state.ts +5 -9
- package/src/main/selector.ts +40 -24
- package/src/main/set-state.ts +8 -11
- package/src/main/silo.ts +4 -3
- package/src/main/timeline.ts +5 -3
- package/src/main/tokens.ts +72 -44
- package/src/main/validators.ts +4 -4
- package/src/react/parse-state-overloads.ts +10 -10
- package/src/react/store-context.tsx +3 -3
- package/src/react/use-i.ts +6 -6
- package/src/react/use-loadable.ts +15 -15
- package/src/react/use-o.ts +9 -9
- package/src/react-devtools/Button.tsx +3 -2
- package/src/react-devtools/StateEditor.tsx +5 -3
- package/src/react-devtools/StateIndex.tsx +6 -4
- package/src/react-devtools/TimelineIndex.tsx +0 -2
- package/src/react-devtools/Updates.tsx +1 -1
- package/src/react-devtools/store.ts +18 -9
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +4 -8
- package/src/realtime-client/sync-continuity.ts +2 -2
- package/src/realtime-server/index.ts +2 -2
|
@@ -11,36 +11,36 @@ import type {
|
|
|
11
11
|
} from "atom.io"
|
|
12
12
|
import type { Canonical } from "atom.io/json"
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type { RootStore } from "../transaction"
|
|
15
15
|
import { createReadonlyHeldSelectorFamily } from "./create-readonly-held-selector-family"
|
|
16
16
|
import { createReadonlyPureSelectorFamily } from "./create-readonly-pure-selector-family"
|
|
17
17
|
import { createWritableHeldSelectorFamily } from "./create-writable-held-selector-family"
|
|
18
18
|
import { createWritablePureSelectorFamily } from "./create-writable-pure-selector-family"
|
|
19
19
|
|
|
20
20
|
export function createSelectorFamily<T extends object, K extends Canonical>(
|
|
21
|
-
store:
|
|
21
|
+
store: RootStore,
|
|
22
22
|
options: WritableHeldSelectorFamilyOptions<T, K>,
|
|
23
23
|
): WritableHeldSelectorFamilyToken<T, K>
|
|
24
24
|
export function createSelectorFamily<T extends object, K extends Canonical>(
|
|
25
|
-
store:
|
|
25
|
+
store: RootStore,
|
|
26
26
|
options: ReadonlyHeldSelectorFamilyOptions<T, K>,
|
|
27
27
|
): ReadonlyHeldSelectorFamilyToken<T, K>
|
|
28
|
-
export function createSelectorFamily<T, K extends Canonical>(
|
|
29
|
-
store:
|
|
30
|
-
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
31
|
-
): WritablePureSelectorFamilyToken<T, K>
|
|
32
|
-
export function createSelectorFamily<T, K extends Canonical>(
|
|
33
|
-
store:
|
|
34
|
-
options: ReadonlyPureSelectorFamilyOptions<T, K>,
|
|
35
|
-
): ReadonlyPureSelectorFamilyToken<T, K>
|
|
28
|
+
export function createSelectorFamily<T, K extends Canonical, E>(
|
|
29
|
+
store: RootStore,
|
|
30
|
+
options: WritablePureSelectorFamilyOptions<T, K, E>,
|
|
31
|
+
): WritablePureSelectorFamilyToken<T, K, E>
|
|
32
|
+
export function createSelectorFamily<T, K extends Canonical, E>(
|
|
33
|
+
store: RootStore,
|
|
34
|
+
options: ReadonlyPureSelectorFamilyOptions<T, K, E>,
|
|
35
|
+
): ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
36
36
|
export function createSelectorFamily(
|
|
37
|
-
store:
|
|
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
|
|
|
@@ -9,7 +9,7 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
|
|
|
9
9
|
import type { Canonical } from "atom.io/json"
|
|
10
10
|
import { stringifyJson } from "atom.io/json"
|
|
11
11
|
|
|
12
|
-
import type { WritableHeldSelectorFamily } from ".."
|
|
12
|
+
import type { RootStore, WritableHeldSelectorFamily } from ".."
|
|
13
13
|
import { newest } from "../lineage"
|
|
14
14
|
import { createWritableHeldSelector } from "../selector"
|
|
15
15
|
import type { Store } from "../store"
|
|
@@ -68,7 +68,7 @@ export function createWritableHeldSelectorFamily<
|
|
|
68
68
|
const selectorFamily = Object.assign(familyFunction, familyToken, {
|
|
69
69
|
internalRoles,
|
|
70
70
|
subject,
|
|
71
|
-
install: (s:
|
|
71
|
+
install: (s: RootStore) => createWritableHeldSelectorFamily(s, options),
|
|
72
72
|
default: options.const,
|
|
73
73
|
}) satisfies WritableHeldSelectorFamily<T, K>
|
|
74
74
|
|
|
@@ -5,35 +5,32 @@ 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"
|
|
11
12
|
import type { Canonical } from "atom.io/json"
|
|
12
13
|
import { stringifyJson } from "atom.io/json"
|
|
13
14
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
getFromStore,
|
|
17
|
-
getJsonToken,
|
|
18
|
-
type WritablePureSelectorFamily,
|
|
19
|
-
} from ".."
|
|
15
|
+
import type { RootStore, WritablePureSelectorFamily } from ".."
|
|
16
|
+
import { findInStore, getFromStore, getJsonToken } from ".."
|
|
20
17
|
import { newest } from "../lineage"
|
|
21
18
|
import { createWritablePureSelector } from "../selector"
|
|
22
19
|
import type { Store } from "../store"
|
|
23
20
|
import { Subject } from "../subject"
|
|
24
21
|
|
|
25
|
-
export function createWritablePureSelectorFamily<T, K extends Canonical>(
|
|
22
|
+
export function createWritablePureSelectorFamily<T, K extends Canonical, E>(
|
|
26
23
|
store: Store,
|
|
27
|
-
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
24
|
+
options: WritablePureSelectorFamilyOptions<T, K, E>,
|
|
28
25
|
internalRoles?: string[],
|
|
29
|
-
): WritablePureSelectorFamilyToken<T, K> {
|
|
26
|
+
): WritablePureSelectorFamilyToken<T, K, E> {
|
|
30
27
|
const familyKey = options.key
|
|
31
28
|
const type = `writable_pure_selector_family`
|
|
32
29
|
|
|
33
30
|
const familyToken = {
|
|
34
31
|
key: familyKey,
|
|
35
32
|
type,
|
|
36
|
-
} as const satisfies WritablePureSelectorFamilyToken<T, K>
|
|
33
|
+
} as const satisfies WritablePureSelectorFamilyToken<T, K, E>
|
|
37
34
|
|
|
38
35
|
const existing = store.families.get(familyKey)
|
|
39
36
|
if (existing) {
|
|
@@ -45,22 +42,28 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
|
|
|
45
42
|
)
|
|
46
43
|
}
|
|
47
44
|
const subject = new Subject<
|
|
48
|
-
StateLifecycleEvent<WritablePureSelectorToken<T>>
|
|
45
|
+
StateLifecycleEvent<WritablePureSelectorToken<T, K, E>>
|
|
49
46
|
>()
|
|
50
47
|
|
|
51
|
-
const familyFunction =
|
|
48
|
+
const familyFunction = <Key extends K>(
|
|
49
|
+
key: Key,
|
|
50
|
+
): WritablePureSelectorToken<T, Key, E> => {
|
|
52
51
|
const subKey = stringifyJson(key)
|
|
53
|
-
const family: FamilyMetadata = { key: familyKey, subKey }
|
|
52
|
+
const family: FamilyMetadata<Key> = { key: familyKey, subKey }
|
|
54
53
|
const fullKey = `${familyKey}(${subKey})`
|
|
55
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
|
+
}
|
|
56
63
|
|
|
57
|
-
const token = createWritablePureSelector(
|
|
64
|
+
const token = createWritablePureSelector<T, Key, E>(
|
|
58
65
|
target,
|
|
59
|
-
|
|
60
|
-
key: fullKey,
|
|
61
|
-
get: options.get(key),
|
|
62
|
-
set: options.set(key),
|
|
63
|
-
},
|
|
66
|
+
individualOptions,
|
|
64
67
|
family,
|
|
65
68
|
)
|
|
66
69
|
|
|
@@ -71,7 +74,7 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
|
|
|
71
74
|
const selectorFamily = Object.assign(familyFunction, familyToken, {
|
|
72
75
|
internalRoles,
|
|
73
76
|
subject,
|
|
74
|
-
install: (s:
|
|
77
|
+
install: (s: RootStore) => createWritablePureSelectorFamily(s, options),
|
|
75
78
|
default: (key: K) => {
|
|
76
79
|
const getFn = options.get(key)
|
|
77
80
|
return getFn({
|
|
@@ -82,7 +85,8 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
|
|
|
82
85
|
json: (token) => getJsonToken(store, token),
|
|
83
86
|
})
|
|
84
87
|
},
|
|
85
|
-
|
|
88
|
+
...(options.catch ? { catch: options.catch } : {}),
|
|
89
|
+
}) satisfies WritablePureSelectorFamily<T, K, E>
|
|
86
90
|
|
|
87
91
|
store.families.set(familyKey, selectorFamily)
|
|
88
92
|
return familyToken
|
|
@@ -6,21 +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
|
-
export function disposeFromStore<K extends Canonical>(
|
|
14
|
+
export function disposeFromStore<K extends Canonical, Key extends K>(
|
|
12
15
|
store: Store,
|
|
13
|
-
token: ReadableFamilyToken<any, K>,
|
|
14
|
-
key:
|
|
16
|
+
token: ReadableFamilyToken<any, K, any>,
|
|
17
|
+
key: Key,
|
|
18
|
+
): void
|
|
19
|
+
|
|
20
|
+
export function disposeFromStore<K extends Canonical, Key extends K>(
|
|
21
|
+
store: Store,
|
|
22
|
+
...params:
|
|
23
|
+
| [token: ReadableFamilyToken<any, K, any>, key: Key]
|
|
24
|
+
| [token: ReadableToken<any, any, any>]
|
|
15
25
|
): void
|
|
16
26
|
|
|
17
27
|
export function disposeFromStore(
|
|
18
28
|
store: Store,
|
|
19
29
|
...params:
|
|
20
|
-
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
21
|
-
| [token: ReadableToken<any>]
|
|
30
|
+
| [token: ReadableFamilyToken<any, any, any>, key: Canonical]
|
|
31
|
+
| [token: ReadableToken<any, any, any>]
|
|
22
32
|
): void {
|
|
23
|
-
let token: ReadableToken<any>
|
|
33
|
+
let token: ReadableToken<any, any, any>
|
|
24
34
|
if (params.length === 1) {
|
|
25
35
|
token = params[0]
|
|
26
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`:
|
|
@@ -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,18 +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>
|
|
21
|
+
|
|
22
|
+
export function getFromStore<T, K extends Canonical, Key extends K, E>(
|
|
23
|
+
store: Store,
|
|
24
|
+
...params:
|
|
25
|
+
| [token: ReadableFamilyToken<T, K, E>, key: Key]
|
|
26
|
+
| [token: ReadableToken<T, any, E>]
|
|
27
|
+
): ViewOf<E | T>
|
|
16
28
|
|
|
17
|
-
export function getFromStore(
|
|
29
|
+
export function getFromStore<T, K extends Canonical, Key extends K, E>(
|
|
18
30
|
store: Store,
|
|
19
31
|
...params:
|
|
20
|
-
| [token: ReadableFamilyToken<
|
|
21
|
-
| [token: ReadableToken<any>]
|
|
22
|
-
):
|
|
32
|
+
| [token: ReadableFamilyToken<T, K, E>, key: Key]
|
|
33
|
+
| [token: ReadableToken<T, any, E>]
|
|
34
|
+
): ViewOf<E | T> {
|
|
23
35
|
const { token, family, subKey } = reduceReference(store, ...params)
|
|
24
36
|
|
|
25
37
|
if (`counterfeit` in token && family && subKey) {
|