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
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type * as AtomIO from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import { IMPLICIT, createSelectorFamily } from "atom.io/internal"
|
|
4
|
+
|
|
5
|
+
import type { Json, JsonInterface } from "."
|
|
6
|
+
import { parseJson } from "."
|
|
7
|
+
|
|
8
|
+
export const selectJsonFamily = <
|
|
9
|
+
T,
|
|
10
|
+
J extends Json.Serializable,
|
|
11
|
+
K extends Json.Serializable,
|
|
12
|
+
>(
|
|
13
|
+
atomFamily: AtomIO.AtomFamily<T, K>,
|
|
14
|
+
transform: JsonInterface<T, J>,
|
|
15
|
+
store: Store = IMPLICIT.STORE,
|
|
16
|
+
): AtomIO.SelectorFamily<J, K> => {
|
|
17
|
+
const jsonFamily = createSelectorFamily<J, K>(
|
|
18
|
+
{
|
|
19
|
+
key: `${atomFamily.key}:JSON`,
|
|
20
|
+
get: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),
|
|
21
|
+
set: (key) => ({ set }, newValue) =>
|
|
22
|
+
set(atomFamily(key), transform.fromJson(newValue)),
|
|
23
|
+
},
|
|
24
|
+
store,
|
|
25
|
+
)
|
|
26
|
+
atomFamily.subject.subscribe(
|
|
27
|
+
`store=${store.config.name}::json-selector-family`,
|
|
28
|
+
(token) => {
|
|
29
|
+
if (token.family) {
|
|
30
|
+
jsonFamily(parseJson(token.family.subKey) as K)
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
)
|
|
34
|
+
return jsonFamily
|
|
35
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type * as AtomIO from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import { IMPLICIT } from "atom.io/internal"
|
|
4
|
+
|
|
5
|
+
import { createSelector } from "atom.io/internal"
|
|
6
|
+
import type { Json, JsonInterface } from "."
|
|
7
|
+
|
|
8
|
+
export const selectJson = <T, J extends Json.Serializable>(
|
|
9
|
+
atom: AtomIO.AtomToken<T>,
|
|
10
|
+
transform: JsonInterface<T, J>,
|
|
11
|
+
store: Store = IMPLICIT.STORE,
|
|
12
|
+
): AtomIO.SelectorToken<J> => {
|
|
13
|
+
return createSelector(
|
|
14
|
+
{
|
|
15
|
+
key: `${atom.key}:JSON`,
|
|
16
|
+
get: ({ get }) => transform.toJson(get(atom)),
|
|
17
|
+
set: ({ set }, newValue) => set(atom, transform.fromJson(newValue)),
|
|
18
|
+
},
|
|
19
|
+
undefined,
|
|
20
|
+
store,
|
|
21
|
+
)
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,96 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Reactive state graph for React, Preact, and vanilla",
|
|
5
|
+
"dependencies": {},
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"@testing-library/react": ">=14.0.0",
|
|
8
|
+
"@floating-ui/react": ">=0.25.0",
|
|
9
|
+
"@floating-ui/react-dom": ">=2.0.0",
|
|
10
|
+
"framer-motion": ">=10.0.0",
|
|
11
|
+
"react": ">=18.0.0",
|
|
12
|
+
"socket.io": ">=4.0.0",
|
|
13
|
+
"socket.io-client": ">=4.0.0"
|
|
14
|
+
},
|
|
15
|
+
"peerDependenciesMeta": {
|
|
16
|
+
"@testing-library/react": {
|
|
17
|
+
"optional": true
|
|
18
|
+
},
|
|
19
|
+
"react": {
|
|
20
|
+
"optional": true
|
|
21
|
+
},
|
|
22
|
+
"@floating-ui/react": {
|
|
23
|
+
"optional": true
|
|
24
|
+
},
|
|
25
|
+
"@floating-ui/react-dom": {
|
|
26
|
+
"optional": true
|
|
27
|
+
},
|
|
28
|
+
"framer-motion": {
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
"socket.io": {
|
|
32
|
+
"optional": true
|
|
33
|
+
},
|
|
34
|
+
"socket.io-client": {
|
|
35
|
+
"optional": true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@emotion/react": "11.11.1",
|
|
40
|
+
"@testing-library/react": "14.0.0",
|
|
41
|
+
"@types/mock-fs": "4.13.1",
|
|
42
|
+
"@types/react": "18.2.21",
|
|
43
|
+
"@types/tmp": "0.2.4",
|
|
44
|
+
"concurrently": "8.2.1",
|
|
45
|
+
"eslint": "8.50.0",
|
|
46
|
+
"framer-motion": "10.16.4",
|
|
47
|
+
"happy-dom": "12.1.6",
|
|
48
|
+
"preact": "10.17.1",
|
|
49
|
+
"react": "18.2.0",
|
|
50
|
+
"react-dom": "18.2.0",
|
|
51
|
+
"react-router-dom": "6.16.0",
|
|
52
|
+
"socket.io": "4.7.2",
|
|
53
|
+
"socket.io-client": "4.7.2",
|
|
54
|
+
"tmp": "0.2.1",
|
|
55
|
+
"tsup": "7.2.0",
|
|
56
|
+
"typescript": "5.2.2",
|
|
57
|
+
"vite": "4.4.9",
|
|
58
|
+
"vite-tsconfig-paths": "4.2.1",
|
|
59
|
+
"vitest": "0.34.5"
|
|
60
|
+
},
|
|
5
61
|
"main": "dist/index.js",
|
|
6
62
|
"types": "dist/index.d.ts",
|
|
7
63
|
"module": "dist/index.mjs",
|
|
8
64
|
"files": [
|
|
9
65
|
"dist",
|
|
66
|
+
"internal/dist",
|
|
67
|
+
"internal/package.json",
|
|
68
|
+
"internal/src",
|
|
10
69
|
"introspection/dist",
|
|
11
70
|
"introspection/package.json",
|
|
71
|
+
"introspection/src",
|
|
12
72
|
"json/dist",
|
|
13
73
|
"json/package.json",
|
|
74
|
+
"json/src",
|
|
14
75
|
"react/dist",
|
|
15
76
|
"react/package.json",
|
|
77
|
+
"react/src",
|
|
16
78
|
"react-devtools/dist",
|
|
17
79
|
"react-devtools/package.json",
|
|
80
|
+
"react-devtools/src",
|
|
18
81
|
"realtime/dist",
|
|
19
82
|
"realtime/package.json",
|
|
83
|
+
"realtime/src",
|
|
20
84
|
"realtime-react/dist",
|
|
21
85
|
"realtime-react/package.json",
|
|
86
|
+
"realtime-react/src",
|
|
22
87
|
"realtime-testing/dist",
|
|
23
88
|
"realtime-testing/package.json",
|
|
24
|
-
"src"
|
|
89
|
+
"realtime-testing/src",
|
|
90
|
+
"src",
|
|
91
|
+
"transceivers/set-rtx/dist",
|
|
92
|
+
"transceivers/set-rtx/package.json",
|
|
93
|
+
"transceivers/set-rtx/src"
|
|
25
94
|
],
|
|
26
95
|
"exports": {
|
|
27
96
|
"./package.json": "./package.json",
|
|
@@ -31,6 +100,13 @@
|
|
|
31
100
|
"import": "./dist/index.mjs",
|
|
32
101
|
"require": "./dist/index.js"
|
|
33
102
|
},
|
|
103
|
+
"./internal/package.json": "./internal/package.json",
|
|
104
|
+
"./internal": {
|
|
105
|
+
"types": "./internal/dist/index.d.ts",
|
|
106
|
+
"browser": "./internal/dist/index.mjs",
|
|
107
|
+
"import": "./internal/dist/index.mjs",
|
|
108
|
+
"require": "./internal/dist/index.js"
|
|
109
|
+
},
|
|
34
110
|
"./introspection/package.json": "./json/package.json",
|
|
35
111
|
"./introspection": {
|
|
36
112
|
"types": "./json/dist/index.d.ts",
|
|
@@ -59,12 +135,12 @@
|
|
|
59
135
|
"import": "./react-devtools/dist/index.mjs",
|
|
60
136
|
"require": "./react-devtools/dist/index.js"
|
|
61
137
|
},
|
|
62
|
-
"./realtime/package.json": "./realtime/package.json",
|
|
63
|
-
"./realtime": {
|
|
64
|
-
"types": "./realtime/dist/index.d.ts",
|
|
65
|
-
"browser": "./realtime/dist/index.mjs",
|
|
66
|
-
"import": "./realtime/dist/index.mjs",
|
|
67
|
-
"require": "./realtime/dist/index.js"
|
|
138
|
+
"./realtime-client/package.json": "./realtime-client/package.json",
|
|
139
|
+
"./realtime-client": {
|
|
140
|
+
"types": "./realtime-client/dist/index.d.ts",
|
|
141
|
+
"browser": "./realtime-client/dist/index.mjs",
|
|
142
|
+
"import": "./realtime-client/dist/index.mjs",
|
|
143
|
+
"require": "./realtime-client/dist/index.js"
|
|
68
144
|
},
|
|
69
145
|
"./realtime-react/package.json": "./realtime-react/package.json",
|
|
70
146
|
"./realtime-react": {
|
|
@@ -73,60 +149,28 @@
|
|
|
73
149
|
"import": "./realtime-react/dist/index.mjs",
|
|
74
150
|
"require": "./realtime-react/dist/index.js"
|
|
75
151
|
},
|
|
152
|
+
"./realtime-server/package.json": "./realtime-server/package.json",
|
|
153
|
+
"./realtime-server": {
|
|
154
|
+
"types": "./realtime-server/dist/index.d.ts",
|
|
155
|
+
"browser": "./realtime-server/dist/index.mjs",
|
|
156
|
+
"import": "./realtime-server/dist/index.mjs",
|
|
157
|
+
"require": "./realtime-server/dist/index.js"
|
|
158
|
+
},
|
|
76
159
|
"./realtime-testing/package.json": "./realtime-testing/package.json",
|
|
77
160
|
"./realtime-testing": {
|
|
78
161
|
"types": "./realtime-testing/dist/index.d.ts",
|
|
79
162
|
"browser": "./realtime-testing/dist/index.mjs",
|
|
80
163
|
"import": "./realtime-testing/dist/index.mjs",
|
|
81
164
|
"require": "./realtime-testing/dist/index.js"
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
"peerDependencies": {
|
|
85
|
-
"preact": ">=10.0.0",
|
|
86
|
-
"react": ">=16.8.0",
|
|
87
|
-
"socket.io": ">=4.0.0",
|
|
88
|
-
"socket.io-client": ">=4.0.0"
|
|
89
|
-
},
|
|
90
|
-
"peerDependenciesMeta": {
|
|
91
|
-
"preact": {
|
|
92
|
-
"optional": true
|
|
93
|
-
},
|
|
94
|
-
"react": {
|
|
95
|
-
"optional": true
|
|
96
165
|
},
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"
|
|
166
|
+
"./transceivers/set-rtx/package.json": "./transceivers/set-rtx/package.json",
|
|
167
|
+
"./transceivers/set-rtx": {
|
|
168
|
+
"types": "./transceivers/set-rtx/dist/index.d.ts",
|
|
169
|
+
"browser": "./transceivers/set-rtx/dist/index.mjs",
|
|
170
|
+
"import": "./transceivers/set-rtx/dist/index.mjs",
|
|
171
|
+
"require": "./transceivers/set-rtx/dist/index.js"
|
|
102
172
|
}
|
|
103
173
|
},
|
|
104
|
-
"dependencies": {
|
|
105
|
-
"fp-ts": "2.16.1"
|
|
106
|
-
},
|
|
107
|
-
"devDependencies": {
|
|
108
|
-
"@emotion/react": "11.11.1",
|
|
109
|
-
"@testing-library/react": "14.0.0",
|
|
110
|
-
"@types/mock-fs": "4.13.1",
|
|
111
|
-
"@types/react": "18.2.20",
|
|
112
|
-
"@types/tmp": "0.2.3",
|
|
113
|
-
"concurrently": "8.2.0",
|
|
114
|
-
"eslint": "8.47.0",
|
|
115
|
-
"framer-motion": "10.15.2",
|
|
116
|
-
"happy-dom": "10.9.0",
|
|
117
|
-
"preact": "10.17.0",
|
|
118
|
-
"react": "18.2.0",
|
|
119
|
-
"react-dom": "18.2.0",
|
|
120
|
-
"react-router-dom": "6.15.0",
|
|
121
|
-
"socket.io": "4.7.2",
|
|
122
|
-
"socket.io-client": "4.7.2",
|
|
123
|
-
"tmp": "0.2.1",
|
|
124
|
-
"tsup": "7.2.0",
|
|
125
|
-
"typescript": "5.1.6",
|
|
126
|
-
"vite": "4.4.9",
|
|
127
|
-
"vite-tsconfig-paths": "4.2.0",
|
|
128
|
-
"vitest": "0.34.1"
|
|
129
|
-
},
|
|
130
174
|
"repository": {
|
|
131
175
|
"type": "git",
|
|
132
176
|
"url": "git+https://github.com/jeremybanka/wayforge.git"
|
|
@@ -140,16 +184,20 @@
|
|
|
140
184
|
"scripts": {
|
|
141
185
|
"build": "concurrently \"npm:build:*\"",
|
|
142
186
|
"build:main": "tsup",
|
|
187
|
+
"build:internal": "cd internal && tsup",
|
|
143
188
|
"build:introspection": "cd introspection && tsup",
|
|
144
189
|
"build:json": "cd json && tsup",
|
|
145
190
|
"build:react": "cd react && tsup",
|
|
146
191
|
"build:react-devtools": "cd react-devtools && tsup",
|
|
147
|
-
"build:realtime": "cd realtime && tsup",
|
|
192
|
+
"build:realtime-client": "cd realtime-client && tsup",
|
|
148
193
|
"build:realtime-react": "cd realtime-react && tsup",
|
|
149
|
-
"
|
|
194
|
+
"build:realtime-server": "cd realtime-server && tsup",
|
|
195
|
+
"build:realtime-testing": "cd realtime-testing && tsup",
|
|
196
|
+
"build:transceivers:set-rtx": "cd transceivers/set-rtx && tsup",
|
|
197
|
+
"lint:biome": "biome check .",
|
|
150
198
|
"lint:eslint": "eslint .",
|
|
151
|
-
"lint": "npm run lint:
|
|
199
|
+
"lint": "npm run lint:biome && npm run lint:eslint",
|
|
152
200
|
"test": "vitest",
|
|
153
|
-
"test:once": "vitest run"
|
|
201
|
+
"test:once": "cross-env LIB=dist vitest run"
|
|
154
202
|
}
|
|
155
203
|
}
|
package/react/dist/index.d.mts
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Store } from 'atom.io/internal';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { StateToken, ReadonlySelectorToken, MutableAtomToken } from 'atom.io';
|
|
4
|
+
import { Json } from 'atom.io/json';
|
|
3
5
|
|
|
4
|
-
declare const StoreContext: React.Context<
|
|
6
|
+
declare const StoreContext: React.Context<Store>;
|
|
5
7
|
declare const StoreProvider: React.FC<{
|
|
6
8
|
children: React.ReactNode;
|
|
7
|
-
store?:
|
|
9
|
+
store?: Store;
|
|
8
10
|
}>;
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
declare function useI<T>(token: StateToken<T>): <New extends T>(next: New | ((old: T) => New)) => void;
|
|
13
|
+
declare function useO<T>(token: ReadonlySelectorToken<T> | StateToken<T>): T;
|
|
14
|
+
declare function useJSON<Serializable extends Json.Serializable>(token: MutableAtomToken<any, Serializable>): Serializable;
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
useI: <T>(token: AtomIO.StateToken<T>) => (next: Modifier<T> | T) => void;
|
|
14
|
-
useO: <T>(token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>) => T;
|
|
15
|
-
useIO: <T>(token: AtomIO.StateToken<T>) => [T, (next: Modifier<T> | T) => void];
|
|
16
|
-
};
|
|
17
|
-
declare const storeHooks: StoreHooks;
|
|
18
|
-
declare function useI<T>(token: AtomIO.StateToken<T>): (next: Modifier<T> | T) => void;
|
|
19
|
-
declare function useO<T>(token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>): T;
|
|
20
|
-
declare function useIO<T>(token: AtomIO.StateToken<T>): [T, (next: Modifier<T> | T) => void];
|
|
21
|
-
declare function useStore<T>(token: AtomIO.StateToken<T>): [T, (next: Modifier<T> | T) => void];
|
|
22
|
-
declare function useStore<T>(token: AtomIO.ReadonlySelectorToken<T>): T;
|
|
23
|
-
|
|
24
|
-
export { StoreContext, StoreHooks, StoreProvider, storeHooks, useI, useIO, useO, useStore };
|
|
16
|
+
export { StoreContext, StoreProvider, useI, useJSON, useO };
|
package/react/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Store } from 'atom.io/internal';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { StateToken, ReadonlySelectorToken, MutableAtomToken } from 'atom.io';
|
|
4
|
+
import { Json } from 'atom.io/json';
|
|
3
5
|
|
|
4
|
-
declare const StoreContext: React.Context<
|
|
6
|
+
declare const StoreContext: React.Context<Store>;
|
|
5
7
|
declare const StoreProvider: React.FC<{
|
|
6
8
|
children: React.ReactNode;
|
|
7
|
-
store?:
|
|
9
|
+
store?: Store;
|
|
8
10
|
}>;
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
declare function useI<T>(token: StateToken<T>): <New extends T>(next: New | ((old: T) => New)) => void;
|
|
13
|
+
declare function useO<T>(token: ReadonlySelectorToken<T> | StateToken<T>): T;
|
|
14
|
+
declare function useJSON<Serializable extends Json.Serializable>(token: MutableAtomToken<any, Serializable>): Serializable;
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
useI: <T>(token: AtomIO.StateToken<T>) => (next: Modifier<T> | T) => void;
|
|
14
|
-
useO: <T>(token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>) => T;
|
|
15
|
-
useIO: <T>(token: AtomIO.StateToken<T>) => [T, (next: Modifier<T> | T) => void];
|
|
16
|
-
};
|
|
17
|
-
declare const storeHooks: StoreHooks;
|
|
18
|
-
declare function useI<T>(token: AtomIO.StateToken<T>): (next: Modifier<T> | T) => void;
|
|
19
|
-
declare function useO<T>(token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>): T;
|
|
20
|
-
declare function useIO<T>(token: AtomIO.StateToken<T>): [T, (next: Modifier<T> | T) => void];
|
|
21
|
-
declare function useStore<T>(token: AtomIO.StateToken<T>): [T, (next: Modifier<T> | T) => void];
|
|
22
|
-
declare function useStore<T>(token: AtomIO.ReadonlySelectorToken<T>): T;
|
|
23
|
-
|
|
24
|
-
export { StoreContext, StoreHooks, StoreProvider, storeHooks, useI, useIO, useO, useStore };
|
|
16
|
+
export { StoreContext, StoreProvider, useI, useJSON, useO };
|
package/react/dist/index.js
CHANGED
|
@@ -1,87 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var internal = require('atom.io/internal');
|
|
4
|
+
var React2 = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var atom_io = require('atom.io');
|
|
28
7
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
41
25
|
|
|
42
|
-
|
|
43
|
-
var AtomIO = __toESM(require("atom.io"));
|
|
44
|
-
var React = __toESM(require("react"));
|
|
45
|
-
var import_jsx_dev_runtime = require("react/jsx-dev-runtime");
|
|
46
|
-
var StoreContext = React.createContext(
|
|
47
|
-
AtomIO.__INTERNAL__.IMPLICIT.STORE
|
|
48
|
-
);
|
|
49
|
-
var StoreProvider = ({ children, store = AtomIO.__INTERNAL__.IMPLICIT.STORE }) => /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(StoreContext.Provider, { value: store, children }, void 0, false, {
|
|
50
|
-
fileName: "../src/react/store-context.tsx",
|
|
51
|
-
lineNumber: 12,
|
|
52
|
-
columnNumber: 2
|
|
53
|
-
}, this);
|
|
26
|
+
var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
|
|
54
27
|
|
|
55
|
-
//
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var storeHooks = { useI, useO, useIO };
|
|
28
|
+
// src/store-context.tsx
|
|
29
|
+
var StoreContext = React2__namespace.createContext(internal.IMPLICIT.STORE);
|
|
30
|
+
var StoreProvider = ({ children, store = internal.IMPLICIT.STORE }) => /* @__PURE__ */ jsxRuntime.jsx(StoreContext.Provider, { value: store, children });
|
|
59
31
|
function useI(token) {
|
|
60
|
-
const store =
|
|
61
|
-
|
|
62
|
-
return update;
|
|
32
|
+
const store = React2__namespace.useContext(StoreContext);
|
|
33
|
+
return (next) => atom_io.setState(token, next, store);
|
|
63
34
|
}
|
|
64
35
|
function useO(token) {
|
|
65
|
-
const store =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
() =>
|
|
36
|
+
const store = React2__namespace.useContext(StoreContext);
|
|
37
|
+
const id = React2__namespace.useId();
|
|
38
|
+
return React2__namespace.useSyncExternalStore(
|
|
39
|
+
(dispatch) => atom_io.subscribe(token, dispatch, `use-o:${id}`, store),
|
|
40
|
+
() => atom_io.getState(token, store),
|
|
41
|
+
() => atom_io.getState(token, store)
|
|
69
42
|
);
|
|
70
43
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
function useStore(token) {
|
|
75
|
-
return token.type === `readonly_selector` ? useO(token) : useIO(token);
|
|
44
|
+
function useJSON(token) {
|
|
45
|
+
const jsonToken = internal.getJsonToken(token);
|
|
46
|
+
return useO(jsonToken);
|
|
76
47
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
useO,
|
|
85
|
-
useStore
|
|
86
|
-
});
|
|
48
|
+
|
|
49
|
+
exports.StoreContext = StoreContext;
|
|
50
|
+
exports.StoreProvider = StoreProvider;
|
|
51
|
+
exports.useI = useI;
|
|
52
|
+
exports.useJSON = useJSON;
|
|
53
|
+
exports.useO = useO;
|
|
54
|
+
//# sourceMappingURL=out.js.map
|
|
87
55
|
//# sourceMappingURL=index.js.map
|
package/react/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../src/store-context.tsx","../src/store-hooks.ts"],"names":["React"],"mappings":";AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACVhD,YAAYA,YAAW;AAEvB,SAAS,UAAU,UAAU,iBAAiB;AAO9C,SAAS,oBAAoB;AAItB,SAAS,KACf,OACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,SAAO,CAAC,SAAS,SAAS,OAAO,MAAM,KAAK;AAC7C;AAEO,SAAS,KAAQ,OAAoD;AAC3E,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,UAAU,OAAO,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IAC7D,MAAM,SAAS,OAAO,KAAK;AAAA,IAC3B,MAAM,SAAS,OAAO,KAAK;AAAA,EAC5B;AACD;AAEO,SAAS,QACf,OACe;AACf,QAAM,YAAY,aAAa,KAAK;AACpC,SAAO,KAAK,SAAS;AACtB","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import * as React from \"react\"\n\nimport { getState, setState, subscribe } from \"atom.io\"\nimport type {\n\tMutableAtomToken,\n\tReadonlySelectorToken,\n\tStateToken,\n} from \"atom.io\"\n\nimport { getJsonToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: StateToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\treturn (next) => setState(token, next, store)\n}\n\nexport function useO<T>(token: ReadonlySelectorToken<T> | StateToken<T>): T {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribe(token, dispatch, `use-o:${id}`, store),\n\t\t() => getState(token, store),\n\t\t() => getState(token, store),\n\t)\n}\n\nexport function useJSON<Serializable extends Json.Serializable,>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable {\n\tconst jsonToken = getJsonToken(token)\n\treturn useO(jsonToken)\n}\n"]}
|
package/react/dist/index.mjs
CHANGED
|
@@ -1,45 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
var StoreContext = React.createContext(
|
|
6
|
-
AtomIO.__INTERNAL__.IMPLICIT.STORE
|
|
7
|
-
);
|
|
8
|
-
var StoreProvider = ({ children, store = AtomIO.__INTERNAL__.IMPLICIT.STORE }) => /* @__PURE__ */ jsxDEV(StoreContext.Provider, { value: store, children }, void 0, false, {
|
|
9
|
-
fileName: "../src/react/store-context.tsx",
|
|
10
|
-
lineNumber: 12,
|
|
11
|
-
columnNumber: 2
|
|
12
|
-
}, this);
|
|
1
|
+
import { IMPLICIT, getJsonToken } from 'atom.io/internal';
|
|
2
|
+
import * as React2 from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { setState, subscribe, getState } from 'atom.io';
|
|
13
5
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var storeHooks = { useI, useO, useIO };
|
|
6
|
+
// src/store-context.tsx
|
|
7
|
+
var StoreContext = React2.createContext(IMPLICIT.STORE);
|
|
8
|
+
var StoreProvider = ({ children, store = IMPLICIT.STORE }) => /* @__PURE__ */ jsx(StoreContext.Provider, { value: store, children });
|
|
18
9
|
function useI(token) {
|
|
19
10
|
const store = React2.useContext(StoreContext);
|
|
20
|
-
|
|
21
|
-
return update;
|
|
11
|
+
return (next) => setState(token, next, store);
|
|
22
12
|
}
|
|
23
13
|
function useO(token) {
|
|
24
14
|
const store = React2.useContext(StoreContext);
|
|
15
|
+
const id = React2.useId();
|
|
25
16
|
return React2.useSyncExternalStore(
|
|
26
|
-
(
|
|
27
|
-
() =>
|
|
17
|
+
(dispatch) => subscribe(token, dispatch, `use-o:${id}`, store),
|
|
18
|
+
() => getState(token, store),
|
|
19
|
+
() => getState(token, store)
|
|
28
20
|
);
|
|
29
21
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
22
|
+
function useJSON(token) {
|
|
23
|
+
const jsonToken = getJsonToken(token);
|
|
24
|
+
return useO(jsonToken);
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
StoreContext,
|
|
38
|
-
StoreProvider,
|
|
39
|
-
storeHooks,
|
|
40
|
-
useI,
|
|
41
|
-
useIO,
|
|
42
|
-
useO,
|
|
43
|
-
useStore
|
|
44
|
-
};
|
|
26
|
+
|
|
27
|
+
export { StoreContext, StoreProvider, useI, useJSON, useO };
|
|
28
|
+
//# sourceMappingURL=out.js.map
|
|
45
29
|
//# sourceMappingURL=index.mjs.map
|
package/react/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../src/store-context.tsx","../src/store-hooks.ts"],"names":["React"],"mappings":";AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACVhD,YAAYA,YAAW;AAEvB,SAAS,UAAU,UAAU,iBAAiB;AAO9C,SAAS,oBAAoB;AAItB,SAAS,KACf,OACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,SAAO,CAAC,SAAS,SAAS,OAAO,MAAM,KAAK;AAC7C;AAEO,SAAS,KAAQ,OAAoD;AAC3E,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,UAAU,OAAO,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IAC7D,MAAM,SAAS,OAAO,KAAK;AAAA,IAC3B,MAAM,SAAS,OAAO,KAAK;AAAA,EAC5B;AACD;AAEO,SAAS,QACf,OACe;AACf,QAAM,YAAY,aAAa,KAAK;AACpC,SAAO,KAAK,SAAS;AACtB","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import * as React from \"react\"\n\nimport { getState, setState, subscribe } from \"atom.io\"\nimport type {\n\tMutableAtomToken,\n\tReadonlySelectorToken,\n\tStateToken,\n} from \"atom.io\"\n\nimport { getJsonToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: StateToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\treturn (next) => setState(token, next, store)\n}\n\nexport function useO<T>(token: ReadonlySelectorToken<T> | StateToken<T>): T {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribe(token, dispatch, `use-o:${id}`, store),\n\t\t() => getState(token, store),\n\t\t() => getState(token, store),\n\t)\n}\n\nexport function useJSON<Serializable extends Json.Serializable,>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable {\n\tconst jsonToken = getJsonToken(token)\n\treturn useO(jsonToken)\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Store } from "atom.io/internal"
|
|
2
|
+
import { IMPLICIT } from "atom.io/internal"
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
export const StoreContext = React.createContext<Store>(IMPLICIT.STORE)
|
|
6
|
+
|
|
7
|
+
export const StoreProvider: React.FC<{
|
|
8
|
+
children: React.ReactNode
|
|
9
|
+
store?: Store
|
|
10
|
+
}> = ({ children, store = IMPLICIT.STORE }) => (
|
|
11
|
+
<StoreContext.Provider value={store}>{children}</StoreContext.Provider>
|
|
12
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { getState, setState, subscribe } from "atom.io"
|
|
4
|
+
import type {
|
|
5
|
+
MutableAtomToken,
|
|
6
|
+
ReadonlySelectorToken,
|
|
7
|
+
StateToken,
|
|
8
|
+
} from "atom.io"
|
|
9
|
+
|
|
10
|
+
import { getJsonToken } from "atom.io/internal"
|
|
11
|
+
import type { Json } from "atom.io/json"
|
|
12
|
+
import { StoreContext } from "./store-context"
|
|
13
|
+
|
|
14
|
+
export function useI<T>(
|
|
15
|
+
token: StateToken<T>,
|
|
16
|
+
): <New extends T>(next: New | ((old: T) => New)) => void {
|
|
17
|
+
const store = React.useContext(StoreContext)
|
|
18
|
+
return (next) => setState(token, next, store)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useO<T>(token: ReadonlySelectorToken<T> | StateToken<T>): T {
|
|
22
|
+
const store = React.useContext(StoreContext)
|
|
23
|
+
const id = React.useId()
|
|
24
|
+
return React.useSyncExternalStore<T>(
|
|
25
|
+
(dispatch) => subscribe(token, dispatch, `use-o:${id}`, store),
|
|
26
|
+
() => getState(token, store),
|
|
27
|
+
() => getState(token, store),
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useJSON<Serializable extends Json.Serializable,>(
|
|
32
|
+
token: MutableAtomToken<any, Serializable>,
|
|
33
|
+
): Serializable {
|
|
34
|
+
const jsonToken = getJsonToken(token)
|
|
35
|
+
return useO(jsonToken)
|
|
36
|
+
}
|