atom.io 0.25.2 → 0.25.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/package.json +6 -6
- package/react/dist/index.cjs +29 -11
- package/react/dist/index.js +30 -12
- package/react/src/parse-state-overloads.ts +43 -0
- package/react/src/use-i.ts +6 -11
- package/react/src/use-o.ts +7 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.3",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"@types/npmlog": "7.0.0",
|
|
57
57
|
"@types/react": "18.3.3",
|
|
58
58
|
"@types/tmp": "0.2.6",
|
|
59
|
-
"@typescript-eslint/parser": "7.
|
|
60
|
-
"@typescript-eslint/rule-tester": "7.
|
|
59
|
+
"@typescript-eslint/parser": "7.15.0",
|
|
60
|
+
"@typescript-eslint/rule-tester": "7.15.0",
|
|
61
61
|
"@vitest/coverage-v8": "1.6.0",
|
|
62
62
|
"@vitest/ui": "1.6.0",
|
|
63
63
|
"concurrently": "8.2.2",
|
|
64
|
-
"drizzle-kit": "0.22.
|
|
64
|
+
"drizzle-kit": "0.22.8",
|
|
65
65
|
"drizzle-orm": "0.31.2",
|
|
66
66
|
"eslint": "npm:eslint@8.57.0",
|
|
67
67
|
"eslint-v9": "npm:eslint@9.6.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"http-proxy": "1.18.1",
|
|
71
71
|
"npmlog": "7.0.1",
|
|
72
72
|
"postgres": "3.4.4",
|
|
73
|
-
"preact": "10.22.
|
|
73
|
+
"preact": "10.22.1",
|
|
74
74
|
"react": "18.3.1",
|
|
75
75
|
"react-dom": "18.3.1",
|
|
76
76
|
"react-router-dom": "6.24.0",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"socket.io-client": "4.7.5",
|
|
79
79
|
"tmp": "0.2.3",
|
|
80
80
|
"tsup": "8.1.0",
|
|
81
|
-
"typescript": "5.5.
|
|
81
|
+
"typescript": "5.5.3",
|
|
82
82
|
"vite": "5.3.2",
|
|
83
83
|
"vite-tsconfig-paths": "4.3.2",
|
|
84
84
|
"vitest": "1.6.0"
|
package/react/dist/index.cjs
CHANGED
|
@@ -28,28 +28,46 @@ var React5__namespace = /*#__PURE__*/_interopNamespace(React5);
|
|
|
28
28
|
// react/src/store-context.tsx
|
|
29
29
|
var StoreContext = React5__namespace.createContext(internal.IMPLICIT.STORE);
|
|
30
30
|
var StoreProvider = ({ children, store = internal.IMPLICIT.STORE }) => /* @__PURE__ */ jsxRuntime.jsx(StoreContext.Provider, { value: store, children });
|
|
31
|
-
function
|
|
31
|
+
function parseStateOverloads(store, ...rest) {
|
|
32
|
+
let token;
|
|
33
|
+
if (rest.length === 2) {
|
|
34
|
+
const family = rest[0];
|
|
35
|
+
const key = rest[1];
|
|
36
|
+
if (store.config.lifespan === `immortal`) {
|
|
37
|
+
const maybeToken = internal.seekInStore(family, key, store);
|
|
38
|
+
if (!maybeToken) {
|
|
39
|
+
throw new internal.NotFoundError(family, key, store);
|
|
40
|
+
}
|
|
41
|
+
token = maybeToken;
|
|
42
|
+
} else {
|
|
43
|
+
token = internal.findInStore(family, key, store);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
token = rest[0];
|
|
47
|
+
}
|
|
48
|
+
return token;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// react/src/use-i.ts
|
|
52
|
+
function useI(...params) {
|
|
32
53
|
const store = React5__namespace.useContext(StoreContext);
|
|
33
|
-
const
|
|
54
|
+
const token = parseStateOverloads(store, ...params);
|
|
34
55
|
const setter = React5__namespace.useRef(null);
|
|
35
56
|
if (setter.current === null) {
|
|
36
57
|
setter.current = (next) => {
|
|
37
|
-
internal.setIntoStore(
|
|
58
|
+
internal.setIntoStore(token, next, store);
|
|
38
59
|
};
|
|
39
60
|
}
|
|
40
61
|
return setter.current;
|
|
41
62
|
}
|
|
42
|
-
function useO(
|
|
63
|
+
function useO(...params) {
|
|
43
64
|
const store = React5__namespace.useContext(StoreContext);
|
|
44
|
-
const
|
|
45
|
-
if (!stateToken) {
|
|
46
|
-
throw new internal.NotFoundError(token, store);
|
|
47
|
-
}
|
|
65
|
+
const token = parseStateOverloads(store, ...params);
|
|
48
66
|
const id = React5__namespace.useId();
|
|
49
67
|
return React5__namespace.useSyncExternalStore(
|
|
50
|
-
(dispatch) => internal.subscribeToState(
|
|
51
|
-
() => internal.getFromStore(
|
|
52
|
-
() => internal.getFromStore(
|
|
68
|
+
(dispatch) => internal.subscribeToState(token, dispatch, `use-o:${id}`, store),
|
|
69
|
+
() => internal.getFromStore(token, store),
|
|
70
|
+
() => internal.getFromStore(token, store)
|
|
53
71
|
);
|
|
54
72
|
}
|
|
55
73
|
|
package/react/dist/index.js
CHANGED
|
@@ -1,33 +1,51 @@
|
|
|
1
1
|
import '../../dist/chunk-S4N6XNPH.js';
|
|
2
|
-
import { IMPLICIT,
|
|
2
|
+
import { IMPLICIT, setIntoStore, subscribeToState, getFromStore, findInStore, getJsonToken, withdraw, subscribeToTimeline, seekInStore, NotFoundError } from 'atom.io/internal';
|
|
3
3
|
import * as React5 from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
import { undo, redo } from 'atom.io';
|
|
6
6
|
|
|
7
7
|
var StoreContext = React5.createContext(IMPLICIT.STORE);
|
|
8
8
|
var StoreProvider = ({ children, store = IMPLICIT.STORE }) => /* @__PURE__ */ jsx(StoreContext.Provider, { value: store, children });
|
|
9
|
-
function
|
|
9
|
+
function parseStateOverloads(store, ...rest) {
|
|
10
|
+
let token;
|
|
11
|
+
if (rest.length === 2) {
|
|
12
|
+
const family = rest[0];
|
|
13
|
+
const key = rest[1];
|
|
14
|
+
if (store.config.lifespan === `immortal`) {
|
|
15
|
+
const maybeToken = seekInStore(family, key, store);
|
|
16
|
+
if (!maybeToken) {
|
|
17
|
+
throw new NotFoundError(family, key, store);
|
|
18
|
+
}
|
|
19
|
+
token = maybeToken;
|
|
20
|
+
} else {
|
|
21
|
+
token = findInStore(family, key, store);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
token = rest[0];
|
|
25
|
+
}
|
|
26
|
+
return token;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// react/src/use-i.ts
|
|
30
|
+
function useI(...params) {
|
|
10
31
|
const store = React5.useContext(StoreContext);
|
|
11
|
-
const
|
|
32
|
+
const token = parseStateOverloads(store, ...params);
|
|
12
33
|
const setter = React5.useRef(null);
|
|
13
34
|
if (setter.current === null) {
|
|
14
35
|
setter.current = (next) => {
|
|
15
|
-
setIntoStore(
|
|
36
|
+
setIntoStore(token, next, store);
|
|
16
37
|
};
|
|
17
38
|
}
|
|
18
39
|
return setter.current;
|
|
19
40
|
}
|
|
20
|
-
function useO(
|
|
41
|
+
function useO(...params) {
|
|
21
42
|
const store = React5.useContext(StoreContext);
|
|
22
|
-
const
|
|
23
|
-
if (!stateToken) {
|
|
24
|
-
throw new NotFoundError(token, store);
|
|
25
|
-
}
|
|
43
|
+
const token = parseStateOverloads(store, ...params);
|
|
26
44
|
const id = React5.useId();
|
|
27
45
|
return React5.useSyncExternalStore(
|
|
28
|
-
(dispatch) => subscribeToState(
|
|
29
|
-
() => getFromStore(
|
|
30
|
-
() => getFromStore(
|
|
46
|
+
(dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),
|
|
47
|
+
() => getFromStore(token, store),
|
|
48
|
+
() => getFromStore(token, store)
|
|
31
49
|
);
|
|
32
50
|
}
|
|
33
51
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ReadableFamilyToken,
|
|
3
|
+
ReadableToken,
|
|
4
|
+
WritableFamilyToken,
|
|
5
|
+
WritableToken,
|
|
6
|
+
} from "atom.io"
|
|
7
|
+
import type { Store } from "atom.io/internal"
|
|
8
|
+
import { findInStore, NotFoundError, seekInStore } from "atom.io/internal"
|
|
9
|
+
import type { Json } from "atom.io/json"
|
|
10
|
+
|
|
11
|
+
export function parseStateOverloads<T, K extends Json.Serializable>(
|
|
12
|
+
store: Store,
|
|
13
|
+
...rest: [WritableFamilyToken<T, K>, K] | [WritableToken<T>]
|
|
14
|
+
): WritableToken<T>
|
|
15
|
+
|
|
16
|
+
export function parseStateOverloads<T, K extends Json.Serializable>(
|
|
17
|
+
store: Store,
|
|
18
|
+
...rest: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]
|
|
19
|
+
): ReadableToken<T>
|
|
20
|
+
|
|
21
|
+
export function parseStateOverloads<T, K extends Json.Serializable>(
|
|
22
|
+
store: Store,
|
|
23
|
+
...rest: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]
|
|
24
|
+
): ReadableToken<T> {
|
|
25
|
+
let token: ReadableToken<any>
|
|
26
|
+
if (rest.length === 2) {
|
|
27
|
+
const family = rest[0]
|
|
28
|
+
const key = rest[1]
|
|
29
|
+
|
|
30
|
+
if (store.config.lifespan === `immortal`) {
|
|
31
|
+
const maybeToken = seekInStore(family, key, store)
|
|
32
|
+
if (!maybeToken) {
|
|
33
|
+
throw new NotFoundError(family, key, store)
|
|
34
|
+
}
|
|
35
|
+
token = maybeToken
|
|
36
|
+
} else {
|
|
37
|
+
token = findInStore(family, key, store)
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
token = rest[0]
|
|
41
|
+
}
|
|
42
|
+
return token
|
|
43
|
+
}
|
package/react/src/use-i.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { WritableFamilyToken, WritableToken } from "atom.io"
|
|
2
|
+
import { setIntoStore } from "atom.io/internal"
|
|
3
3
|
import type { Json } from "atom.io/json"
|
|
4
4
|
import * as React from "react"
|
|
5
5
|
|
|
6
|
+
import { parseStateOverloads } from "./parse-state-overloads"
|
|
6
7
|
import { StoreContext } from "./store-context"
|
|
7
8
|
|
|
8
9
|
export function useI<T>(
|
|
@@ -15,22 +16,16 @@ export function useI<T, K extends Json.Serializable>(
|
|
|
15
16
|
): <New extends T>(next: New | ((old: T) => New)) => void
|
|
16
17
|
|
|
17
18
|
export function useI<T, K extends Json.Serializable>(
|
|
18
|
-
|
|
19
|
-
key?: K,
|
|
19
|
+
...params: [WritableFamilyToken<T, K>, K] | [WritableToken<T>]
|
|
20
20
|
): <New extends T>(next: New | ((old: T) => New)) => void {
|
|
21
21
|
const store = React.useContext(StoreContext)
|
|
22
|
-
const
|
|
23
|
-
token.type === `atom_family` ||
|
|
24
|
-
token.type === `mutable_atom_family` ||
|
|
25
|
-
token.type === `selector_family`
|
|
26
|
-
? findInStore(token, key as K, store)
|
|
27
|
-
: token
|
|
22
|
+
const token = parseStateOverloads(store, ...params)
|
|
28
23
|
const setter: React.MutableRefObject<
|
|
29
24
|
(<New extends T>(next: New | ((old: T) => New)) => void) | null
|
|
30
25
|
> = React.useRef(null)
|
|
31
26
|
if (setter.current === null) {
|
|
32
27
|
setter.current = (next) => {
|
|
33
|
-
setIntoStore(
|
|
28
|
+
setIntoStore(token, next, store)
|
|
34
29
|
}
|
|
35
30
|
}
|
|
36
31
|
return setter.current
|
package/react/src/use-o.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import type { ReadableFamilyToken, ReadableToken } from "atom.io"
|
|
2
|
-
import {
|
|
3
|
-
getFromStore,
|
|
4
|
-
NotFoundError,
|
|
5
|
-
seekInStore,
|
|
6
|
-
subscribeToState,
|
|
7
|
-
} from "atom.io/internal"
|
|
2
|
+
import { getFromStore, subscribeToState } from "atom.io/internal"
|
|
8
3
|
import type { Json } from "atom.io/json"
|
|
9
4
|
import * as React from "react"
|
|
10
5
|
|
|
6
|
+
import { parseStateOverloads } from "./parse-state-overloads"
|
|
11
7
|
import { StoreContext } from "./store-context"
|
|
12
8
|
|
|
13
9
|
export function useO<T>(token: ReadableToken<T>): T
|
|
@@ -18,24 +14,14 @@ export function useO<T, K extends Json.Serializable>(
|
|
|
18
14
|
): T
|
|
19
15
|
|
|
20
16
|
export function useO<T, K extends Json.Serializable>(
|
|
21
|
-
|
|
22
|
-
key?: K,
|
|
17
|
+
...params: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]
|
|
23
18
|
): T {
|
|
24
19
|
const store = React.useContext(StoreContext)
|
|
25
|
-
const
|
|
26
|
-
token.type === `atom_family` ||
|
|
27
|
-
token.type === `mutable_atom_family` ||
|
|
28
|
-
token.type === `selector_family` ||
|
|
29
|
-
token.type === `readonly_selector_family`
|
|
30
|
-
? seekInStore(token, key as K, store)
|
|
31
|
-
: token
|
|
32
|
-
if (!stateToken) {
|
|
33
|
-
throw new NotFoundError(token, store)
|
|
34
|
-
}
|
|
20
|
+
const token = parseStateOverloads(store, ...params)
|
|
35
21
|
const id = React.useId()
|
|
36
22
|
return React.useSyncExternalStore<T>(
|
|
37
|
-
(dispatch) => subscribeToState(
|
|
38
|
-
() => getFromStore(
|
|
39
|
-
() => getFromStore(
|
|
23
|
+
(dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),
|
|
24
|
+
() => getFromStore(token, store),
|
|
25
|
+
() => getFromStore(token, store),
|
|
40
26
|
)
|
|
41
27
|
}
|