atom.io 0.6.2 → 0.6.4
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 +27 -15
- package/dist/index.d.ts +27 -15
- package/dist/index.js +44 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -24
- 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/json/package.json +13 -13
- package/package.json +31 -12
- package/react/dist/index.d.mts +24 -0
- package/react/dist/index.d.ts +24 -0
- package/react/dist/index.js +87 -0
- package/react/dist/index.js.map +1 -0
- package/react/dist/index.mjs +45 -0
- package/react/dist/index.mjs.map +1 -0
- package/react/package.json +13 -13
- 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 +2108 -0
- package/react-devtools/dist/index.js.map +1 -0
- package/react-devtools/dist/index.mjs +2080 -0
- package/react-devtools/dist/index.mjs.map +1 -0
- package/react-devtools/package.json +13 -13
- 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/package.json +13 -13
- package/realtime-react/dist/index.d.mts +45 -0
- package/realtime-react/dist/index.d.ts +45 -0
- package/realtime-react/dist/index.js +217 -0
- package/realtime-react/dist/index.js.map +1 -0
- package/realtime-react/dist/index.mjs +172 -0
- package/realtime-react/dist/index.mjs.map +1 -0
- package/realtime-react/package.json +13 -13
- package/realtime-testing/dist/index.d.mts +49 -0
- package/realtime-testing/dist/index.d.ts +49 -0
- package/realtime-testing/dist/index.js +165 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +129 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/realtime-testing/package.json +15 -0
- package/src/atom.ts +16 -17
- package/src/index.ts +59 -59
- package/src/internal/atom-internal.ts +37 -37
- package/src/internal/families-internal.ts +115 -116
- package/src/internal/get.ts +83 -83
- package/src/internal/index.ts +1 -0
- 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 +47 -47
- package/src/internal/selector/create-readonly-selector.ts +38 -38
- 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 +38 -39
- package/src/internal/set.ts +78 -78
- package/src/internal/store.ts +119 -119
- package/src/internal/subject.ts +24 -0
- 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 +81 -82
- 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 +49 -49
- package/src/json/select-json.ts +12 -12
- package/src/logger.ts +30 -30
- package/src/react/store-context.tsx +5 -6
- package/src/react/store-hooks.ts +19 -20
- package/src/react-devtools/AtomIODevtools.tsx +85 -85
- package/src/react-devtools/StateEditor.tsx +54 -55
- package/src/react-devtools/TokenList.tsx +49 -45
- package/src/react-explorer/AtomIOExplorer.tsx +198 -187
- 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 +18 -19
- 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 +16 -17
- package/src/realtime-react/use-pull-family.ts +14 -15
- package/src/realtime-react/use-pull.ts +13 -14
- package/src/realtime-react/use-push.ts +16 -17
- package/src/realtime-react/use-server-action.ts +22 -23
- package/src/realtime-testing/index.ts +1 -0
- package/src/realtime-testing/setup-realtime-test.tsx +159 -0
- package/src/selector.ts +26 -27
- 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
|
@@ -1,106 +1,105 @@
|
|
|
1
1
|
import HAMT from "hamt_plus"
|
|
2
|
-
import * as Rx from "rxjs"
|
|
3
2
|
|
|
4
3
|
import type { ƒn } from "~/packages/anvl/src/function"
|
|
5
4
|
|
|
6
5
|
import type { Store } from "."
|
|
7
|
-
import { target, IMPLICIT } from "."
|
|
6
|
+
import { Subject, target, IMPLICIT } from "."
|
|
8
7
|
import { addAtomToTimeline } from "./timeline/add-atom-to-timeline"
|
|
9
8
|
import type {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
StateUpdate,
|
|
10
|
+
TimelineOptions,
|
|
11
|
+
TimelineToken,
|
|
12
|
+
TimelineUpdate,
|
|
13
|
+
TransactionUpdate,
|
|
15
14
|
} from ".."
|
|
16
15
|
|
|
17
16
|
export type TimelineAtomUpdate = StateUpdate<unknown> & {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
key: string
|
|
18
|
+
type: `atom_update`
|
|
19
|
+
timestamp: number
|
|
21
20
|
}
|
|
22
21
|
export type TimelineSelectorUpdate = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
key: string
|
|
23
|
+
type: `selector_update`
|
|
24
|
+
timestamp: number
|
|
25
|
+
atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[]
|
|
27
26
|
}
|
|
28
27
|
export type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
key: string
|
|
29
|
+
type: `transaction_update`
|
|
30
|
+
timestamp: number
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export type Timeline = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
key: string
|
|
35
|
+
at: number
|
|
36
|
+
timeTraveling: boolean
|
|
37
|
+
history: TimelineUpdate[]
|
|
38
|
+
selectorTime: number | null
|
|
39
|
+
transactionKey: string | null
|
|
40
|
+
install: (store: Store) => void
|
|
41
|
+
subject: Subject<
|
|
42
|
+
TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate
|
|
43
|
+
>
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
export function timeline__INTERNAL(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
options: TimelineOptions,
|
|
48
|
+
store: Store = IMPLICIT.STORE,
|
|
49
|
+
data: Timeline | null = null,
|
|
51
50
|
): TimelineToken {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
const tl: Timeline = {
|
|
52
|
+
key: options.key,
|
|
53
|
+
at: 0,
|
|
54
|
+
timeTraveling: false,
|
|
55
|
+
selectorTime: null,
|
|
56
|
+
transactionKey: null,
|
|
57
|
+
...data,
|
|
58
|
+
history: data?.history.map((update) => ({ ...update })) ?? [],
|
|
59
|
+
install: (store) => timeline__INTERNAL(options, store, tl),
|
|
60
|
+
subject: new Subject(),
|
|
61
|
+
}
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
63
|
+
const core = target(store)
|
|
64
|
+
for (const tokenOrFamily of options.atoms) {
|
|
65
|
+
const timelineKey = core.timelineAtoms.getRelatedId(tokenOrFamily.key)
|
|
66
|
+
if (timelineKey) {
|
|
67
|
+
store.config.logger?.error(
|
|
68
|
+
`❌ Failed to add atom "${tokenOrFamily.key}" to timeline "${options.key}" because it belongs to timeline "${timelineKey}"`,
|
|
69
|
+
)
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
if (tokenOrFamily.type === `atom_family`) {
|
|
73
|
+
const family = tokenOrFamily
|
|
74
|
+
family.subject.subscribe((token) =>
|
|
75
|
+
addAtomToTimeline(token, options.atoms, tl, store),
|
|
76
|
+
)
|
|
77
|
+
} else {
|
|
78
|
+
const token = tokenOrFamily
|
|
79
|
+
if (`family` in token && token.family) {
|
|
80
|
+
const familyTimelineKey = core.timelineAtoms.getRelatedId(
|
|
81
|
+
token.family.key,
|
|
82
|
+
)
|
|
83
|
+
if (familyTimelineKey) {
|
|
84
|
+
store.config.logger?.error(
|
|
85
|
+
`❌ Failed to add atom "${token.key}" to timeline "${options.key}" because its family "${token.family.key}" belongs to timeline "${familyTimelineKey}"`,
|
|
86
|
+
)
|
|
87
|
+
continue
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
addAtomToTimeline(token, options.atoms, tl, store)
|
|
91
|
+
}
|
|
92
|
+
core.timelineAtoms = core.timelineAtoms.set({
|
|
93
|
+
atomKey: tokenOrFamily.key,
|
|
94
|
+
timelineKey: options.key,
|
|
95
|
+
})
|
|
96
|
+
}
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
store.timelines = HAMT.set(options.key, tl, store.timelines)
|
|
99
|
+
const token: TimelineToken = {
|
|
100
|
+
key: options.key,
|
|
101
|
+
type: `timeline`,
|
|
102
|
+
}
|
|
103
|
+
store.subject.timelineCreation.next(token)
|
|
104
|
+
return token
|
|
106
105
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Store } from ".."
|
|
2
2
|
|
|
3
3
|
export const abortTransaction = (store: Store): void => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
if (store.transactionStatus.phase === `idle`) {
|
|
5
|
+
store.config.logger?.warn(
|
|
6
|
+
`abortTransaction called outside of a transaction. This is probably a bug.`,
|
|
7
|
+
)
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
store.transactionStatus = { phase: `idle` }
|
|
11
|
+
store.config.logger?.info(`🪂`, `transaction fail`)
|
|
12
12
|
}
|
|
@@ -8,47 +8,47 @@ import type { AtomToken } from "../.."
|
|
|
8
8
|
import { setState } from "../.."
|
|
9
9
|
|
|
10
10
|
export const applyTransaction = <ƒ extends ƒn>(
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
output: ReturnType<ƒ>,
|
|
12
|
+
store: Store,
|
|
13
13
|
): void => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
if (store.transactionStatus.phase !== `building`) {
|
|
15
|
+
store.config.logger?.warn(
|
|
16
|
+
`abortTransaction called outside of a transaction. This is probably a bug.`,
|
|
17
|
+
)
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
store.config.logger?.info(
|
|
21
|
+
`🛃 apply transaction "${store.transactionStatus.key}"`,
|
|
22
|
+
)
|
|
23
|
+
store.transactionStatus.phase = `applying`
|
|
24
|
+
store.transactionStatus.output = output
|
|
25
|
+
const { atomUpdates } = store.transactionStatus
|
|
26
26
|
|
|
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
|
-
|
|
27
|
+
for (const { key, newValue } of atomUpdates) {
|
|
28
|
+
const token: AtomToken<unknown> = { key, type: `atom` }
|
|
29
|
+
if (!HAMT.has(token.key, store.valueMap)) {
|
|
30
|
+
const newAtom = HAMT.get(token.key, store.transactionStatus.core.atoms)
|
|
31
|
+
store.atoms = HAMT.set(newAtom.key, newAtom, store.atoms)
|
|
32
|
+
store.valueMap = HAMT.set(newAtom.key, newAtom.default, store.valueMap)
|
|
33
|
+
store.config.logger?.info(`🔧`, `add atom "${newAtom.key}"`)
|
|
34
|
+
}
|
|
35
|
+
setState(token, newValue, store)
|
|
36
|
+
}
|
|
37
|
+
const myTransaction = withdraw<ƒ>(
|
|
38
|
+
{ key: store.transactionStatus.key, type: `transaction` },
|
|
39
|
+
store,
|
|
40
|
+
)
|
|
41
|
+
if (myTransaction === null) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
myTransaction.subject.next({
|
|
47
|
+
key: store.transactionStatus.key,
|
|
48
|
+
atomUpdates,
|
|
49
|
+
output,
|
|
50
|
+
params: store.transactionStatus.params as Parameters<ƒ>,
|
|
51
|
+
})
|
|
52
|
+
store.transactionStatus = { phase: `idle` }
|
|
53
|
+
store.config.logger?.info(`🛬`, `transaction done`)
|
|
54
54
|
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import type { Store } from ".."
|
|
2
2
|
|
|
3
3
|
export const buildTransaction = (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
key: string,
|
|
5
|
+
params: any[],
|
|
6
|
+
store: Store,
|
|
7
7
|
): void => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
store.transactionStatus = {
|
|
9
|
+
key,
|
|
10
|
+
phase: `building`,
|
|
11
|
+
time: Date.now(),
|
|
12
|
+
core: {
|
|
13
|
+
atoms: store.atoms,
|
|
14
|
+
atomsThatAreDefault: store.atomsThatAreDefault,
|
|
15
|
+
operation: { open: false },
|
|
16
|
+
readonlySelectors: store.readonlySelectors,
|
|
17
|
+
timelines: store.timelines,
|
|
18
|
+
timelineAtoms: store.timelineAtoms,
|
|
19
|
+
transactions: store.transactions,
|
|
20
|
+
selectorAtoms: store.selectorAtoms,
|
|
21
|
+
selectorGraph: store.selectorGraph,
|
|
22
|
+
selectors: store.selectors,
|
|
23
|
+
valueMap: store.valueMap,
|
|
24
|
+
},
|
|
25
|
+
atomUpdates: [],
|
|
26
|
+
params,
|
|
27
|
+
output: undefined,
|
|
28
|
+
}
|
|
29
|
+
store.config.logger?.info(
|
|
30
|
+
`🛫`,
|
|
31
|
+
`transaction "${key}" started in store "${store.config.name}"`,
|
|
32
|
+
)
|
|
33
33
|
}
|
|
@@ -10,16 +10,16 @@ export * from "./redo-transaction"
|
|
|
10
10
|
export * from "./undo-transaction"
|
|
11
11
|
|
|
12
12
|
export const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const
|
|
13
|
-
export type TransactionPhase =
|
|
13
|
+
export type TransactionPhase = typeof TRANSACTION_PHASES[number]
|
|
14
14
|
|
|
15
15
|
export type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
phase: `applying` | `building`
|
|
17
|
+
time: number
|
|
18
|
+
core: StoreCore
|
|
19
19
|
}
|
|
20
20
|
export type TransactionIdle = {
|
|
21
|
-
|
|
21
|
+
phase: `idle`
|
|
22
22
|
}
|
|
23
23
|
export type TransactionStatus<ƒ extends ƒn> =
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
| TransactionIdle
|
|
25
|
+
| TransactionUpdateInProgress<ƒ>
|
|
@@ -6,18 +6,18 @@ import type { AtomToken, TransactionUpdate } from "../.."
|
|
|
6
6
|
import { setState } from "../.."
|
|
7
7
|
|
|
8
8
|
export const redoTransactionUpdate = <ƒ extends ƒn>(
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
update: TransactionUpdate<ƒ>,
|
|
10
|
+
store: Store,
|
|
11
11
|
): void => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
store.config.logger?.info(` ⏭ redo transaction "${update.key}" (redo)`)
|
|
13
|
+
for (const { key, newValue } of update.atomUpdates) {
|
|
14
|
+
const token: AtomToken<unknown> = { key, type: `atom` }
|
|
15
|
+
const state = withdraw(token, store)
|
|
16
|
+
if (state === null) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
setState(state, newValue, store)
|
|
22
|
+
}
|
|
23
23
|
}
|
|
@@ -6,18 +6,18 @@ import type { AtomToken, TransactionUpdate } from "../.."
|
|
|
6
6
|
import { setState } from "../.."
|
|
7
7
|
|
|
8
8
|
export const undoTransactionUpdate = <ƒ extends ƒn>(
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
update: TransactionUpdate<ƒ>,
|
|
10
|
+
store: Store,
|
|
11
11
|
): void => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
store.config.logger?.info(` ⏮ undo transaction "${update.key}" (undo)`)
|
|
13
|
+
for (const { key, oldValue } of update.atomUpdates) {
|
|
14
|
+
const token: AtomToken<unknown> = { key, type: `atom` }
|
|
15
|
+
const state = withdraw(token, store)
|
|
16
|
+
if (state === null) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
setState(state, oldValue, store)
|
|
22
|
+
}
|
|
23
23
|
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
import HAMT from "hamt_plus"
|
|
2
|
-
import * as Rx from "rxjs"
|
|
3
2
|
|
|
4
3
|
import type { ƒn } from "~/packages/anvl/src/function"
|
|
5
4
|
|
|
6
5
|
import type { Store, StoreCore } from "."
|
|
7
6
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
Subject,
|
|
8
|
+
abortTransaction,
|
|
9
|
+
applyTransaction,
|
|
10
|
+
buildTransaction,
|
|
11
|
+
deposit,
|
|
12
|
+
IMPLICIT,
|
|
13
13
|
} from "."
|
|
14
14
|
import type { TransactionOptions, TransactionToken, TransactionUpdate } from ".."
|
|
15
15
|
import { getState, setState } from ".."
|
|
16
16
|
|
|
17
17
|
export type Transaction<ƒ extends ƒn> = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
key: string
|
|
19
|
+
type: `transaction`
|
|
20
|
+
install: (store: Store) => void
|
|
21
|
+
subject: Subject<TransactionUpdate<ƒ>>
|
|
22
|
+
run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function transaction__INTERNAL<ƒ extends ƒn>(
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
options: TransactionOptions<ƒ>,
|
|
27
|
+
store: Store = IMPLICIT.STORE,
|
|
28
28
|
): TransactionToken<ƒ> {
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
29
|
+
const newTransaction: Transaction<ƒ> = {
|
|
30
|
+
key: options.key,
|
|
31
|
+
type: `transaction`,
|
|
32
|
+
run: (...params: Parameters<ƒ>) => {
|
|
33
|
+
buildTransaction(options.key, params, store)
|
|
34
|
+
try {
|
|
35
|
+
const output = options.do(
|
|
36
|
+
{
|
|
37
|
+
get: (token) => getState(token, store),
|
|
38
|
+
set: (token, value) => setState(token, value, store),
|
|
39
|
+
},
|
|
40
|
+
...params,
|
|
41
|
+
)
|
|
42
|
+
applyTransaction(output, store)
|
|
43
|
+
return output
|
|
44
|
+
} catch (thrown) {
|
|
45
|
+
abortTransaction(store)
|
|
46
|
+
store.config.logger?.error(`Transaction ${options.key} failed`, thrown)
|
|
47
|
+
throw thrown
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
install: (store) => transaction__INTERNAL(options, store),
|
|
51
|
+
subject: new Subject(),
|
|
52
|
+
}
|
|
53
|
+
const core = target(store)
|
|
54
|
+
core.transactions = HAMT.set(
|
|
55
|
+
newTransaction.key,
|
|
56
|
+
newTransaction,
|
|
57
|
+
core.transactions,
|
|
58
|
+
)
|
|
59
|
+
const token = deposit(newTransaction)
|
|
60
|
+
store.subject.transactionCreation.next(token)
|
|
61
|
+
return token
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export const target = (store: Store = IMPLICIT.STORE): StoreCore =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
store.transactionStatus.phase === `building`
|
|
66
|
+
? store.transactionStatus.core
|
|
67
|
+
: store
|
package/src/json/select-json.ts
CHANGED
|
@@ -3,16 +3,16 @@ import * as AtomIO from "atom.io"
|
|
|
3
3
|
import type { Json, JsonInterface } from "~/packages/anvl/src/json"
|
|
4
4
|
|
|
5
5
|
export const selectJson = <T, J extends Json>(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
atom: AtomIO.AtomToken<T>,
|
|
7
|
+
transform: JsonInterface<T, J>,
|
|
8
|
+
store: AtomIO.Store = AtomIO.__INTERNAL__.IMPLICIT.STORE,
|
|
9
9
|
): AtomIO.SelectorToken<J> =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
)
|