atom.io 0.6.1 → 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 +3 -3
- package/dist/index.d.ts +3 -3
- 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.js.map +1 -1
- package/json/dist/index.mjs.map +1 -1
- package/package.json +13 -3
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs.map +1 -1
- package/react-devtools/dist/index.js +32 -18
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +32 -18
- package/react-devtools/dist/index.mjs.map +1 -1
- package/realtime/dist/index.js.map +1 -1
- package/realtime/dist/index.mjs.map +1 -1
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs.map +1 -1
- 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
|
@@ -4,30 +4,30 @@ import { target } from ".."
|
|
|
4
4
|
import type { ReadonlySelectorToken, StateToken } from "../.."
|
|
5
5
|
|
|
6
6
|
export const updateSelectorAtoms = (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
selectorKey: string,
|
|
8
|
+
dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>,
|
|
9
|
+
store: Store,
|
|
10
10
|
): void => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
33
|
}
|
|
@@ -6,56 +6,56 @@ import { target, IMPLICIT } from "."
|
|
|
6
6
|
import { createReadWriteSelector } from "./selector/create-read-write-selector"
|
|
7
7
|
import { createReadonlySelector } from "./selector/create-readonly-selector"
|
|
8
8
|
import type {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
FamilyMetadata,
|
|
10
|
+
ReadonlySelectorOptions,
|
|
11
|
+
ReadonlySelectorToken,
|
|
12
|
+
SelectorOptions,
|
|
13
|
+
SelectorToken,
|
|
14
14
|
} from ".."
|
|
15
15
|
|
|
16
16
|
export type Selector<T> = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
key: string
|
|
18
|
+
type: `selector`
|
|
19
|
+
family?: FamilyMetadata
|
|
20
|
+
install: (store: Store) => void
|
|
21
|
+
subject: Rx.Subject<{ newValue: T; oldValue: T }>
|
|
22
|
+
get: () => T
|
|
23
|
+
set: (newValue: T | ((oldValue: T) => T)) => void
|
|
24
24
|
}
|
|
25
25
|
export type ReadonlySelector<T> = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
key: string
|
|
27
|
+
type: `readonly_selector`
|
|
28
|
+
family?: FamilyMetadata
|
|
29
|
+
install: (store: Store) => void
|
|
30
|
+
subject: Rx.Subject<{ newValue: T; oldValue: T }>
|
|
31
|
+
get: () => T
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function selector__INTERNAL<T>(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
options: SelectorOptions<T>,
|
|
36
|
+
family?: FamilyMetadata,
|
|
37
|
+
store?: Store,
|
|
38
38
|
): SelectorToken<T>
|
|
39
39
|
export function selector__INTERNAL<T>(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
options: ReadonlySelectorOptions<T>,
|
|
41
|
+
family?: FamilyMetadata,
|
|
42
|
+
store?: Store,
|
|
43
43
|
): ReadonlySelectorToken<T>
|
|
44
44
|
export function selector__INTERNAL<T>(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
options: ReadonlySelectorOptions<T> | SelectorOptions<T>,
|
|
46
|
+
family?: FamilyMetadata,
|
|
47
|
+
store: Store = IMPLICIT.STORE,
|
|
48
48
|
): ReadonlySelectorToken<T> | SelectorToken<T> {
|
|
49
|
-
|
|
49
|
+
const core = target(store)
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
if (HAMT.has(options.key, core.selectors)) {
|
|
52
|
+
store.config.logger?.error(
|
|
53
|
+
`Key "${options.key}" already exists in the store.`,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
if (!(`set` in options)) {
|
|
58
|
+
return createReadonlySelector(options, family, store, core)
|
|
59
|
+
}
|
|
60
|
+
return createReadWriteSelector(options, family, store, core)
|
|
61
61
|
}
|
package/src/internal/set.ts
CHANGED
|
@@ -4,99 +4,99 @@ import { become } from "~/packages/anvl/src/function"
|
|
|
4
4
|
|
|
5
5
|
import type { Atom, Selector, Store } from "."
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
IMPLICIT,
|
|
8
|
+
cacheValue,
|
|
9
|
+
emitUpdate,
|
|
10
|
+
evictCachedValue,
|
|
11
|
+
getState__INTERNAL,
|
|
12
|
+
isAtomDefault,
|
|
13
|
+
isDone,
|
|
14
|
+
markAtomAsNotDefault,
|
|
15
|
+
markDone,
|
|
16
|
+
stowUpdate,
|
|
17
|
+
target,
|
|
18
18
|
} from "."
|
|
19
19
|
|
|
20
20
|
export const evictDownStream = <T>(
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
state: Atom<T>,
|
|
22
|
+
store: Store = IMPLICIT.STORE,
|
|
23
23
|
): void => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
24
|
+
const core = target(store)
|
|
25
|
+
const downstream = core.selectorAtoms.getRelations(state.key)
|
|
26
|
+
const downstreamKeys = downstream.map(({ id }) => id)
|
|
27
|
+
store.config.logger?.info(
|
|
28
|
+
` || ${downstreamKeys.length} downstream:`,
|
|
29
|
+
downstreamKeys,
|
|
30
|
+
)
|
|
31
|
+
if (core.operation.open) {
|
|
32
|
+
store.config.logger?.info(` ||`, [...core.operation.done], `already done`)
|
|
33
|
+
}
|
|
34
|
+
downstream.forEach(({ id: stateKey }) => {
|
|
35
|
+
if (isDone(stateKey, store)) {
|
|
36
|
+
store.config.logger?.info(` || ${stateKey} already done`)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
const state =
|
|
40
|
+
HAMT.get(stateKey, core.selectors) ??
|
|
41
|
+
HAMT.get(stateKey, core.readonlySelectors)
|
|
42
|
+
if (!state) {
|
|
43
|
+
store.config.logger?.info(
|
|
44
|
+
` || ${stateKey} is an atom, and can't be downstream`,
|
|
45
|
+
)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
evictCachedValue(stateKey, store)
|
|
49
|
+
store.config.logger?.info(` xx evicted "${stateKey}"`)
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
markDone(stateKey, store)
|
|
52
|
+
})
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export const setAtomState = <T>(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
atom: Atom<T>,
|
|
57
|
+
next: T | ((oldValue: T) => T),
|
|
58
|
+
store: Store = IMPLICIT.STORE,
|
|
59
59
|
): void => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
const oldValue = getState__INTERNAL(atom, store)
|
|
61
|
+
const newValue = become(next)(oldValue)
|
|
62
|
+
store.config.logger?.info(`<< setting atom "${atom.key}" to`, newValue)
|
|
63
|
+
cacheValue(atom.key, newValue, store)
|
|
64
|
+
if (isAtomDefault(atom.key, store)) {
|
|
65
|
+
markAtomAsNotDefault(atom.key, store)
|
|
66
|
+
}
|
|
67
|
+
markDone(atom.key, store)
|
|
68
|
+
store.config.logger?.info(
|
|
69
|
+
` || evicting caches downstream from "${atom.key}"`,
|
|
70
|
+
)
|
|
71
|
+
evictDownStream(atom, store)
|
|
72
|
+
const update = { oldValue, newValue }
|
|
73
|
+
if (store.transactionStatus.phase !== `building`) {
|
|
74
|
+
emitUpdate(atom, update, store)
|
|
75
|
+
} else {
|
|
76
|
+
stowUpdate(atom, update, store)
|
|
77
|
+
}
|
|
78
78
|
}
|
|
79
79
|
export const setSelectorState = <T>(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
selector: Selector<T>,
|
|
81
|
+
next: T | ((oldValue: T) => T),
|
|
82
|
+
store: Store = IMPLICIT.STORE,
|
|
83
83
|
): void => {
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const oldValue = getState__INTERNAL(selector, store)
|
|
85
|
+
const newValue = become(next)(oldValue)
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
store.config.logger?.info(`<< setting selector "${selector.key}" to`, newValue)
|
|
88
|
+
store.config.logger?.info(` || propagating change made to "${selector.key}"`)
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
selector.set(newValue)
|
|
91
91
|
}
|
|
92
92
|
export const setState__INTERNAL = <T>(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
state: Atom<T> | Selector<T>,
|
|
94
|
+
value: T | ((oldValue: T) => T),
|
|
95
|
+
store: Store = IMPLICIT.STORE,
|
|
96
96
|
): void => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
if (`set` in state) {
|
|
98
|
+
setSelectorState(state, value, store)
|
|
99
|
+
} else {
|
|
100
|
+
setAtomState(state, value, store)
|
|
101
|
+
}
|
|
102
102
|
}
|
package/src/internal/store.ts
CHANGED
|
@@ -7,147 +7,147 @@ import { doNothing } from "~/packages/anvl/src/function"
|
|
|
7
7
|
import { Join } from "~/packages/anvl/src/join"
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
Atom,
|
|
11
|
+
OperationProgress,
|
|
12
|
+
ReadonlySelector,
|
|
13
|
+
Selector,
|
|
14
|
+
TransactionStatus,
|
|
15
|
+
Timeline,
|
|
16
|
+
Transaction,
|
|
17
17
|
} from "."
|
|
18
18
|
import type {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
AtomToken,
|
|
20
|
+
Logger,
|
|
21
|
+
ReadonlySelectorToken,
|
|
22
|
+
SelectorToken,
|
|
23
|
+
TimelineToken,
|
|
24
|
+
TransactionToken,
|
|
25
25
|
} from ".."
|
|
26
26
|
|
|
27
27
|
export type StoreCore = Pick<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
Store,
|
|
29
|
+
| `atoms`
|
|
30
|
+
| `atomsThatAreDefault`
|
|
31
|
+
| `operation`
|
|
32
|
+
| `readonlySelectors`
|
|
33
|
+
| `selectorAtoms`
|
|
34
|
+
| `selectorGraph`
|
|
35
|
+
| `selectors`
|
|
36
|
+
| `timelineAtoms`
|
|
37
|
+
| `timelines`
|
|
38
|
+
| `transactions`
|
|
39
|
+
| `valueMap`
|
|
40
40
|
>
|
|
41
41
|
|
|
42
42
|
export interface Store {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
atoms: Hamt<Atom<any>, string>
|
|
44
|
+
atomsThatAreDefault: Set<string>
|
|
45
|
+
readonlySelectors: Hamt<ReadonlySelector<any>, string>
|
|
46
|
+
selectorAtoms: Join<null, `selectorKey`, `atomKey`>
|
|
47
|
+
selectorGraph: Join<{ source: string }>
|
|
48
|
+
selectors: Hamt<Selector<any>, string>
|
|
49
|
+
timelineAtoms: Join<null, `timelineKey`, `atomKey`>
|
|
50
|
+
timelines: Hamt<Timeline, string>
|
|
51
|
+
transactions: Hamt<Transaction<any>, string>
|
|
52
|
+
valueMap: Hamt<any, string>
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
subject: {
|
|
55
|
+
atomCreation: Rx.Subject<AtomToken<unknown>>
|
|
56
|
+
selectorCreation: Rx.Subject<
|
|
57
|
+
ReadonlySelectorToken<unknown> | SelectorToken<unknown>
|
|
58
|
+
>
|
|
59
|
+
transactionCreation: Rx.Subject<TransactionToken<unknown>>
|
|
60
|
+
timelineCreation: Rx.Subject<TimelineToken>
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
operation: OperationProgress
|
|
64
|
+
transactionStatus: TransactionStatus<ƒn>
|
|
65
|
+
config: {
|
|
66
|
+
name: string
|
|
67
|
+
logger: Logger | null
|
|
68
|
+
logger__INTERNAL: Logger
|
|
69
|
+
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export const createStore = (name: string, store: Store | null = null): Store => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
const copiedStore = {
|
|
74
|
+
...(store ??
|
|
75
|
+
(() => ({
|
|
76
|
+
atomsThatAreDefault: new Set(),
|
|
77
|
+
selectorAtoms: new Join({ relationType: `n:n` })
|
|
78
|
+
.from(`selectorKey`)
|
|
79
|
+
.to(`atomKey`),
|
|
80
|
+
selectorGraph: new Join({ relationType: `n:n` }),
|
|
81
|
+
valueMap: HAMT.make<any, string>(),
|
|
82
|
+
}))()),
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
atoms: HAMT.make<Atom<any>, string>(),
|
|
85
|
+
readonlySelectors: HAMT.make<ReadonlySelector<any>, string>(),
|
|
86
|
+
selectors: HAMT.make<Selector<any>, string>(),
|
|
87
|
+
transactions: HAMT.make<Transaction<any>, string>(),
|
|
88
|
+
timelines: HAMT.make<Timeline, string>(),
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
timelineAtoms: new Join({ relationType: `1:n` })
|
|
91
|
+
.from(`timelineKey`)
|
|
92
|
+
.to(`atomKey`),
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
subject: {
|
|
95
|
+
atomCreation: new Rx.Subject(),
|
|
96
|
+
selectorCreation: new Rx.Subject(),
|
|
97
|
+
transactionCreation: new Rx.Subject(),
|
|
98
|
+
timelineCreation: new Rx.Subject(),
|
|
99
|
+
...store?.subject,
|
|
100
|
+
},
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
102
|
+
operation: {
|
|
103
|
+
open: false,
|
|
104
|
+
...store?.operation,
|
|
105
|
+
},
|
|
106
|
+
transactionStatus: {
|
|
107
|
+
phase: `idle`,
|
|
108
|
+
...store?.transactionStatus,
|
|
109
|
+
},
|
|
110
|
+
config: {
|
|
111
|
+
logger: {
|
|
112
|
+
...console,
|
|
113
|
+
info: doNothing,
|
|
114
|
+
...store?.config?.logger,
|
|
115
|
+
},
|
|
116
|
+
logger__INTERNAL: console,
|
|
117
|
+
...store?.config,
|
|
118
|
+
name,
|
|
119
|
+
},
|
|
120
|
+
} satisfies Store
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
122
|
+
store?.atoms.forEach((atom) => {
|
|
123
|
+
const copiedAtom = { ...atom, subject: new Rx.Subject() } satisfies Atom<any>
|
|
124
|
+
copiedStore.atoms = HAMT.set(atom.key, copiedAtom, copiedStore.atoms)
|
|
125
|
+
})
|
|
126
|
+
store?.readonlySelectors.forEach((selector) => {
|
|
127
|
+
selector.install(copiedStore)
|
|
128
|
+
})
|
|
129
|
+
store?.selectors.forEach((selector) => {
|
|
130
|
+
selector.install(copiedStore)
|
|
131
|
+
})
|
|
132
|
+
store?.transactions.forEach((tx) => {
|
|
133
|
+
tx.install(copiedStore)
|
|
134
|
+
})
|
|
135
|
+
store?.timelines.forEach((timeline) => {
|
|
136
|
+
timeline.install(copiedStore)
|
|
137
|
+
})
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
return copiedStore
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export const IMPLICIT = {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
STORE_INTERNAL: undefined as Store | undefined,
|
|
144
|
+
get STORE(): Store {
|
|
145
|
+
return this.STORE_INTERNAL ?? (this.STORE_INTERNAL = createStore(`DEFAULT`))
|
|
146
|
+
},
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
export const clearStore = (store: Store = IMPLICIT.STORE): void => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
const { config } = store
|
|
151
|
+
Object.assign(store, createStore(config.name))
|
|
152
|
+
store.config = config
|
|
153
153
|
}
|