atom.io 0.6.8 → 0.6.9
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 +226 -258
- package/dist/index.d.ts +226 -258
- package/dist/index.js +28 -1917
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1877
- package/dist/index.mjs.map +1 -1
- package/introspection/dist/index.d.mts +117 -171
- package/introspection/dist/index.d.ts +117 -171
- package/introspection/dist/index.js +6 -346
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +5 -324
- package/introspection/dist/index.mjs.map +1 -1
- package/json/dist/index.d.mts +32 -1
- package/json/dist/index.d.ts +32 -1
- package/json/dist/index.js +31 -48
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +6 -14
- package/json/dist/index.mjs.map +1 -1
- package/package.json +22 -14
- package/react/dist/index.js +34 -83
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +7 -43
- package/react/dist/index.mjs.map +1 -1
- package/react-devtools/dist/index.css +1 -50
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +124 -188
- package/react-devtools/dist/index.d.ts +124 -188
- package/react-devtools/dist/index.js +56 -4674
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +19 -4642
- package/react-devtools/dist/index.mjs.map +1 -1
- package/realtime/dist/index.d.mts +1 -3
- package/realtime/dist/index.d.ts +1 -3
- package/realtime/dist/index.js +26 -184
- package/realtime/dist/index.js.map +1 -1
- package/realtime/dist/index.mjs +4 -148
- package/realtime/dist/index.mjs.map +1 -1
- package/realtime-react/dist/index.d.mts +2 -4
- package/realtime-react/dist/index.d.ts +2 -4
- package/realtime-react/dist/index.js +41 -214
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +9 -169
- package/realtime-react/dist/index.mjs.map +1 -1
- package/src/atom.ts +4 -3
- package/src/index.ts +12 -9
- package/src/logger.ts +5 -5
- package/src/selector.ts +3 -3
- package/src/silo.ts +36 -39
- package/src/subscribe.ts +24 -19
- package/src/timeline.ts +9 -4
- package/src/transaction.ts +3 -4
- package/src/internal/atom-internal.ts +0 -54
- package/src/internal/families-internal.ts +0 -144
- package/src/internal/get.ts +0 -129
- package/src/internal/index.ts +0 -15
- package/src/internal/is-default.ts +0 -35
- package/src/internal/operation.ts +0 -139
- package/src/internal/selector/create-read-write-selector.ts +0 -68
- package/src/internal/selector/create-readonly-selector.ts +0 -48
- package/src/internal/selector/index.ts +0 -4
- package/src/internal/selector/lookup-selector-sources.ts +0 -16
- package/src/internal/selector/register-selector.ts +0 -57
- package/src/internal/selector/trace-selector-atoms.ts +0 -43
- package/src/internal/selector/update-selector-atoms.ts +0 -33
- package/src/internal/selector-internal.ts +0 -58
- package/src/internal/set.ts +0 -99
- package/src/internal/store.ts +0 -151
- package/src/internal/subscribe-internal.ts +0 -88
- package/src/internal/time-travel-internal.ts +0 -91
- package/src/internal/timeline/add-atom-to-timeline.ts +0 -168
- package/src/internal/timeline/index.ts +0 -1
- package/src/internal/timeline-internal.ts +0 -107
- package/src/internal/transaction/abort-transaction.ts +0 -12
- package/src/internal/transaction/apply-transaction.ts +0 -57
- package/src/internal/transaction/build-transaction.ts +0 -33
- package/src/internal/transaction/index.ts +0 -25
- package/src/internal/transaction/redo-transaction.ts +0 -23
- package/src/internal/transaction/undo-transaction.ts +0 -23
- package/src/internal/transaction-internal.ts +0 -61
- package/src/introspection/attach-atom-index.ts +0 -73
- package/src/introspection/attach-introspection-states.ts +0 -42
- package/src/introspection/attach-selector-index.ts +0 -77
- package/src/introspection/attach-timeline-family.ts +0 -59
- package/src/introspection/attach-timeline-index.ts +0 -36
- package/src/introspection/attach-transaction-index.ts +0 -38
- package/src/introspection/attach-transaction-logs.ts +0 -40
- package/src/introspection/index.ts +0 -20
- package/src/json/index.ts +0 -1
- package/src/json/select-json.ts +0 -18
- package/src/react/index.ts +0 -2
- package/src/react/store-context.tsx +0 -13
- package/src/react/store-hooks.ts +0 -47
- package/src/react-devtools/AtomIODevtools.tsx +0 -107
- package/src/react-devtools/Button.tsx +0 -24
- package/src/react-devtools/StateEditor.tsx +0 -74
- package/src/react-devtools/StateIndex.tsx +0 -156
- package/src/react-devtools/TimelineIndex.tsx +0 -92
- package/src/react-devtools/TransactionIndex.tsx +0 -70
- package/src/react-devtools/Updates.tsx +0 -145
- package/src/react-devtools/devtools.scss +0 -310
- package/src/react-devtools/index.ts +0 -72
- package/src/react-explorer/AtomIOExplorer.tsx +0 -218
- package/src/react-explorer/explorer-effects.ts +0 -20
- package/src/react-explorer/explorer-states.ts +0 -217
- package/src/react-explorer/index.ts +0 -23
- package/src/react-explorer/space-states.ts +0 -72
- package/src/react-explorer/view-states.ts +0 -41
- package/src/realtime/README.md +0 -33
- package/src/realtime/hook-composition/expose-family.ts +0 -101
- package/src/realtime/hook-composition/expose-single.ts +0 -38
- package/src/realtime/hook-composition/expose-timeline.ts +0 -60
- package/src/realtime/hook-composition/index.ts +0 -12
- package/src/realtime/hook-composition/receive-state.ts +0 -29
- package/src/realtime/hook-composition/receive-transaction.ts +0 -18
- package/src/realtime/index.ts +0 -1
- package/src/realtime-react/index.ts +0 -3
- package/src/realtime-react/realtime-context.tsx +0 -30
- package/src/realtime-react/realtime-hooks.ts +0 -39
- package/src/realtime-react/realtime-state.ts +0 -10
- package/src/realtime-react/use-pull-family-member.ts +0 -26
- package/src/realtime-react/use-pull-family.ts +0 -24
- package/src/realtime-react/use-pull.ts +0 -24
- package/src/realtime-react/use-push.ts +0 -27
- package/src/realtime-react/use-server-action.ts +0 -33
- package/src/realtime-testing/index.ts +0 -1
- package/src/realtime-testing/setup-realtime-test.tsx +0 -159
- package/src/tracker/index.ts +0 -3
- package/src/tracker/tracker.ts +0 -61
- package/src/web-effects/index.ts +0 -1
- package/src/web-effects/storage.ts +0 -30
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import type { Atom, ReadonlySelector, Selector } from "."
|
|
2
|
-
import { target } from "."
|
|
3
|
-
import type { Store } from "./store"
|
|
4
|
-
import { IMPLICIT } from "./store"
|
|
5
|
-
import type { StateToken } from ".."
|
|
6
|
-
|
|
7
|
-
export type OperationProgress =
|
|
8
|
-
| {
|
|
9
|
-
open: false
|
|
10
|
-
}
|
|
11
|
-
| {
|
|
12
|
-
open: true
|
|
13
|
-
done: Set<string>
|
|
14
|
-
prev: Map<string, any>
|
|
15
|
-
time: number
|
|
16
|
-
token: StateToken<any>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const openOperation = (token: StateToken<any>, store: Store): void => {
|
|
20
|
-
const core = target(store)
|
|
21
|
-
if (core.operation.open) {
|
|
22
|
-
store.config.logger?.error(
|
|
23
|
-
`❌ failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`,
|
|
24
|
-
)
|
|
25
|
-
throw Symbol(`violation`)
|
|
26
|
-
}
|
|
27
|
-
core.operation = {
|
|
28
|
-
open: true,
|
|
29
|
-
done: new Set(),
|
|
30
|
-
prev: new Map(store.valueMap),
|
|
31
|
-
time: Date.now(),
|
|
32
|
-
token,
|
|
33
|
-
}
|
|
34
|
-
store.config.logger?.info(
|
|
35
|
-
`⭕ operation start from "${token.key}" in store "${store.config.name}"`,
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
export const closeOperation = (store: Store): void => {
|
|
39
|
-
const core = target(store)
|
|
40
|
-
core.operation = { open: false }
|
|
41
|
-
store.config.logger?.info(`🔴 operation done`)
|
|
42
|
-
store.subject.operationStatus.next(core.operation)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const isDone = (key: string, store: Store = IMPLICIT.STORE): boolean => {
|
|
46
|
-
const core = target(store)
|
|
47
|
-
if (!core.operation.open) {
|
|
48
|
-
store.config.logger?.warn(
|
|
49
|
-
`isDone called outside of an operation. This is probably a bug.`,
|
|
50
|
-
)
|
|
51
|
-
return true
|
|
52
|
-
}
|
|
53
|
-
return core.operation.done.has(key)
|
|
54
|
-
}
|
|
55
|
-
export const markDone = (key: string, store: Store = IMPLICIT.STORE): void => {
|
|
56
|
-
const core = target(store)
|
|
57
|
-
if (!core.operation.open) {
|
|
58
|
-
store.config.logger?.warn(
|
|
59
|
-
`markDone called outside of an operation. This is probably a bug.`,
|
|
60
|
-
)
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
core.operation.done.add(key)
|
|
64
|
-
}
|
|
65
|
-
export const recallState = <T>(
|
|
66
|
-
state: Atom<T> | ReadonlySelector<T> | Selector<T>,
|
|
67
|
-
store: Store = IMPLICIT.STORE,
|
|
68
|
-
): T => {
|
|
69
|
-
const core = target(store)
|
|
70
|
-
if (!core.operation.open) {
|
|
71
|
-
store.config.logger?.warn(
|
|
72
|
-
`recall called outside of an operation. This is probably a bug.`,
|
|
73
|
-
)
|
|
74
|
-
return core.valueMap.get(state.key)
|
|
75
|
-
}
|
|
76
|
-
return core.operation.prev.get(state.key)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const cacheValue = (
|
|
80
|
-
key: string,
|
|
81
|
-
value: unknown,
|
|
82
|
-
store: Store = IMPLICIT.STORE,
|
|
83
|
-
): void => {
|
|
84
|
-
const core = target(store)
|
|
85
|
-
core.valueMap.set(key, value)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export const evictCachedValue = (
|
|
89
|
-
key: string,
|
|
90
|
-
store: Store = IMPLICIT.STORE,
|
|
91
|
-
): void => {
|
|
92
|
-
const core = target(store)
|
|
93
|
-
core.valueMap.delete(key)
|
|
94
|
-
}
|
|
95
|
-
export const readCachedValue = <T>(
|
|
96
|
-
key: string,
|
|
97
|
-
store: Store = IMPLICIT.STORE,
|
|
98
|
-
): T => target(store).valueMap.get(key)
|
|
99
|
-
|
|
100
|
-
export const isValueCached = (
|
|
101
|
-
key: string,
|
|
102
|
-
store: Store = IMPLICIT.STORE,
|
|
103
|
-
): boolean => target(store).valueMap.has(key)
|
|
104
|
-
|
|
105
|
-
export const storeAtom = (
|
|
106
|
-
atom: Atom<any>,
|
|
107
|
-
store: Store = IMPLICIT.STORE,
|
|
108
|
-
): void => {
|
|
109
|
-
const core = target(store)
|
|
110
|
-
core.atoms.set(atom.key, atom)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export const storeSelector = (
|
|
114
|
-
selector: Selector<any>,
|
|
115
|
-
store: Store = IMPLICIT.STORE,
|
|
116
|
-
): void => {
|
|
117
|
-
const core = target(store)
|
|
118
|
-
core.selectors.set(selector.key, selector)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export const storeReadonlySelector = (
|
|
122
|
-
selector: ReadonlySelector<any>,
|
|
123
|
-
store: Store = IMPLICIT.STORE,
|
|
124
|
-
): void => {
|
|
125
|
-
const core = target(store)
|
|
126
|
-
core.readonlySelectors.set(selector.key, selector)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export const hasKeyBeenUsed = (
|
|
130
|
-
key: string,
|
|
131
|
-
store: Store = IMPLICIT.STORE,
|
|
132
|
-
): boolean => {
|
|
133
|
-
const core = target(store)
|
|
134
|
-
return (
|
|
135
|
-
core.atoms.has(key) ||
|
|
136
|
-
core.selectors.has(key) ||
|
|
137
|
-
core.readonlySelectors.has(key)
|
|
138
|
-
)
|
|
139
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { become } from "~/packages/anvl/src/function"
|
|
2
|
-
|
|
3
|
-
import { Subject } from ".."
|
|
4
|
-
import {
|
|
5
|
-
type Store,
|
|
6
|
-
type Selector,
|
|
7
|
-
type StoreCore,
|
|
8
|
-
registerSelector,
|
|
9
|
-
selector__INTERNAL,
|
|
10
|
-
} from ".."
|
|
11
|
-
import type { FamilyMetadata, SelectorToken } from "../.."
|
|
12
|
-
import type { SelectorOptions } from "../../selector"
|
|
13
|
-
import { cacheValue, markDone } from "../operation"
|
|
14
|
-
|
|
15
|
-
export const createReadWriteSelector = <T>(
|
|
16
|
-
options: SelectorOptions<T>,
|
|
17
|
-
family: FamilyMetadata | undefined,
|
|
18
|
-
store: Store,
|
|
19
|
-
core: StoreCore,
|
|
20
|
-
): SelectorToken<T> => {
|
|
21
|
-
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
22
|
-
|
|
23
|
-
const { get, set } = registerSelector(options.key, store)
|
|
24
|
-
const getSelf = () => {
|
|
25
|
-
const value = options.get({ get })
|
|
26
|
-
cacheValue(options.key, value, store)
|
|
27
|
-
return value
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const setSelf = (next: T | ((oldValue: T) => T)): void => {
|
|
31
|
-
const oldValue = getSelf()
|
|
32
|
-
store.config.logger?.info(
|
|
33
|
-
` <- "${options.key}" went (`,
|
|
34
|
-
oldValue,
|
|
35
|
-
`->`,
|
|
36
|
-
next,
|
|
37
|
-
`)`,
|
|
38
|
-
)
|
|
39
|
-
const newValue = become(next)(oldValue)
|
|
40
|
-
cacheValue(options.key, newValue, store)
|
|
41
|
-
markDone(options.key, store)
|
|
42
|
-
if (store.transactionStatus.phase === `idle`) {
|
|
43
|
-
subject.next({ newValue, oldValue })
|
|
44
|
-
}
|
|
45
|
-
options.set({ get, set }, newValue)
|
|
46
|
-
}
|
|
47
|
-
const mySelector: Selector<T> = {
|
|
48
|
-
...options,
|
|
49
|
-
subject,
|
|
50
|
-
install: (s: Store) => selector__INTERNAL(options, family, s),
|
|
51
|
-
get: getSelf,
|
|
52
|
-
set: setSelf,
|
|
53
|
-
type: `selector`,
|
|
54
|
-
...(family && { family }),
|
|
55
|
-
}
|
|
56
|
-
core.selectors.set(options.key, mySelector)
|
|
57
|
-
const initialValue = getSelf()
|
|
58
|
-
store.config.logger?.info(` ✨ "${options.key}" =`, initialValue)
|
|
59
|
-
const token: SelectorToken<T> = {
|
|
60
|
-
key: options.key,
|
|
61
|
-
type: `selector`,
|
|
62
|
-
}
|
|
63
|
-
if (family) {
|
|
64
|
-
token.family = family
|
|
65
|
-
}
|
|
66
|
-
store.subject.selectorCreation.next(token)
|
|
67
|
-
return token
|
|
68
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { registerSelector } from "./register-selector"
|
|
2
|
-
import { Subject } from ".."
|
|
3
|
-
import type {
|
|
4
|
-
FamilyMetadata,
|
|
5
|
-
ReadonlySelectorOptions,
|
|
6
|
-
ReadonlySelectorToken,
|
|
7
|
-
Store,
|
|
8
|
-
} from "../.."
|
|
9
|
-
import { cacheValue } from "../operation"
|
|
10
|
-
import { selector__INTERNAL, type ReadonlySelector } from "../selector-internal"
|
|
11
|
-
import type { StoreCore } from "../store"
|
|
12
|
-
|
|
13
|
-
export const createReadonlySelector = <T>(
|
|
14
|
-
options: ReadonlySelectorOptions<T>,
|
|
15
|
-
family: FamilyMetadata | undefined,
|
|
16
|
-
store: Store,
|
|
17
|
-
core: StoreCore,
|
|
18
|
-
): ReadonlySelectorToken<T> => {
|
|
19
|
-
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
20
|
-
|
|
21
|
-
const { get } = registerSelector(options.key, store)
|
|
22
|
-
const getSelf = () => {
|
|
23
|
-
const value = options.get({ get })
|
|
24
|
-
cacheValue(options.key, value, store)
|
|
25
|
-
return value
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const readonlySelector: ReadonlySelector<T> = {
|
|
29
|
-
...options,
|
|
30
|
-
subject,
|
|
31
|
-
install: (s: Store) => selector__INTERNAL(options, family, s),
|
|
32
|
-
get: getSelf,
|
|
33
|
-
type: `readonly_selector`,
|
|
34
|
-
...(family && { family }),
|
|
35
|
-
}
|
|
36
|
-
core.readonlySelectors.set(options.key, readonlySelector)
|
|
37
|
-
const initialValue = getSelf()
|
|
38
|
-
store.config.logger?.info(` ✨ "${options.key}" =`, initialValue)
|
|
39
|
-
const token: ReadonlySelectorToken<T> = {
|
|
40
|
-
key: options.key,
|
|
41
|
-
type: `readonly_selector`,
|
|
42
|
-
}
|
|
43
|
-
if (family) {
|
|
44
|
-
token.family = family
|
|
45
|
-
}
|
|
46
|
-
store.subject.selectorCreation.next(token)
|
|
47
|
-
return token
|
|
48
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Store } from ".."
|
|
2
|
-
import { target, lookup } from ".."
|
|
3
|
-
import type { AtomToken, ReadonlySelectorToken, SelectorToken } from "../.."
|
|
4
|
-
|
|
5
|
-
export const lookupSelectorSources = (
|
|
6
|
-
key: string,
|
|
7
|
-
store: Store,
|
|
8
|
-
): (
|
|
9
|
-
| AtomToken<unknown>
|
|
10
|
-
| ReadonlySelectorToken<unknown>
|
|
11
|
-
| SelectorToken<unknown>
|
|
12
|
-
)[] =>
|
|
13
|
-
target(store)
|
|
14
|
-
.selectorGraph.getRelations(key)
|
|
15
|
-
.filter(({ source }) => source !== key)
|
|
16
|
-
.map(({ source }) => lookup(source, store))
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { updateSelectorAtoms } from "./update-selector-atoms"
|
|
2
|
-
import type { Transactors } from "../../transaction"
|
|
3
|
-
import { getState__INTERNAL, withdraw } from "../get"
|
|
4
|
-
import { setState__INTERNAL } from "../set"
|
|
5
|
-
import type { Store } from "../store"
|
|
6
|
-
import { IMPLICIT } from "../store"
|
|
7
|
-
import { target } from "../transaction-internal"
|
|
8
|
-
|
|
9
|
-
export const registerSelector = (
|
|
10
|
-
selectorKey: string,
|
|
11
|
-
store: Store = IMPLICIT.STORE,
|
|
12
|
-
): Transactors => ({
|
|
13
|
-
get: (dependency) => {
|
|
14
|
-
const core = target(store)
|
|
15
|
-
const alreadyRegistered = core.selectorGraph
|
|
16
|
-
.getRelations(selectorKey)
|
|
17
|
-
.some(({ source }) => source === dependency.key)
|
|
18
|
-
|
|
19
|
-
const dependencyState = withdraw(dependency, store)
|
|
20
|
-
if (dependencyState === null) {
|
|
21
|
-
throw new Error(
|
|
22
|
-
`State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
const dependencyValue = getState__INTERNAL(dependencyState, store)
|
|
26
|
-
|
|
27
|
-
if (alreadyRegistered) {
|
|
28
|
-
store.config.logger?.info(
|
|
29
|
-
` || ${selectorKey} <- ${dependency.key} =`,
|
|
30
|
-
dependencyValue,
|
|
31
|
-
)
|
|
32
|
-
} else {
|
|
33
|
-
store.config.logger?.info(
|
|
34
|
-
`🔌 registerSelector "${selectorKey}" <- ( "${dependency.key}" =`,
|
|
35
|
-
dependencyValue,
|
|
36
|
-
`)`,
|
|
37
|
-
)
|
|
38
|
-
core.selectorGraph = core.selectorGraph.set(
|
|
39
|
-
{ from: dependency.key, to: selectorKey },
|
|
40
|
-
{
|
|
41
|
-
source: dependency.key,
|
|
42
|
-
},
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
updateSelectorAtoms(selectorKey, dependency, store)
|
|
46
|
-
return dependencyValue
|
|
47
|
-
},
|
|
48
|
-
set: (stateToken, newValue) => {
|
|
49
|
-
const state = withdraw(stateToken, store)
|
|
50
|
-
if (state === null) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
setState__INTERNAL(state, newValue, store)
|
|
56
|
-
},
|
|
57
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { lookupSelectorSources } from "./lookup-selector-sources"
|
|
2
|
-
import type { Store, AtomToken, ReadonlySelectorToken, StateToken } from "../.."
|
|
3
|
-
|
|
4
|
-
export const traceSelectorAtoms = (
|
|
5
|
-
selectorKey: string,
|
|
6
|
-
dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>,
|
|
7
|
-
store: Store,
|
|
8
|
-
): AtomToken<unknown>[] => {
|
|
9
|
-
const roots: AtomToken<unknown>[] = []
|
|
10
|
-
|
|
11
|
-
const sources = lookupSelectorSources(dependency.key, store)
|
|
12
|
-
let depth = 0
|
|
13
|
-
while (sources.length > 0) {
|
|
14
|
-
// rome-ignore lint/style/noNonNullAssertion: just checked length ^^^
|
|
15
|
-
const source = sources.shift()!
|
|
16
|
-
++depth
|
|
17
|
-
if (depth > 999) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
`Maximum selector dependency depth exceeded in selector "${selectorKey}".`,
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (source.type !== `atom`) {
|
|
24
|
-
sources.push(...lookupSelectorSources(source.key, store))
|
|
25
|
-
} else {
|
|
26
|
-
roots.push(source)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return roots
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const traceAllSelectorAtoms = (
|
|
34
|
-
selectorKey: string,
|
|
35
|
-
store: Store,
|
|
36
|
-
): AtomToken<unknown>[] => {
|
|
37
|
-
const sources = lookupSelectorSources(selectorKey, store)
|
|
38
|
-
return sources.flatMap((source) =>
|
|
39
|
-
source.type === `atom`
|
|
40
|
-
? source
|
|
41
|
-
: traceSelectorAtoms(selectorKey, source, store),
|
|
42
|
-
)
|
|
43
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { traceSelectorAtoms } from "./trace-selector-atoms"
|
|
2
|
-
import type { Store } from ".."
|
|
3
|
-
import { target } from ".."
|
|
4
|
-
import type { ReadonlySelectorToken, StateToken } from "../.."
|
|
5
|
-
|
|
6
|
-
export const updateSelectorAtoms = (
|
|
7
|
-
selectorKey: string,
|
|
8
|
-
dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>,
|
|
9
|
-
store: Store,
|
|
10
|
-
): void => {
|
|
11
|
-
const core = target(store)
|
|
12
|
-
if (dependency.type === `atom`) {
|
|
13
|
-
core.selectorAtoms = core.selectorAtoms.set({
|
|
14
|
-
selectorKey,
|
|
15
|
-
atomKey: dependency.key,
|
|
16
|
-
})
|
|
17
|
-
store.config.logger?.info(
|
|
18
|
-
` || adding root for "${selectorKey}": ${dependency.key}`,
|
|
19
|
-
)
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
const roots = traceSelectorAtoms(selectorKey, dependency, store)
|
|
23
|
-
store.config.logger?.info(
|
|
24
|
-
` || adding roots for "${selectorKey}":`,
|
|
25
|
-
roots.map((r) => r.key),
|
|
26
|
-
)
|
|
27
|
-
for (const root of roots) {
|
|
28
|
-
core.selectorAtoms = core.selectorAtoms.set({
|
|
29
|
-
selectorKey,
|
|
30
|
-
atomKey: root.key,
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { target, IMPLICIT } from "."
|
|
2
|
-
import type { Store, Subject } from "."
|
|
3
|
-
import { createReadWriteSelector } from "./selector/create-read-write-selector"
|
|
4
|
-
import { createReadonlySelector } from "./selector/create-readonly-selector"
|
|
5
|
-
import type {
|
|
6
|
-
FamilyMetadata,
|
|
7
|
-
ReadonlySelectorOptions,
|
|
8
|
-
ReadonlySelectorToken,
|
|
9
|
-
SelectorOptions,
|
|
10
|
-
SelectorToken,
|
|
11
|
-
} from ".."
|
|
12
|
-
|
|
13
|
-
export type Selector<T> = {
|
|
14
|
-
key: string
|
|
15
|
-
type: `selector`
|
|
16
|
-
family?: FamilyMetadata
|
|
17
|
-
install: (store: Store) => void
|
|
18
|
-
subject: Subject<{ newValue: T; oldValue: T }>
|
|
19
|
-
get: () => T
|
|
20
|
-
set: (newValue: T | ((oldValue: T) => T)) => void
|
|
21
|
-
}
|
|
22
|
-
export type ReadonlySelector<T> = {
|
|
23
|
-
key: string
|
|
24
|
-
type: `readonly_selector`
|
|
25
|
-
family?: FamilyMetadata
|
|
26
|
-
install: (store: Store) => void
|
|
27
|
-
subject: Subject<{ newValue: T; oldValue: T }>
|
|
28
|
-
get: () => T
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function selector__INTERNAL<T>(
|
|
32
|
-
options: SelectorOptions<T>,
|
|
33
|
-
family?: FamilyMetadata,
|
|
34
|
-
store?: Store,
|
|
35
|
-
): SelectorToken<T>
|
|
36
|
-
export function selector__INTERNAL<T>(
|
|
37
|
-
options: ReadonlySelectorOptions<T>,
|
|
38
|
-
family?: FamilyMetadata,
|
|
39
|
-
store?: Store,
|
|
40
|
-
): ReadonlySelectorToken<T>
|
|
41
|
-
export function selector__INTERNAL<T>(
|
|
42
|
-
options: ReadonlySelectorOptions<T> | SelectorOptions<T>,
|
|
43
|
-
family?: FamilyMetadata,
|
|
44
|
-
store: Store = IMPLICIT.STORE,
|
|
45
|
-
): ReadonlySelectorToken<T> | SelectorToken<T> {
|
|
46
|
-
const core = target(store)
|
|
47
|
-
|
|
48
|
-
if (core.selectors.has(options.key)) {
|
|
49
|
-
store.config.logger?.error(
|
|
50
|
-
`Key "${options.key}" already exists in the store.`,
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (!(`set` in options)) {
|
|
55
|
-
return createReadonlySelector(options, family, store, core)
|
|
56
|
-
}
|
|
57
|
-
return createReadWriteSelector(options, family, store, core)
|
|
58
|
-
}
|
package/src/internal/set.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { become } from "~/packages/anvl/src/function"
|
|
2
|
-
|
|
3
|
-
import type { Atom, Selector, Store } from "."
|
|
4
|
-
import {
|
|
5
|
-
IMPLICIT,
|
|
6
|
-
cacheValue,
|
|
7
|
-
emitUpdate,
|
|
8
|
-
evictCachedValue,
|
|
9
|
-
getState__INTERNAL,
|
|
10
|
-
isAtomDefault,
|
|
11
|
-
isDone,
|
|
12
|
-
markAtomAsNotDefault,
|
|
13
|
-
markDone,
|
|
14
|
-
stowUpdate,
|
|
15
|
-
target,
|
|
16
|
-
} from "."
|
|
17
|
-
|
|
18
|
-
export const evictDownStream = <T>(
|
|
19
|
-
state: Atom<T>,
|
|
20
|
-
store: Store = IMPLICIT.STORE,
|
|
21
|
-
): void => {
|
|
22
|
-
const core = target(store)
|
|
23
|
-
const downstream = core.selectorAtoms.getRelations(state.key)
|
|
24
|
-
const downstreamKeys = downstream.map(({ id }) => id)
|
|
25
|
-
store.config.logger?.info(
|
|
26
|
-
` || ${downstreamKeys.length} downstream:`,
|
|
27
|
-
downstreamKeys,
|
|
28
|
-
)
|
|
29
|
-
if (core.operation.open) {
|
|
30
|
-
store.config.logger?.info(` ||`, [...core.operation.done], `already done`)
|
|
31
|
-
}
|
|
32
|
-
downstream.forEach(({ id: stateKey }) => {
|
|
33
|
-
if (isDone(stateKey, store)) {
|
|
34
|
-
store.config.logger?.info(` || ${stateKey} already done`)
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
const state =
|
|
38
|
-
core.selectors.get(stateKey) ?? core.readonlySelectors.get(stateKey)
|
|
39
|
-
if (!state) {
|
|
40
|
-
store.config.logger?.info(
|
|
41
|
-
` || ${stateKey} is an atom, and can't be downstream`,
|
|
42
|
-
)
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
evictCachedValue(stateKey, store)
|
|
46
|
-
store.config.logger?.info(` xx evicted "${stateKey}"`)
|
|
47
|
-
|
|
48
|
-
markDone(stateKey, store)
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const setAtomState = <T>(
|
|
53
|
-
atom: Atom<T>,
|
|
54
|
-
next: T | ((oldValue: T) => T),
|
|
55
|
-
store: Store = IMPLICIT.STORE,
|
|
56
|
-
): void => {
|
|
57
|
-
const oldValue = getState__INTERNAL(atom, store)
|
|
58
|
-
const newValue = become(next)(oldValue)
|
|
59
|
-
store.config.logger?.info(`<< setting atom "${atom.key}" to`, newValue)
|
|
60
|
-
cacheValue(atom.key, newValue, store)
|
|
61
|
-
if (isAtomDefault(atom.key, store)) {
|
|
62
|
-
markAtomAsNotDefault(atom.key, store)
|
|
63
|
-
}
|
|
64
|
-
markDone(atom.key, store)
|
|
65
|
-
store.config.logger?.info(
|
|
66
|
-
` || evicting caches downstream from "${atom.key}"`,
|
|
67
|
-
)
|
|
68
|
-
evictDownStream(atom, store)
|
|
69
|
-
const update = { oldValue, newValue }
|
|
70
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
71
|
-
emitUpdate(atom, update, store)
|
|
72
|
-
} else {
|
|
73
|
-
stowUpdate(atom, update, store)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export const setSelectorState = <T>(
|
|
77
|
-
selector: Selector<T>,
|
|
78
|
-
next: T | ((oldValue: T) => T),
|
|
79
|
-
store: Store = IMPLICIT.STORE,
|
|
80
|
-
): void => {
|
|
81
|
-
const oldValue = getState__INTERNAL(selector, store)
|
|
82
|
-
const newValue = become(next)(oldValue)
|
|
83
|
-
|
|
84
|
-
store.config.logger?.info(`<< setting selector "${selector.key}" to`, newValue)
|
|
85
|
-
store.config.logger?.info(` || propagating change made to "${selector.key}"`)
|
|
86
|
-
|
|
87
|
-
selector.set(newValue)
|
|
88
|
-
}
|
|
89
|
-
export const setState__INTERNAL = <T>(
|
|
90
|
-
state: Atom<T> | Selector<T>,
|
|
91
|
-
value: T | ((oldValue: T) => T),
|
|
92
|
-
store: Store = IMPLICIT.STORE,
|
|
93
|
-
): void => {
|
|
94
|
-
if (`set` in state) {
|
|
95
|
-
setSelectorState(state, value, store)
|
|
96
|
-
} else {
|
|
97
|
-
setAtomState(state, value, store)
|
|
98
|
-
}
|
|
99
|
-
}
|