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
package/src/transaction.ts
CHANGED
|
@@ -5,56 +5,56 @@ import type { Store } from "./internal"
|
|
|
5
5
|
import { IMPLICIT, transaction__INTERNAL, withdraw } from "./internal"
|
|
6
6
|
|
|
7
7
|
export type TransactionToken<_> = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
key: string
|
|
9
|
+
type: `transaction`
|
|
10
|
+
__brand?: _
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type TransactionUpdate<ƒ extends ƒn> = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
key: string
|
|
15
|
+
atomUpdates: KeyedStateUpdate<unknown>[]
|
|
16
|
+
params: Parameters<ƒ>
|
|
17
|
+
output: ReturnType<ƒ>
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type Transactors = {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
get: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S
|
|
22
|
+
set: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void
|
|
23
23
|
}
|
|
24
24
|
export type ReadonlyTransactors = Pick<Transactors, `get`>
|
|
25
25
|
|
|
26
26
|
export type Read<ƒ extends ƒn> = (
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
transactors: ReadonlyTransactors,
|
|
28
|
+
...parameters: Parameters<ƒ>
|
|
29
29
|
) => ReturnType<ƒ>
|
|
30
30
|
|
|
31
31
|
export type Write<ƒ extends ƒn> = (
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
transactors: Transactors,
|
|
33
|
+
...parameters: Parameters<ƒ>
|
|
34
34
|
) => ReturnType<ƒ>
|
|
35
35
|
|
|
36
36
|
export type TransactionOptions<ƒ extends ƒn> = {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
key: string
|
|
38
|
+
do: Write<ƒ>
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export type TransactionIO<Token extends TransactionToken<any>> =
|
|
42
|
-
|
|
42
|
+
Token extends TransactionToken<infer ƒ> ? ƒ : never
|
|
43
43
|
|
|
44
44
|
export function transaction<ƒ extends ƒn>(
|
|
45
|
-
|
|
45
|
+
options: TransactionOptions<ƒ>,
|
|
46
46
|
): TransactionToken<ƒ> {
|
|
47
|
-
|
|
47
|
+
return transaction__INTERNAL(options)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export const runTransaction =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>
|
|
52
|
+
(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {
|
|
53
|
+
const tx = withdraw(token, store)
|
|
54
|
+
if (tx) {
|
|
55
|
+
return tx.run(...parameters)
|
|
56
|
+
}
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`,
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -3,28 +3,28 @@ import type { Json } from "~/packages/anvl/src/json"
|
|
|
3
3
|
import type { AtomEffect } from "../index"
|
|
4
4
|
|
|
5
5
|
export type StringInterface<T> = {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
stringify: (t: T) => string
|
|
7
|
+
parse: (s: string) => T
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const persistAtom =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
<T>(storage: Storage) =>
|
|
12
|
+
({ stringify, parse }: StringInterface<T>) =>
|
|
13
|
+
(key: string): AtomEffect<T> =>
|
|
14
|
+
({ setSelf, onSet }) => {
|
|
15
|
+
const savedValue = storage.getItem(key)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
if (savedValue != null) setSelf(parse(savedValue))
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
onSet(({ newValue }) => {
|
|
20
|
+
if (newValue == null) {
|
|
21
|
+
storage.removeItem(key)
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
storage.setItem(key, stringify(newValue))
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
27
|
|
|
28
28
|
export const lazyLocalStorageEffect: <J extends Json>(
|
|
29
|
-
|
|
29
|
+
key: string,
|
|
30
30
|
) => AtomEffect<J> = persistAtom(localStorage)(JSON)
|