bansa 0.0.20 → 0.0.22
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/react.d.ts +8 -6
- package/dist/react.js +6 -18
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Atom, AtomGetter, AtomOptions, AtomScope, AtomValuePair, DerivedAtom, PrimitiveAtom } from '.';
|
|
1
|
+
import type { Atom, AtomScope, AtomValuePair, DerivedAtom, PrimitiveAtom } from '.';
|
|
3
2
|
export declare const ScopeContext: import("react").Context<AtomScope>;
|
|
4
3
|
export declare const ScopeProvider: ({ value, children }: {
|
|
5
|
-
value
|
|
4
|
+
value?: AtomValuePair<unknown>[];
|
|
6
5
|
children: React.ReactNode;
|
|
7
6
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
8
7
|
export declare const useAtomValue: <Value>(atom: Atom<Value>) => Value;
|
|
9
8
|
export declare const useAtomState: <Value>(atom: DerivedAtom<Value>) => import("./atom").AtomState<Value>;
|
|
9
|
+
export declare const useScopedAtom: UseScopedAtom;
|
|
10
10
|
export declare const useAtom: <Value>(atom: PrimitiveAtom<Value>) => readonly [Value, (newState: Value) => void];
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export type UseScopedAtom = {
|
|
12
|
+
<Value>(baseAtom: PrimitiveAtom<Value>): PrimitiveAtom<Value>;
|
|
13
|
+
<Value>(baseAtom: DerivedAtom<Value>): DerivedAtom<Value>;
|
|
14
|
+
<Value>(baseAtom: Atom<Value>): Atom<Value>;
|
|
15
|
+
};
|
package/dist/react.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, use, useContext, useMemo,
|
|
3
|
-
import {
|
|
2
|
+
import { createContext, use, useContext, useMemo, useSyncExternalStore } from "react";
|
|
3
|
+
import { createScope } from ".";
|
|
4
4
|
const ScopeContext = createContext((x) => x);
|
|
5
5
|
const ScopeProvider = ({ value, children }) => {
|
|
6
|
-
const parentScope = useContext(ScopeContext);
|
|
6
|
+
const parentScope = value && useContext(ScopeContext);
|
|
7
7
|
const scope = useMemo(() => createScope(parentScope, value), [parentScope]);
|
|
8
8
|
return /* @__PURE__ */ jsx(ScopeContext.Provider, { value: scope, children });
|
|
9
9
|
};
|
|
@@ -28,25 +28,13 @@ const useAtomState = (atom) => (atom = useContext(ScopeContext)(atom), useSyncEx
|
|
|
28
28
|
return atom.state;
|
|
29
29
|
}
|
|
30
30
|
));
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const useLocalAtomValue = (init, options) => useAtomValue(useLocalAtom(init, options));
|
|
34
|
-
const useStateAtom = (atom) => {
|
|
35
|
-
atom = useContext(ScopeContext)(atom);
|
|
36
|
-
const [state, setState] = useState(() => atom.get());
|
|
37
|
-
const setStateWithAtom = (newState) => {
|
|
38
|
-
setState(newState);
|
|
39
|
-
atom.set(newState);
|
|
40
|
-
};
|
|
41
|
-
return [state, setStateWithAtom];
|
|
42
|
-
};
|
|
31
|
+
const useScopedAtom = ((atom) => useContext(ScopeContext)(atom));
|
|
32
|
+
const useAtom = (atom) => (atom = useScopedAtom(atom), [useAtomValue(atom), (newState) => atom.set(newState)]);
|
|
43
33
|
export {
|
|
44
34
|
ScopeContext,
|
|
45
35
|
ScopeProvider,
|
|
46
36
|
useAtom,
|
|
47
37
|
useAtomState,
|
|
48
38
|
useAtomValue,
|
|
49
|
-
|
|
50
|
-
useLocalAtomValue,
|
|
51
|
-
useStateAtom
|
|
39
|
+
useScopedAtom
|
|
52
40
|
};
|