atom.io 0.6.8 → 0.7.0
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/README.md +21 -2
- package/dist/index.d.mts +42 -461
- package/dist/index.d.ts +42 -461
- package/dist/index.js +128 -1792
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -1742
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +342 -0
- package/internal/dist/index.d.ts +342 -0
- package/internal/dist/index.js +1873 -0
- package/internal/dist/index.js.map +1 -0
- package/internal/dist/index.mjs +1798 -0
- package/internal/dist/index.mjs.map +1 -0
- package/internal/package.json +15 -0
- package/internal/src/atom/create-atom.ts +75 -0
- package/internal/src/atom/delete-atom.ts +10 -0
- package/internal/src/atom/index.ts +3 -0
- package/{src/internal → internal/src/atom}/is-default.ts +4 -2
- package/internal/src/caching.ts +21 -0
- package/internal/src/families/create-atom-family.ts +59 -0
- package/internal/src/families/create-readonly-selector-family.ts +45 -0
- package/internal/src/families/create-selector-family.ts +67 -0
- package/internal/src/families/index.ts +3 -0
- package/internal/src/get-state-internal.ts +23 -0
- package/internal/src/index.ts +13 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +25 -0
- package/internal/src/mutable/create-mutable-atom.ts +49 -0
- package/internal/src/mutable/get-json-token.ts +22 -0
- package/internal/src/mutable/get-update-token.ts +20 -0
- package/internal/src/mutable/index.ts +17 -0
- package/internal/src/mutable/is-atom-token-mutable.ts +7 -0
- package/internal/src/mutable/tracker-family.ts +61 -0
- package/internal/src/mutable/tracker.ts +164 -0
- package/internal/src/mutable/transceiver.ts +110 -0
- package/internal/src/operation.ts +68 -0
- package/{src/internal → internal/src}/selector/create-read-write-selector.ts +10 -13
- package/{src/internal → internal/src}/selector/create-readonly-selector.ts +9 -8
- package/internal/src/selector/create-selector.ts +65 -0
- package/{src/internal → internal/src}/selector/index.ts +1 -0
- package/internal/src/selector/lookup-selector-sources.ts +20 -0
- package/{src/internal → internal/src}/selector/register-selector.ts +13 -9
- package/{src/internal → internal/src}/selector/trace-selector-atoms.ts +4 -2
- package/{src/internal → internal/src}/selector/update-selector-atoms.ts +4 -3
- package/internal/src/set-state/become.ts +10 -0
- package/internal/src/set-state/copy-mutable-if-needed.ts +23 -0
- package/internal/src/set-state/copy-mutable-in-transaction.ts +59 -0
- package/internal/src/set-state/copy-mutable-into-new-store.ts +34 -0
- package/internal/src/set-state/emit-update.ts +23 -0
- package/internal/src/set-state/evict-downstream.ts +39 -0
- package/internal/src/set-state/index.ts +2 -0
- package/internal/src/set-state/set-atom-state.ts +38 -0
- package/internal/src/set-state/set-selector-state.ts +19 -0
- package/internal/src/set-state/set-state-internal.ts +18 -0
- package/internal/src/set-state/stow-update.ts +42 -0
- package/internal/src/store/deposit.ts +43 -0
- package/internal/src/store/index.ts +5 -0
- package/internal/src/store/lookup.ts +26 -0
- package/internal/src/store/store.ts +154 -0
- package/internal/src/store/withdraw-new-family-member.ts +53 -0
- package/internal/src/store/withdraw.ts +113 -0
- package/internal/src/subject.ts +21 -0
- package/internal/src/subscribe/index.ts +1 -0
- package/internal/src/subscribe/recall-state.ts +19 -0
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +47 -0
- package/{src/internal → internal/src}/timeline/add-atom-to-timeline.ts +50 -29
- package/internal/src/timeline/index.ts +3 -0
- package/{src/internal → internal/src/timeline}/time-travel-internal.ts +6 -6
- package/{src/internal → internal/src/timeline}/timeline-internal.ts +20 -12
- package/{src/internal → internal/src}/transaction/abort-transaction.ts +1 -1
- package/{src/internal → internal/src}/transaction/apply-transaction.ts +25 -18
- package/{src/internal → internal/src}/transaction/build-transaction.ts +12 -6
- package/{src/internal → internal/src}/transaction/index.ts +3 -2
- package/{src/internal → internal/src}/transaction/redo-transaction.ts +4 -5
- package/{src/internal → internal/src/transaction}/transaction-internal.ts +16 -13
- package/{src/internal → internal/src}/transaction/undo-transaction.ts +4 -5
- package/introspection/dist/index.d.mts +12 -260
- package/introspection/dist/index.d.ts +12 -260
- package/introspection/dist/index.js +125 -140
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +103 -116
- package/introspection/dist/index.mjs.map +1 -1
- package/{src/introspection → introspection/src}/attach-atom-index.ts +41 -30
- package/{src/introspection → introspection/src}/attach-introspection-states.ts +6 -10
- package/introspection/src/attach-selector-index.ts +90 -0
- package/{src/introspection → introspection/src}/attach-timeline-family.ts +16 -16
- package/introspection/src/attach-timeline-index.ts +38 -0
- package/introspection/src/attach-transaction-index.ts +40 -0
- package/{src/introspection → introspection/src}/attach-transaction-logs.ts +11 -8
- package/json/dist/index.d.mts +41 -2
- package/json/dist/index.d.ts +41 -2
- package/json/dist/index.js +88 -48
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +76 -13
- package/json/dist/index.mjs.map +1 -1
- package/json/src/index.ts +5 -0
- package/json/src/select-json-family.ts +35 -0
- package/json/src/select-json.ts +22 -0
- package/package.json +105 -57
- package/react/dist/index.d.mts +9 -17
- package/react/dist/index.d.ts +9 -17
- package/react/dist/index.js +45 -77
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +18 -34
- package/react/dist/index.mjs.map +1 -1
- package/react/src/store-context.tsx +12 -0
- package/react/src/store-hooks.ts +36 -0
- package/react-devtools/dist/index.css +1 -1
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +199 -230
- package/react-devtools/dist/index.d.ts +199 -230
- package/react-devtools/dist/index.js +610 -2466
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +543 -2401
- package/react-devtools/dist/index.mjs.map +1 -1
- package/{src/react-devtools → react-devtools/src}/AtomIODevtools.tsx +5 -3
- package/{src/react-devtools → react-devtools/src}/Button.tsx +2 -3
- package/{src/react-devtools → react-devtools/src}/StateEditor.tsx +3 -2
- package/{src/react-devtools → react-devtools/src}/StateIndex.tsx +7 -4
- package/{src/react-devtools → react-devtools/src}/TimelineIndex.tsx +7 -11
- package/{src/react-devtools → react-devtools/src}/TransactionIndex.tsx +4 -4
- package/{src/react-devtools → react-devtools/src}/Updates.tsx +9 -4
- package/{src/react-devtools → react-devtools/src}/index.ts +5 -5
- package/realtime-react/dist/index.d.mts +9 -25
- package/realtime-react/dist/index.d.ts +9 -25
- package/realtime-react/dist/index.js +75 -193
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +44 -148
- package/realtime-react/dist/index.mjs.map +1 -1
- package/realtime-react/src/index.ts +7 -0
- package/{src/realtime-react → realtime-react/src}/realtime-context.tsx +3 -4
- package/realtime-react/src/use-pull-family-member.ts +15 -0
- package/realtime-react/src/use-pull-mutable-family-member.ts +20 -0
- package/realtime-react/src/use-pull-mutable.ts +17 -0
- package/realtime-react/src/use-pull.ts +15 -0
- package/realtime-react/src/use-push.ts +19 -0
- package/realtime-react/src/use-server-action.ts +18 -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 +147 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +116 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/{src/realtime-testing → realtime-testing/src}/setup-realtime-test.tsx +10 -8
- package/src/atom.ts +64 -8
- package/src/index.ts +36 -29
- package/src/logger.ts +7 -7
- package/src/selector.ts +5 -5
- package/src/silo.ts +49 -43
- package/src/subscribe.ts +27 -22
- package/src/timeline.ts +9 -4
- package/src/transaction.ts +3 -4
- package/transceivers/set-rtx/dist/index.d.mts +39 -0
- package/transceivers/set-rtx/dist/index.d.ts +39 -0
- package/transceivers/set-rtx/dist/index.js +213 -0
- package/transceivers/set-rtx/dist/index.js.map +1 -0
- package/transceivers/set-rtx/dist/index.mjs +211 -0
- package/transceivers/set-rtx/dist/index.mjs.map +1 -0
- package/{realtime → transceivers/set-rtx}/package.json +1 -1
- package/transceivers/set-rtx/src/index.ts +1 -0
- package/transceivers/set-rtx/src/set-rtx.ts +242 -0
- package/realtime/dist/index.d.mts +0 -25
- package/realtime/dist/index.d.ts +0 -25
- package/realtime/dist/index.js +0 -190
- package/realtime/dist/index.js.map +0 -1
- package/realtime/dist/index.mjs +0 -151
- package/realtime/dist/index.mjs.map +0 -1
- 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/operation.ts +0 -139
- package/src/internal/selector/lookup-selector-sources.ts +0 -16
- 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/timeline/index.ts +0 -1
- package/src/introspection/attach-selector-index.ts +0 -77
- package/src/introspection/attach-timeline-index.ts +0 -36
- package/src/introspection/attach-transaction-index.ts +0 -38
- package/src/json/index.ts +0 -1
- package/src/json/select-json.ts +0 -18
- package/src/react/store-context.tsx +0 -13
- package/src/react/store-hooks.ts +0 -47
- 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-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/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
- /package/{src/introspection → introspection/src}/index.ts +0 -0
- /package/{src/react → react/src}/index.ts +0 -0
- /package/{src/react-devtools → react-devtools/src}/devtools.scss +0 -0
- /package/{src/realtime-testing → realtime-testing/src}/index.ts +0 -0
|
@@ -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
|
-
}
|
package/src/internal/store.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type { ƒn } from "~/packages/anvl/src/function"
|
|
2
|
-
import { doNothing } from "~/packages/anvl/src/function"
|
|
3
|
-
import { Join } from "~/packages/anvl/src/join"
|
|
4
|
-
|
|
5
|
-
import { Subject } from "."
|
|
6
|
-
import type {
|
|
7
|
-
Atom,
|
|
8
|
-
OperationProgress,
|
|
9
|
-
ReadonlySelector,
|
|
10
|
-
Selector,
|
|
11
|
-
TransactionStatus,
|
|
12
|
-
Timeline,
|
|
13
|
-
Transaction,
|
|
14
|
-
} from "."
|
|
15
|
-
import type {
|
|
16
|
-
AtomToken,
|
|
17
|
-
Logger,
|
|
18
|
-
ReadonlySelectorToken,
|
|
19
|
-
SelectorToken,
|
|
20
|
-
TimelineToken,
|
|
21
|
-
TransactionToken,
|
|
22
|
-
} from ".."
|
|
23
|
-
|
|
24
|
-
export type StoreCore = Pick<
|
|
25
|
-
Store,
|
|
26
|
-
| `atoms`
|
|
27
|
-
| `atomsThatAreDefault`
|
|
28
|
-
| `operation`
|
|
29
|
-
| `readonlySelectors`
|
|
30
|
-
| `selectorAtoms`
|
|
31
|
-
| `selectorGraph`
|
|
32
|
-
| `selectors`
|
|
33
|
-
| `timelineAtoms`
|
|
34
|
-
| `timelines`
|
|
35
|
-
| `transactions`
|
|
36
|
-
| `valueMap`
|
|
37
|
-
>
|
|
38
|
-
|
|
39
|
-
export interface Store {
|
|
40
|
-
atoms: Map<string, Atom<any>>
|
|
41
|
-
atomsThatAreDefault: Set<string>
|
|
42
|
-
readonlySelectors: Map<string, ReadonlySelector<any>>
|
|
43
|
-
selectorAtoms: Join<null, `selectorKey`, `atomKey`>
|
|
44
|
-
selectorGraph: Join<{ source: string }>
|
|
45
|
-
selectors: Map<string, Selector<any>>
|
|
46
|
-
timelineAtoms: Join<null, `timelineKey`, `atomKey`>
|
|
47
|
-
timelines: Map<string, Timeline>
|
|
48
|
-
transactions: Map<string, Transaction<any>>
|
|
49
|
-
valueMap: Map<string, any>
|
|
50
|
-
|
|
51
|
-
subject: {
|
|
52
|
-
atomCreation: Subject<AtomToken<unknown>>
|
|
53
|
-
selectorCreation: Subject<
|
|
54
|
-
ReadonlySelectorToken<unknown> | SelectorToken<unknown>
|
|
55
|
-
>
|
|
56
|
-
transactionCreation: Subject<TransactionToken<ƒn>>
|
|
57
|
-
timelineCreation: Subject<TimelineToken>
|
|
58
|
-
operationStatus: Subject<OperationProgress>
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
operation: OperationProgress
|
|
62
|
-
transactionStatus: TransactionStatus<ƒn>
|
|
63
|
-
config: {
|
|
64
|
-
name: string
|
|
65
|
-
logger: Logger | null
|
|
66
|
-
logger__INTERNAL: Logger
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const createStore = (name: string, store: Store | null = null): Store => {
|
|
71
|
-
const created = {
|
|
72
|
-
...(store ??
|
|
73
|
-
(() => ({
|
|
74
|
-
atomsThatAreDefault: new Set(),
|
|
75
|
-
selectorAtoms: new Join({ relationType: `n:n` })
|
|
76
|
-
.from(`selectorKey`)
|
|
77
|
-
.to(`atomKey`),
|
|
78
|
-
selectorGraph: new Join({ relationType: `n:n` }),
|
|
79
|
-
}))()),
|
|
80
|
-
|
|
81
|
-
valueMap: new Map(store?.valueMap),
|
|
82
|
-
atoms: new Map(),
|
|
83
|
-
readonlySelectors: new Map(),
|
|
84
|
-
selectors: new Map(),
|
|
85
|
-
transactions: new Map(),
|
|
86
|
-
timelines: new Map(),
|
|
87
|
-
|
|
88
|
-
timelineAtoms: new Join({ relationType: `1:n` })
|
|
89
|
-
.from(`timelineKey`)
|
|
90
|
-
.to(`atomKey`),
|
|
91
|
-
|
|
92
|
-
subject: {
|
|
93
|
-
atomCreation: new Subject(),
|
|
94
|
-
selectorCreation: new Subject(),
|
|
95
|
-
transactionCreation: new Subject(),
|
|
96
|
-
timelineCreation: new Subject(),
|
|
97
|
-
operationStatus: new Subject(),
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
operation: {
|
|
101
|
-
open: false,
|
|
102
|
-
...store?.operation,
|
|
103
|
-
},
|
|
104
|
-
transactionStatus: {
|
|
105
|
-
phase: `idle`,
|
|
106
|
-
...store?.transactionStatus,
|
|
107
|
-
},
|
|
108
|
-
config: {
|
|
109
|
-
logger: {
|
|
110
|
-
...console,
|
|
111
|
-
info: doNothing,
|
|
112
|
-
...store?.config?.logger,
|
|
113
|
-
},
|
|
114
|
-
logger__INTERNAL: console,
|
|
115
|
-
...store?.config,
|
|
116
|
-
name,
|
|
117
|
-
},
|
|
118
|
-
} satisfies Store
|
|
119
|
-
|
|
120
|
-
store?.atoms.forEach((atom) => {
|
|
121
|
-
const copiedAtom = { ...atom, subject: new Subject() } satisfies Atom<any>
|
|
122
|
-
created.atoms.set(atom.key, copiedAtom)
|
|
123
|
-
})
|
|
124
|
-
store?.readonlySelectors.forEach((selector) => {
|
|
125
|
-
selector.install(created)
|
|
126
|
-
})
|
|
127
|
-
store?.selectors.forEach((selector) => {
|
|
128
|
-
selector.install(created)
|
|
129
|
-
})
|
|
130
|
-
store?.transactions.forEach((tx) => {
|
|
131
|
-
tx.install(created)
|
|
132
|
-
})
|
|
133
|
-
store?.timelines.forEach((timeline) => {
|
|
134
|
-
timeline.install(created)
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
return created
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export const IMPLICIT = {
|
|
141
|
-
STORE_INTERNAL: undefined as Store | undefined,
|
|
142
|
-
get STORE(): Store {
|
|
143
|
-
return this.STORE_INTERNAL ?? (this.STORE_INTERNAL = createStore(`DEFAULT`))
|
|
144
|
-
},
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export const clearStore = (store: Store = IMPLICIT.STORE): void => {
|
|
148
|
-
const { config } = store
|
|
149
|
-
Object.assign(store, createStore(config.name))
|
|
150
|
-
store.config = config
|
|
151
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { Atom, ReadonlySelector, Selector, Store } from "."
|
|
2
|
-
import {
|
|
3
|
-
getState__INTERNAL,
|
|
4
|
-
withdraw,
|
|
5
|
-
recallState,
|
|
6
|
-
traceAllSelectorAtoms,
|
|
7
|
-
} from "."
|
|
8
|
-
import type { StateUpdate } from ".."
|
|
9
|
-
|
|
10
|
-
export const prepareUpdate = <T>(
|
|
11
|
-
state: Atom<T> | ReadonlySelector<T> | Selector<T>,
|
|
12
|
-
store: Store,
|
|
13
|
-
): StateUpdate<T> => {
|
|
14
|
-
const oldValue = recallState(state, store)
|
|
15
|
-
const newValue = getState__INTERNAL(state, store)
|
|
16
|
-
return { newValue, oldValue }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const stowUpdate = <T>(
|
|
20
|
-
state: Atom<T>,
|
|
21
|
-
update: StateUpdate<T>,
|
|
22
|
-
store: Store,
|
|
23
|
-
): void => {
|
|
24
|
-
const { key } = state
|
|
25
|
-
const { logger } = store.config
|
|
26
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
27
|
-
store.config.logger?.warn(
|
|
28
|
-
`stowUpdate called outside of a transaction. This is probably a bug.`,
|
|
29
|
-
)
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
store.transactionStatus.atomUpdates.push({ key, ...update })
|
|
33
|
-
logger?.info(`📝 ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const emitUpdate = <T>(
|
|
37
|
-
state: Atom<T> | ReadonlySelector<T> | Selector<T>,
|
|
38
|
-
update: StateUpdate<T>,
|
|
39
|
-
store: Store,
|
|
40
|
-
): void => {
|
|
41
|
-
const { key } = state
|
|
42
|
-
const { logger } = store.config
|
|
43
|
-
logger?.info(
|
|
44
|
-
`📢 ${state.type} "${key}" went (`,
|
|
45
|
-
update.oldValue,
|
|
46
|
-
`->`,
|
|
47
|
-
update.newValue,
|
|
48
|
-
`)`,
|
|
49
|
-
)
|
|
50
|
-
state.subject.next(update)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const subscribeToRootAtoms = <T>(
|
|
54
|
-
state: ReadonlySelector<T> | Selector<T>,
|
|
55
|
-
store: Store,
|
|
56
|
-
): { unsubscribe: () => void }[] | null => {
|
|
57
|
-
const dependencySubscriptions =
|
|
58
|
-
`default` in state
|
|
59
|
-
? null
|
|
60
|
-
: traceAllSelectorAtoms(state.key, store).map((atomToken) => {
|
|
61
|
-
const atom = withdraw(atomToken, store)
|
|
62
|
-
if (atom === null) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`,
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
return atom.subject.subscribe((atomChange) => {
|
|
68
|
-
store.config.logger?.info(
|
|
69
|
-
`📢 selector "${state.key}" saw root "${atomToken.key}" go (`,
|
|
70
|
-
atomChange.oldValue,
|
|
71
|
-
`->`,
|
|
72
|
-
atomChange.newValue,
|
|
73
|
-
`)`,
|
|
74
|
-
)
|
|
75
|
-
const oldValue = recallState(state, store)
|
|
76
|
-
const newValue = getState__INTERNAL(state, store)
|
|
77
|
-
store.config.logger?.info(
|
|
78
|
-
` <- "${state.key}" went (`,
|
|
79
|
-
oldValue,
|
|
80
|
-
`->`,
|
|
81
|
-
newValue,
|
|
82
|
-
`)`,
|
|
83
|
-
)
|
|
84
|
-
state.subject.next({ newValue, oldValue })
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
return dependencySubscriptions
|
|
88
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./add-atom-to-timeline"
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { __INTERNAL__ } from "atom.io"
|
|
2
|
-
import type { ReadonlySelectorToken, SelectorToken } from "atom.io"
|
|
3
|
-
|
|
4
|
-
import type { StateTokenIndex } from "."
|
|
5
|
-
|
|
6
|
-
export type SelectorTokenIndex = StateTokenIndex<
|
|
7
|
-
ReadonlySelectorToken<unknown> | SelectorToken<unknown>
|
|
8
|
-
>
|
|
9
|
-
|
|
10
|
-
export const attachSelectorIndex = (
|
|
11
|
-
store: __INTERNAL__.Store = __INTERNAL__.IMPLICIT.STORE,
|
|
12
|
-
): ReadonlySelectorToken<SelectorTokenIndex> => {
|
|
13
|
-
const readonlySelectorTokenIndexState__INTERNAL =
|
|
14
|
-
__INTERNAL__.atom__INTERNAL<SelectorTokenIndex>(
|
|
15
|
-
{
|
|
16
|
-
key: `👁🗨 Selector Token Index (Internal)`,
|
|
17
|
-
default: () =>
|
|
18
|
-
Object.assign(
|
|
19
|
-
[...store.readonlySelectors]
|
|
20
|
-
.filter(([key]) => !key.includes(`👁🗨`))
|
|
21
|
-
.reduce<SelectorTokenIndex>((acc, [key]) => {
|
|
22
|
-
acc[key] = { key, type: `readonly_selector` }
|
|
23
|
-
return acc
|
|
24
|
-
}, {}),
|
|
25
|
-
[...store.selectors].reduce<SelectorTokenIndex>((acc, [key]) => {
|
|
26
|
-
acc[key] = { key, type: `selector` }
|
|
27
|
-
return acc
|
|
28
|
-
}, {}),
|
|
29
|
-
),
|
|
30
|
-
effects: [
|
|
31
|
-
({ setSelf }) => {
|
|
32
|
-
store.subject.selectorCreation.subscribe((selectorToken) => {
|
|
33
|
-
if (store.operation.open) {
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
if (selectorToken.key.includes(`👁🗨`)) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
setSelf((state) => {
|
|
40
|
-
const { key, family } = selectorToken
|
|
41
|
-
if (family) {
|
|
42
|
-
const { key: familyKey, subKey } = family
|
|
43
|
-
const current = state[familyKey]
|
|
44
|
-
if (current === undefined || `familyMembers` in current) {
|
|
45
|
-
const familyKeyState = current || {
|
|
46
|
-
key: familyKey,
|
|
47
|
-
familyMembers: {},
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
...state,
|
|
51
|
-
[familyKey]: {
|
|
52
|
-
...familyKeyState,
|
|
53
|
-
familyMembers: {
|
|
54
|
-
...familyKeyState.familyMembers,
|
|
55
|
-
[subKey]: selectorToken,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
...state,
|
|
63
|
-
[key]: selectorToken,
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
undefined,
|
|
71
|
-
store,
|
|
72
|
-
)
|
|
73
|
-
return __INTERNAL__.selector__INTERNAL({
|
|
74
|
-
key: `👁🗨 Selector Token Index`,
|
|
75
|
-
get: ({ get }) => get(readonlySelectorTokenIndexState__INTERNAL),
|
|
76
|
-
})
|
|
77
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ReadonlySelectorToken, Store, TimelineToken } from "atom.io"
|
|
2
|
-
import { __INTERNAL__ } from "atom.io"
|
|
3
|
-
|
|
4
|
-
export const attachTimelineIndex = (
|
|
5
|
-
store: Store = __INTERNAL__.IMPLICIT.STORE,
|
|
6
|
-
): ReadonlySelectorToken<TimelineToken[]> => {
|
|
7
|
-
const timelineTokenIndexState__INTERNAL = __INTERNAL__.atom__INTERNAL<
|
|
8
|
-
TimelineToken[]
|
|
9
|
-
>(
|
|
10
|
-
{
|
|
11
|
-
key: `👁🗨 Timeline Token Index (Internal)`,
|
|
12
|
-
default: () =>
|
|
13
|
-
[...store.timelines].map(([key]) => {
|
|
14
|
-
return { key, type: `timeline` }
|
|
15
|
-
}),
|
|
16
|
-
effects: [
|
|
17
|
-
({ setSelf }) => {
|
|
18
|
-
store.subject.timelineCreation.subscribe((timelineToken) => {
|
|
19
|
-
setSelf((state) => [...state, timelineToken])
|
|
20
|
-
})
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
undefined,
|
|
25
|
-
store,
|
|
26
|
-
)
|
|
27
|
-
const timelineTokenIndex = __INTERNAL__.selector__INTERNAL(
|
|
28
|
-
{
|
|
29
|
-
key: `👁🗨 Timeline Token Index`,
|
|
30
|
-
get: ({ get }) => get(timelineTokenIndexState__INTERNAL),
|
|
31
|
-
},
|
|
32
|
-
undefined,
|
|
33
|
-
store,
|
|
34
|
-
)
|
|
35
|
-
return timelineTokenIndex
|
|
36
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ReadonlySelectorToken, TransactionToken } from "atom.io"
|
|
2
|
-
import { __INTERNAL__ } from "atom.io"
|
|
3
|
-
|
|
4
|
-
import type { ƒn } from "~/packages/anvl/src/function"
|
|
5
|
-
|
|
6
|
-
export const attachTransactionIndex = (
|
|
7
|
-
store: __INTERNAL__.Store = __INTERNAL__.IMPLICIT.STORE,
|
|
8
|
-
): ReadonlySelectorToken<TransactionToken<ƒn>[]> => {
|
|
9
|
-
const transactionTokenIndexState__INTERNAL = __INTERNAL__.atom__INTERNAL<
|
|
10
|
-
TransactionToken<ƒn>[]
|
|
11
|
-
>(
|
|
12
|
-
{
|
|
13
|
-
key: `👁🗨 Transaction Token Index (Internal)`,
|
|
14
|
-
default: () =>
|
|
15
|
-
[...store.transactions].map(([key]) => {
|
|
16
|
-
return { key, type: `transaction` }
|
|
17
|
-
}),
|
|
18
|
-
effects: [
|
|
19
|
-
({ setSelf }) => {
|
|
20
|
-
store.subject.transactionCreation.subscribe((transactionToken) => {
|
|
21
|
-
setSelf((state) => [...state, transactionToken])
|
|
22
|
-
})
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
undefined,
|
|
27
|
-
store,
|
|
28
|
-
)
|
|
29
|
-
const transactionTokenIndex = __INTERNAL__.selector__INTERNAL(
|
|
30
|
-
{
|
|
31
|
-
key: `👁🗨 Transaction Token Index`,
|
|
32
|
-
get: ({ get }) => get(transactionTokenIndexState__INTERNAL),
|
|
33
|
-
},
|
|
34
|
-
undefined,
|
|
35
|
-
store,
|
|
36
|
-
)
|
|
37
|
-
return transactionTokenIndex
|
|
38
|
-
}
|
package/src/json/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./select-json"
|
package/src/json/select-json.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as AtomIO from "atom.io"
|
|
2
|
-
|
|
3
|
-
import type { Json, JsonInterface } from "~/packages/anvl/src/json"
|
|
4
|
-
|
|
5
|
-
export const selectJson = <T, J extends Json.Serializable>(
|
|
6
|
-
atom: AtomIO.AtomToken<T>,
|
|
7
|
-
transform: JsonInterface<T, J>,
|
|
8
|
-
store: AtomIO.Store = AtomIO.__INTERNAL__.IMPLICIT.STORE,
|
|
9
|
-
): AtomIO.SelectorToken<J> =>
|
|
10
|
-
AtomIO.__INTERNAL__.selector__INTERNAL(
|
|
11
|
-
{
|
|
12
|
-
key: `${atom.key}JSON`,
|
|
13
|
-
get: ({ get }) => transform.toJson(get(atom)),
|
|
14
|
-
set: ({ set }, newValue) => set(atom, transform.fromJson(newValue)),
|
|
15
|
-
},
|
|
16
|
-
undefined,
|
|
17
|
-
store,
|
|
18
|
-
)
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as AtomIO from "atom.io"
|
|
2
|
-
import * as React from "react"
|
|
3
|
-
|
|
4
|
-
export const StoreContext = React.createContext<AtomIO.Store>(
|
|
5
|
-
AtomIO.__INTERNAL__.IMPLICIT.STORE,
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
export const StoreProvider: React.FC<{
|
|
9
|
-
children: React.ReactNode
|
|
10
|
-
store?: AtomIO.Store
|
|
11
|
-
}> = ({ children, store = AtomIO.__INTERNAL__.IMPLICIT.STORE }) => (
|
|
12
|
-
<StoreContext.Provider value={store}>{children}</StoreContext.Provider>
|
|
13
|
-
)
|
package/src/react/store-hooks.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as AtomIO from "atom.io"
|
|
2
|
-
import * as React from "react"
|
|
3
|
-
|
|
4
|
-
import type { Modifier } from "~/packages/anvl/src/function"
|
|
5
|
-
|
|
6
|
-
import { StoreContext } from "./store-context"
|
|
7
|
-
|
|
8
|
-
export type StoreHooks = {
|
|
9
|
-
useI: <T>(token: AtomIO.StateToken<T>) => (next: Modifier<T> | T) => void
|
|
10
|
-
useO: <T>(token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>) => T
|
|
11
|
-
useIO: <T>(token: AtomIO.StateToken<T>) => [T, (next: Modifier<T> | T) => void]
|
|
12
|
-
}
|
|
13
|
-
export const storeHooks: StoreHooks = { useI, useO, useIO }
|
|
14
|
-
|
|
15
|
-
export function useI<T>(
|
|
16
|
-
token: AtomIO.StateToken<T>,
|
|
17
|
-
): (next: Modifier<T> | T) => void {
|
|
18
|
-
const store = React.useContext(StoreContext)
|
|
19
|
-
const update = (next: Modifier<T> | T) => AtomIO.setState(token, next, store)
|
|
20
|
-
return update
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function useO<T>(
|
|
24
|
-
token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>,
|
|
25
|
-
): T {
|
|
26
|
-
const store = React.useContext(StoreContext)
|
|
27
|
-
return React.useSyncExternalStore<T>(
|
|
28
|
-
(observe) => AtomIO.subscribe(token, observe, store),
|
|
29
|
-
() => AtomIO.getState(token, store),
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function useIO<T>(
|
|
34
|
-
token: AtomIO.StateToken<T>,
|
|
35
|
-
): [T, (next: Modifier<T> | T) => void] {
|
|
36
|
-
return [useO(token), useI(token)]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function useStore<T>(
|
|
40
|
-
token: AtomIO.StateToken<T>,
|
|
41
|
-
): [T, (next: Modifier<T> | T) => void]
|
|
42
|
-
export function useStore<T>(token: AtomIO.ReadonlySelectorToken<T>): T
|
|
43
|
-
export function useStore<T>(
|
|
44
|
-
token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>,
|
|
45
|
-
): T | [T, (next: Modifier<T> | T) => void] {
|
|
46
|
-
return token.type === `readonly_selector` ? useO(token) : useIO(token)
|
|
47
|
-
}
|