atom.io 0.6.2 → 0.6.3
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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -2
- package/dist/index.mjs.map +1 -1
- package/json/dist/index.d.mts +18 -0
- package/json/dist/index.d.ts +18 -0
- package/json/dist/index.js +51 -0
- package/json/dist/index.js.map +1 -0
- package/json/dist/index.mjs +15 -0
- package/json/dist/index.mjs.map +1 -0
- package/package.json +13 -3
- package/react/dist/index.d.mts +24 -0
- package/react/dist/index.d.ts +24 -0
- package/react/dist/index.js +83 -0
- package/react/dist/index.js.map +1 -0
- package/react/dist/index.mjs +41 -0
- package/react/dist/index.mjs.map +1 -0
- package/react-devtools/dist/index.css +26 -0
- package/react-devtools/dist/index.css.map +1 -0
- package/react-devtools/dist/index.d.mts +15 -0
- package/react-devtools/dist/index.d.ts +15 -0
- package/react-devtools/dist/index.js +1596 -0
- package/react-devtools/dist/index.js.map +1 -0
- package/react-devtools/dist/index.mjs +1568 -0
- package/react-devtools/dist/index.mjs.map +1 -0
- package/realtime/dist/index.d.mts +27 -0
- package/realtime/dist/index.d.ts +27 -0
- package/realtime/dist/index.js +191 -0
- package/realtime/dist/index.js.map +1 -0
- package/realtime/dist/index.mjs +152 -0
- package/realtime/dist/index.mjs.map +1 -0
- package/realtime-react/dist/index.d.mts +45 -0
- package/realtime-react/dist/index.d.ts +45 -0
- package/realtime-react/dist/index.js +213 -0
- package/realtime-react/dist/index.js.map +1 -0
- package/realtime-react/dist/index.mjs +168 -0
- package/realtime-react/dist/index.mjs.map +1 -0
- package/realtime-testing/dist/index.d.mts +49 -0
- package/realtime-testing/dist/index.d.ts +49 -0
- package/realtime-testing/dist/index.js +153 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +117 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/realtime-testing/package.json +15 -0
- package/src/atom.ts +15 -15
- package/src/index.ts +59 -59
- package/src/internal/atom-internal.ts +36 -36
- package/src/internal/families-internal.ts +114 -114
- package/src/internal/get.ts +83 -83
- package/src/internal/is-default.ts +17 -17
- package/src/internal/meta/attach-meta.ts +7 -7
- package/src/internal/meta/meta-state.ts +115 -115
- package/src/internal/operation.ts +93 -93
- package/src/internal/selector/create-read-write-selector.ts +46 -46
- package/src/internal/selector/create-readonly-selector.ts +37 -37
- package/src/internal/selector/lookup-selector-sources.ts +9 -9
- package/src/internal/selector/register-selector.ts +44 -44
- package/src/internal/selector/trace-selector-atoms.ts +30 -30
- package/src/internal/selector/update-selector-atoms.ts +25 -25
- package/src/internal/selector-internal.ts +37 -37
- package/src/internal/set.ts +78 -78
- package/src/internal/store.ts +118 -118
- package/src/internal/subscribe-internal.ts +62 -62
- package/src/internal/time-travel-internal.ts +76 -76
- package/src/internal/timeline/add-atom-to-timeline.ts +158 -153
- package/src/internal/timeline-internal.ts +80 -80
- package/src/internal/transaction/abort-transaction.ts +8 -8
- package/src/internal/transaction/apply-transaction.ts +41 -41
- package/src/internal/transaction/build-transaction.ts +28 -28
- package/src/internal/transaction/index.ts +7 -7
- package/src/internal/transaction/redo-transaction.ts +13 -13
- package/src/internal/transaction/undo-transaction.ts +13 -13
- package/src/internal/transaction-internal.ts +48 -48
- package/src/json/select-json.ts +12 -12
- package/src/logger.ts +30 -30
- package/src/react/store-context.tsx +4 -4
- package/src/react/store-hooks.ts +18 -18
- package/src/react-devtools/AtomIODevtools.tsx +83 -82
- package/src/react-devtools/StateEditor.tsx +53 -53
- package/src/react-devtools/TokenList.tsx +47 -42
- package/src/react-explorer/AtomIOExplorer.tsx +197 -185
- package/src/react-explorer/explorer-effects.ts +11 -11
- package/src/react-explorer/explorer-states.ts +186 -193
- package/src/react-explorer/index.ts +11 -11
- package/src/react-explorer/space-states.ts +48 -50
- package/src/react-explorer/view-states.ts +25 -25
- package/src/realtime/hook-composition/expose-family.ts +81 -81
- package/src/realtime/hook-composition/expose-single.ts +26 -26
- package/src/realtime/hook-composition/expose-timeline.ts +60 -0
- package/src/realtime/hook-composition/index.ts +2 -2
- package/src/realtime/hook-composition/receive-state.ts +18 -18
- package/src/realtime/hook-composition/receive-transaction.ts +8 -8
- package/src/realtime-react/realtime-context.tsx +17 -17
- package/src/realtime-react/realtime-hooks.ts +17 -17
- package/src/realtime-react/realtime-state.ts +4 -4
- package/src/realtime-react/use-pull-family-member.ts +15 -15
- package/src/realtime-react/use-pull-family.ts +13 -13
- package/src/realtime-react/use-pull.ts +12 -12
- package/src/realtime-react/use-push.ts +15 -15
- package/src/realtime-react/use-server-action.ts +21 -21
- package/src/realtime-testing/index.ts +1 -0
- package/src/realtime-testing/setup-realtime-test.tsx +160 -0
- package/src/selector.ts +25 -25
- package/src/silo.ts +38 -38
- package/src/subscribe.ts +68 -68
- package/src/timeline.ts +13 -13
- package/src/transaction.ts +28 -28
- package/src/web-effects/storage.ts +17 -17
|
@@ -12,44 +12,44 @@ import { setState, subscribe } from ".."
|
|
|
12
12
|
import type { AtomOptions } from "../atom"
|
|
13
13
|
|
|
14
14
|
export type Atom<T> = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
key: string
|
|
16
|
+
type: `atom`
|
|
17
|
+
family?: FamilyMetadata
|
|
18
|
+
subject: Rx.Subject<{ newValue: T; oldValue: T }>
|
|
19
|
+
default: T
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function atom__INTERNAL<T>(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
options: AtomOptions<T>,
|
|
24
|
+
family?: FamilyMetadata,
|
|
25
|
+
store: Store = IMPLICIT.STORE,
|
|
26
26
|
): AtomToken<T> {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
27
|
+
const core = target(store)
|
|
28
|
+
if (hasKeyBeenUsed(options.key, store)) {
|
|
29
|
+
store.config.logger?.error?.(
|
|
30
|
+
`Key "${options.key}" already exists in the store.`,
|
|
31
|
+
)
|
|
32
|
+
return deposit(core.atoms.get(options.key))
|
|
33
|
+
}
|
|
34
|
+
const subject = new Rx.Subject<{ newValue: T; oldValue: T }>()
|
|
35
|
+
const newAtom = {
|
|
36
|
+
...options,
|
|
37
|
+
subject,
|
|
38
|
+
type: `atom`,
|
|
39
|
+
...(family && { family }),
|
|
40
|
+
} as const
|
|
41
|
+
const initialValue =
|
|
42
|
+
options.default instanceof Function ? options.default() : options.default
|
|
43
|
+
core.atoms = HAMT.set(newAtom.key, newAtom, core.atoms)
|
|
44
|
+
markAtomAsDefault(options.key, store)
|
|
45
|
+
cacheValue(options.key, initialValue, store)
|
|
46
|
+
const token = deposit(newAtom)
|
|
47
|
+
options.effects?.forEach((effect) =>
|
|
48
|
+
effect({
|
|
49
|
+
setSelf: (next) => setState(token, next, store),
|
|
50
|
+
onSet: (handle: UpdateHandler<T>) => subscribe(token, handle, store),
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
store.subject.atomCreation.next(token)
|
|
54
|
+
return token as AtomToken<T>
|
|
55
55
|
}
|
|
@@ -5,138 +5,138 @@ import { stringifyJson } from "~/packages/anvl/src/json"
|
|
|
5
5
|
|
|
6
6
|
import type { Store } from "."
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
atom__INTERNAL,
|
|
9
|
+
withdraw,
|
|
10
|
+
selector__INTERNAL,
|
|
11
|
+
target,
|
|
12
|
+
deposit,
|
|
13
|
+
IMPLICIT,
|
|
14
14
|
} from "."
|
|
15
15
|
import type {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
AtomFamily,
|
|
17
|
+
AtomFamilyOptions,
|
|
18
|
+
AtomToken,
|
|
19
|
+
FamilyMetadata,
|
|
20
|
+
ReadonlySelectorFamily,
|
|
21
|
+
ReadonlySelectorFamilyOptions,
|
|
22
|
+
ReadonlySelectorToken,
|
|
23
|
+
SelectorFamily,
|
|
24
|
+
SelectorFamilyOptions,
|
|
25
|
+
SelectorToken,
|
|
26
26
|
} from ".."
|
|
27
27
|
|
|
28
28
|
export function atomFamily__INTERNAL<T, K extends Serializable>(
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
options: AtomFamilyOptions<T, K>,
|
|
30
|
+
store: Store = IMPLICIT.STORE,
|
|
31
31
|
): AtomFamily<T, K> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
32
|
+
const subject = new Rx.Subject<AtomToken<T>>()
|
|
33
|
+
return Object.assign(
|
|
34
|
+
(key: K): AtomToken<T> => {
|
|
35
|
+
const subKey = stringifyJson(key)
|
|
36
|
+
const family: FamilyMetadata = { key: options.key, subKey }
|
|
37
|
+
const fullKey = `${options.key}(${subKey})`
|
|
38
|
+
const existing = withdraw({ key: fullKey, type: `atom` }, store)
|
|
39
|
+
const token: AtomToken<any> = existing
|
|
40
|
+
? deposit(existing)
|
|
41
|
+
: atom__INTERNAL<T>(
|
|
42
|
+
{
|
|
43
|
+
key: fullKey,
|
|
44
|
+
default:
|
|
45
|
+
options.default instanceof Function
|
|
46
|
+
? options.default(key)
|
|
47
|
+
: options.default,
|
|
48
|
+
effects: options.effects?.(key),
|
|
49
|
+
},
|
|
50
|
+
family,
|
|
51
|
+
store,
|
|
52
|
+
)
|
|
53
|
+
subject.next(token)
|
|
54
|
+
return token
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: options.key,
|
|
58
|
+
type: `atom_family`,
|
|
59
|
+
subject,
|
|
60
|
+
} as const,
|
|
61
|
+
)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export function readonlySelectorFamily__INTERNAL<T, K extends Serializable>(
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
66
|
+
store?: Store,
|
|
67
67
|
): ReadonlySelectorFamily<T, K> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
68
|
+
const core = target(store)
|
|
69
|
+
const subject = new Rx.Subject<ReadonlySelectorToken<T>>()
|
|
70
|
+
return Object.assign(
|
|
71
|
+
(key: K): ReadonlySelectorToken<T> => {
|
|
72
|
+
const subKey = stringifyJson(key)
|
|
73
|
+
const family: FamilyMetadata = { key: options.key, subKey }
|
|
74
|
+
const fullKey = `${options.key}(${subKey})`
|
|
75
|
+
const existing = core.readonlySelectors.get(fullKey)
|
|
76
|
+
if (existing) {
|
|
77
|
+
return deposit(existing)
|
|
78
|
+
}
|
|
79
|
+
return selector__INTERNAL<T>(
|
|
80
|
+
{
|
|
81
|
+
key: fullKey,
|
|
82
|
+
get: options.get(key),
|
|
83
|
+
},
|
|
84
|
+
family,
|
|
85
|
+
store,
|
|
86
|
+
) as ReadonlySelectorToken<T>
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: options.key,
|
|
90
|
+
type: `readonly_selector_family`,
|
|
91
|
+
subject,
|
|
92
|
+
} as const,
|
|
93
|
+
) as ReadonlySelectorFamily<T, K>
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export function selectorFamily__INTERNAL<T, K extends Serializable>(
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
options: SelectorFamilyOptions<T, K>,
|
|
98
|
+
store?: Store,
|
|
99
99
|
): SelectorFamily<T, K>
|
|
100
100
|
export function selectorFamily__INTERNAL<T, K extends Serializable>(
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
102
|
+
store?: Store,
|
|
103
103
|
): ReadonlySelectorFamily<T, K>
|
|
104
104
|
export function selectorFamily__INTERNAL<T, K extends Serializable>(
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
options: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,
|
|
106
|
+
store: Store = IMPLICIT.STORE,
|
|
107
107
|
): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {
|
|
108
|
-
|
|
108
|
+
const isReadonly = !(`set` in options)
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
if (isReadonly) {
|
|
111
|
+
return readonlySelectorFamily__INTERNAL(options, store)
|
|
112
|
+
}
|
|
113
|
+
const core = target(store)
|
|
114
|
+
const subject = new Rx.Subject<SelectorToken<T>>()
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
116
|
+
return Object.assign(
|
|
117
|
+
(key: K): SelectorToken<T> => {
|
|
118
|
+
const subKey = stringifyJson(key)
|
|
119
|
+
const family: FamilyMetadata = { key: options.key, subKey }
|
|
120
|
+
const fullKey = `${options.key}(${subKey})`
|
|
121
|
+
const existing = core.selectors.get(fullKey)
|
|
122
|
+
if (existing) {
|
|
123
|
+
return deposit(existing)
|
|
124
|
+
}
|
|
125
|
+
const token = selector__INTERNAL<T>(
|
|
126
|
+
{
|
|
127
|
+
key: fullKey,
|
|
128
|
+
get: options.get(key),
|
|
129
|
+
set: options.set(key),
|
|
130
|
+
},
|
|
131
|
+
family,
|
|
132
|
+
store,
|
|
133
|
+
)
|
|
134
|
+
subject.next(token)
|
|
135
|
+
return token
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
key: options.key,
|
|
139
|
+
type: `selector_family`,
|
|
140
|
+
} as const,
|
|
141
|
+
) as SelectorFamily<T, K>
|
|
142
142
|
}
|
package/src/internal/get.ts
CHANGED
|
@@ -3,85 +3,85 @@ import HAMT from "hamt_plus"
|
|
|
3
3
|
import type { ƒn } from "~/packages/anvl/src/function"
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
Atom,
|
|
7
|
+
ReadonlySelector,
|
|
8
|
+
Selector,
|
|
9
|
+
Store,
|
|
10
|
+
Timeline,
|
|
11
|
+
Transaction,
|
|
12
12
|
} from "."
|
|
13
13
|
import { target, isValueCached, readCachedValue, IMPLICIT } from "."
|
|
14
14
|
import type {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
AtomToken,
|
|
16
|
+
ReadonlySelectorToken,
|
|
17
|
+
SelectorToken,
|
|
18
|
+
StateToken,
|
|
19
|
+
TimelineToken,
|
|
20
|
+
TransactionToken,
|
|
21
21
|
} from ".."
|
|
22
22
|
|
|
23
23
|
export const computeSelectorState = <T>(
|
|
24
|
-
|
|
24
|
+
selector: ReadonlySelector<T> | Selector<T>,
|
|
25
25
|
): T => selector.get()
|
|
26
26
|
|
|
27
27
|
export function lookup(
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
key: string,
|
|
29
|
+
store: Store,
|
|
30
30
|
): AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
const core = target(store)
|
|
32
|
+
const type = HAMT.has(key, core.atoms)
|
|
33
|
+
? `atom`
|
|
34
|
+
: HAMT.has(key, core.selectors)
|
|
35
|
+
? `selector`
|
|
36
|
+
: `readonly_selector`
|
|
37
|
+
return { key, type } as any
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | null
|
|
41
41
|
export function withdraw<T>(
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
token: SelectorToken<T>,
|
|
43
|
+
store: Store,
|
|
44
44
|
): Selector<T> | null
|
|
45
45
|
export function withdraw<T>(
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
token: StateToken<T>,
|
|
47
|
+
store: Store,
|
|
48
48
|
): Atom<T> | Selector<T> | null
|
|
49
49
|
export function withdraw<T>(
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
token: ReadonlySelectorToken<T>,
|
|
51
|
+
store: Store,
|
|
52
52
|
): ReadonlySelector<T> | null
|
|
53
53
|
export function withdraw<T>(
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
token: TransactionToken<T>,
|
|
55
|
+
store: Store,
|
|
56
56
|
): Transaction<T extends ƒn ? T : never> | null
|
|
57
57
|
export function withdraw<T>(
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
token: ReadonlySelectorToken<T> | StateToken<T>,
|
|
59
|
+
store: Store,
|
|
60
60
|
): Atom<T> | ReadonlySelector<T> | Selector<T> | null
|
|
61
61
|
export function withdraw<T>(token: TimelineToken, store: Store): Timeline | null
|
|
62
62
|
export function withdraw<T>(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
token:
|
|
64
|
+
| ReadonlySelectorToken<T>
|
|
65
|
+
| StateToken<T>
|
|
66
|
+
| TimelineToken
|
|
67
|
+
| TransactionToken<T>,
|
|
68
|
+
store: Store,
|
|
69
69
|
):
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
| Atom<T>
|
|
71
|
+
| ReadonlySelector<T>
|
|
72
|
+
| Selector<T>
|
|
73
|
+
| Timeline
|
|
74
|
+
| Transaction<T extends ƒn ? T : never>
|
|
75
|
+
| null {
|
|
76
|
+
const core = target(store)
|
|
77
|
+
return (
|
|
78
|
+
HAMT.get(token.key, core.atoms) ??
|
|
79
|
+
HAMT.get(token.key, core.selectors) ??
|
|
80
|
+
HAMT.get(token.key, core.readonlySelectors) ??
|
|
81
|
+
HAMT.get(token.key, core.transactions) ??
|
|
82
|
+
HAMT.get(token.key, core.timelines) ??
|
|
83
|
+
null
|
|
84
|
+
)
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export function deposit<T>(state: Atom<T>): AtomToken<T>
|
|
@@ -89,43 +89,43 @@ export function deposit<T>(state: Selector<T>): SelectorToken<T>
|
|
|
89
89
|
export function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>
|
|
90
90
|
export function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>
|
|
91
91
|
export function deposit<T>(
|
|
92
|
-
|
|
92
|
+
state: Transaction<T extends ƒn ? T : never>,
|
|
93
93
|
): TransactionToken<T>
|
|
94
94
|
export function deposit<T>(
|
|
95
|
-
|
|
95
|
+
state: Atom<T> | ReadonlySelector<T> | Selector<T>,
|
|
96
96
|
): ReadonlySelectorToken<T> | StateToken<T>
|
|
97
97
|
export function deposit<T>(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
state:
|
|
99
|
+
| Atom<T>
|
|
100
|
+
| ReadonlySelector<T>
|
|
101
|
+
| Selector<T>
|
|
102
|
+
| Transaction<T extends ƒn ? T : never>,
|
|
103
103
|
):
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
| AtomToken<T>
|
|
105
|
+
| ReadonlySelectorToken<T>
|
|
106
|
+
| SelectorToken<T>
|
|
107
|
+
| TransactionToken<T> {
|
|
108
|
+
return {
|
|
109
|
+
key: state.key,
|
|
110
|
+
type: state.type,
|
|
111
|
+
...(`family` in state && { family: state.family }),
|
|
112
|
+
} as any
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
export const getState__INTERNAL = <T>(
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
state: Atom<T> | ReadonlySelector<T> | Selector<T>,
|
|
117
|
+
store: Store = IMPLICIT.STORE,
|
|
118
118
|
): T => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
if (isValueCached(state.key, store)) {
|
|
120
|
+
store.config.logger?.info(`>> read "${state.key}"`)
|
|
121
|
+
return readCachedValue(state.key, store)
|
|
122
|
+
}
|
|
123
|
+
if (state.type !== `atom`) {
|
|
124
|
+
store.config.logger?.info(`-> calc "${state.key}"`)
|
|
125
|
+
return computeSelectorState(state)
|
|
126
|
+
}
|
|
127
|
+
store.config.logger?.error(
|
|
128
|
+
`Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`,
|
|
129
|
+
)
|
|
130
|
+
return state.default
|
|
131
131
|
}
|
|
@@ -2,34 +2,34 @@ import type { Store } from "."
|
|
|
2
2
|
import { target, IMPLICIT, traceAllSelectorAtoms } from "."
|
|
3
3
|
|
|
4
4
|
export const isAtomDefault = (
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
key: string,
|
|
6
|
+
store: Store = IMPLICIT.STORE,
|
|
7
7
|
): boolean => {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const core = target(store)
|
|
9
|
+
return core.atomsThatAreDefault.has(key)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const markAtomAsDefault = (
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
key: string,
|
|
14
|
+
store: Store = IMPLICIT.STORE,
|
|
15
15
|
): void => {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const core = target(store)
|
|
17
|
+
core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export const markAtomAsNotDefault = (
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
key: string,
|
|
22
|
+
store: Store = IMPLICIT.STORE,
|
|
23
23
|
): void => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const core = target(store)
|
|
25
|
+
core.atomsThatAreDefault = new Set(target(store).atomsThatAreDefault)
|
|
26
|
+
core.atomsThatAreDefault.delete(key)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const isSelectorDefault = (
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
key: string,
|
|
31
|
+
store: Store = IMPLICIT.STORE,
|
|
32
32
|
): boolean => {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const roots = traceAllSelectorAtoms(key, store)
|
|
34
|
+
return roots.every((root) => isAtomDefault(root.key, store))
|
|
35
35
|
}
|
|
@@ -5,13 +5,13 @@ import type { Store } from "../store"
|
|
|
5
5
|
import { IMPLICIT } from "../store"
|
|
6
6
|
|
|
7
7
|
export const attachMetaState = (
|
|
8
|
-
|
|
8
|
+
store: Store = IMPLICIT.STORE,
|
|
9
9
|
): {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
atomTokenIndexState: ReadonlySelectorToken<AtomTokenIndex>
|
|
11
|
+
selectorTokenIndexState: ReadonlySelectorToken<SelectorTokenIndex>
|
|
12
12
|
} => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
return {
|
|
14
|
+
atomTokenIndexState: attachMetaAtoms(store),
|
|
15
|
+
selectorTokenIndexState: attachMetaSelectors(store),
|
|
16
|
+
}
|
|
17
17
|
}
|