bansa 0.0.46 → 0.0.48
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.mts +3 -3
- package/dist/react.d.mts.map +1 -1
- package/dist/react.mjs +3 -2
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.d.mts
CHANGED
|
@@ -8,9 +8,9 @@ declare const useScopedAtom: UseScopedAtom;
|
|
|
8
8
|
declare const useForkedAtom: <Value>(atom: DerivedAtom<Value>, injectedEntries?: AtomValuePair<any>[]) => DerivedAtom<Value>;
|
|
9
9
|
declare const useAtomValue: <Value>(atom: Atom<Value>, getServerSnapshot?: null | (() => Value)) => Value;
|
|
10
10
|
type UseAtomState = {
|
|
11
|
-
<Value>(atom: PrimitiveAtom<Value
|
|
12
|
-
<Value>(atom: DerivedAtom<Value
|
|
13
|
-
<Value>(atom: Atom<Value
|
|
11
|
+
<Value>(atom: PrimitiveAtom<Value>, getServerSnapshot?: null | (() => Value)): AtomSuccessState<Value>;
|
|
12
|
+
<Value>(atom: DerivedAtom<Value>, getServerSnapshot?: null | (() => Value)): AtomState<Value>;
|
|
13
|
+
<Value>(atom: Atom<Value>, getServerSnapshot?: null | (() => Value)): AtomState<Value>;
|
|
14
14
|
};
|
|
15
15
|
declare const useAtomState: UseAtomState;
|
|
16
16
|
declare const useAtom: <Value>(atom: PrimitiveAtom<Value>) => readonly [Value, (newState: AtomUpdater<Value>) => void];
|
package/dist/react.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.mts","names":[],"sources":["../src/react.tsx"],"mappings":";;;;;cAsBa,YAAA,EAAY,KAAA,CAAA,OAAA,CAAA,SAAA;AAAA,cAGZ,aAAA,EAIP,aAAA;AAAA,cAUO,aAAA,UACX,IAAA,EAAM,WAAA,CAAY,KAAA,GAClB,eAAA,GAAkB,aAAA,YAAoB,WAAA,CAAA,KAAA;AAAA,cAU3B,YAAA,UAC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,KAAA;AAAA"}
|
package/dist/react.mjs
CHANGED
|
@@ -37,13 +37,14 @@ const useAtomValue = (atom, getServerSnapshot) => {
|
|
|
37
37
|
throw atom.state.error;
|
|
38
38
|
}
|
|
39
39
|
}, [atom]);
|
|
40
|
-
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot === void 0 ? getSnapshot : getServerSnapshot === null ? throwPromise : getServerSnapshot);
|
|
40
|
+
return useSyncExternalStore(getServerSnapshot ? nop : subscribe, getSnapshot, getServerSnapshot === void 0 ? getSnapshot : getServerSnapshot === null ? throwPromise : getServerSnapshot);
|
|
41
41
|
};
|
|
42
42
|
const ssrPromise = new Promise(() => {});
|
|
43
43
|
const throwPromise = () => {
|
|
44
44
|
if (REACT_USE) React.use(ssrPromise);
|
|
45
45
|
throw ssrPromise;
|
|
46
46
|
};
|
|
47
|
+
const nop = () => nop;
|
|
47
48
|
const sameAtomState = (a, b) => a.active === b.active && a.promise === b.promise && Object.is(a.error, b.error) && Object.is(a.value, b.value);
|
|
48
49
|
const useAtomState = ((atom, getServerSnapshot) => {
|
|
49
50
|
atom = useScopedAtom(atom);
|
|
@@ -67,7 +68,7 @@ const useAtomState = ((atom, getServerSnapshot) => {
|
|
|
67
68
|
promise: void 0,
|
|
68
69
|
value: getServerSnapshot()
|
|
69
70
|
} : stateSnapshot.current, [getServerSnapshot]);
|
|
70
|
-
return useSyncExternalStore(subscribe, getStateSnapshot, getServerSnapshot === void 0 ? getStateSnapshot : getServerStateSnapshot);
|
|
71
|
+
return useSyncExternalStore(getServerSnapshot ? nop : subscribe, getStateSnapshot, getServerSnapshot === void 0 ? getStateSnapshot : getServerStateSnapshot);
|
|
71
72
|
});
|
|
72
73
|
const useAtom = (atom) => {
|
|
73
74
|
atom = useScopedAtom(atom);
|
package/dist/react.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useSyncExternalStore,\n version,\n} from \"react\";\nimport { createScope } from \"./atom.ts\";\nimport type {\n Atom,\n AtomScope,\n AtomSuccessState,\n AtomState,\n AtomUpdater,\n AtomValuePair,\n DerivedAtom,\n PrimitiveAtom,\n} from \"./atom.ts\";\n\nexport const ScopeContext = createContext<AtomScope>((x) => x as any);\n\nconst forkedAtomParentMap = new WeakMap<Atom<any>, AtomScope>();\nexport const useScopedAtom = (<Value,>(atom: Atom<Value>) => {\n const scope = useContext(ScopeContext);\n if (forkedAtomParentMap.get(atom) === scope) return atom;\n return scope(atom);\n}) as UseScopedAtom;\n\nconst useForkedScope = (injectedEntries?: AtomValuePair<any>[]) => {\n const parentScope = useContext(ScopeContext);\n const deps = injectedEntries?.flat() || [];\n deps.push(parentScope);\n // oxlint-disable-next-line exhaustive-deps\n return useMemo(() => createScope(injectedEntries && parentScope, injectedEntries), deps);\n};\n\nexport const useForkedAtom = <Value,>(\n atom: DerivedAtom<Value>,\n injectedEntries?: AtomValuePair<any>[],\n) => {\n atom = useForkedScope(injectedEntries)(atom);\n forkedAtomParentMap.set(atom, useContext(ScopeContext));\n return atom;\n};\n\n// TODO: cleanup\nconst REACT_MAJOR_VERSION = parseInt(version || \"19\", 10) || 19;\nconst REACT_USE = REACT_MAJOR_VERSION >= 19 && \"use\" in React;\nexport const useAtomValue = <Value,>(\n atom: Atom<Value>,\n getServerSnapshot?: null | (() => Value),\n) => {\n atom = useScopedAtom(atom);\n const subscribe = useCallback((watcher: () => void) => atom.watch(watcher), [atom]);\n const getSnapshot = useCallback(() => {\n // https://github.com/facebook/react/pull/34032\n try {\n return atom.get();\n } catch (_) {\n if (atom.state.promise) {\n const promise = Promise.resolve(atom.state.promise);\n if (REACT_USE) React.use(promise);\n throw promise;\n }\n throw atom.state.error;\n }\n }, [atom]);\n return useSyncExternalStore(\n subscribe,\n getSnapshot,\n getServerSnapshot === undefined\n ? getSnapshot\n : getServerSnapshot === null\n ? throwPromise\n : getServerSnapshot,\n );\n};\n\nconst ssrPromise = new Promise(() => {});\nconst throwPromise = () => {\n if (REACT_USE) React.use(ssrPromise);\n throw ssrPromise;\n};\nconst sameAtomState = <Value,>(a: AtomState<Value>, b: AtomState<Value>) =>\n a.active === b.active &&\n a.promise === b.promise &&\n Object.is(a.error, b.error) &&\n Object.is(a.value, b.value);\n\ntype UseAtomState = {\n <Value>(atom: PrimitiveAtom<Value
|
|
1
|
+
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useSyncExternalStore,\n version,\n} from \"react\";\nimport { createScope } from \"./atom.ts\";\nimport type {\n Atom,\n AtomScope,\n AtomSuccessState,\n AtomState,\n AtomUpdater,\n AtomValuePair,\n DerivedAtom,\n PrimitiveAtom,\n} from \"./atom.ts\";\n\nexport const ScopeContext = createContext<AtomScope>((x) => x as any);\n\nconst forkedAtomParentMap = new WeakMap<Atom<any>, AtomScope>();\nexport const useScopedAtom = (<Value,>(atom: Atom<Value>) => {\n const scope = useContext(ScopeContext);\n if (forkedAtomParentMap.get(atom) === scope) return atom;\n return scope(atom);\n}) as UseScopedAtom;\n\nconst useForkedScope = (injectedEntries?: AtomValuePair<any>[]) => {\n const parentScope = useContext(ScopeContext);\n const deps = injectedEntries?.flat() || [];\n deps.push(parentScope);\n // oxlint-disable-next-line exhaustive-deps\n return useMemo(() => createScope(injectedEntries && parentScope, injectedEntries), deps);\n};\n\nexport const useForkedAtom = <Value,>(\n atom: DerivedAtom<Value>,\n injectedEntries?: AtomValuePair<any>[],\n) => {\n atom = useForkedScope(injectedEntries)(atom);\n forkedAtomParentMap.set(atom, useContext(ScopeContext));\n return atom;\n};\n\n// TODO: cleanup\nconst REACT_MAJOR_VERSION = parseInt(version || \"19\", 10) || 19;\nconst REACT_USE = REACT_MAJOR_VERSION >= 19 && \"use\" in React;\nexport const useAtomValue = <Value,>(\n atom: Atom<Value>,\n getServerSnapshot?: null | (() => Value),\n) => {\n atom = useScopedAtom(atom);\n const subscribe = useCallback((watcher: () => void) => atom.watch(watcher), [atom]);\n const getSnapshot = useCallback(() => {\n // https://github.com/facebook/react/pull/34032\n try {\n return atom.get();\n } catch (_) {\n if (atom.state.promise) {\n const promise = Promise.resolve(atom.state.promise);\n if (REACT_USE) React.use(promise);\n throw promise;\n }\n throw atom.state.error;\n }\n }, [atom]);\n return useSyncExternalStore(\n getServerSnapshot ? nop : subscribe,\n getSnapshot,\n getServerSnapshot === undefined\n ? getSnapshot\n : getServerSnapshot === null\n ? throwPromise\n : getServerSnapshot,\n );\n};\n\nconst ssrPromise = new Promise(() => {});\nconst throwPromise = () => {\n if (REACT_USE) React.use(ssrPromise);\n throw ssrPromise;\n};\nconst nop = () => nop;\nconst sameAtomState = <Value,>(a: AtomState<Value>, b: AtomState<Value>) =>\n a.active === b.active &&\n a.promise === b.promise &&\n Object.is(a.error, b.error) &&\n Object.is(a.value, b.value);\n\ntype UseAtomState = {\n <Value>(\n atom: PrimitiveAtom<Value>,\n getServerSnapshot?: null | (() => Value),\n ): AtomSuccessState<Value>;\n <Value>(atom: DerivedAtom<Value>, getServerSnapshot?: null | (() => Value)): AtomState<Value>;\n <Value>(atom: Atom<Value>, getServerSnapshot?: null | (() => Value)): AtomState<Value>;\n};\n\nexport const useAtomState = (<Value,>(\n atom: Atom<Value>,\n getServerSnapshot?: null | (() => Value),\n) => {\n atom = useScopedAtom(atom);\n const stateSnapshot = useRef({ ...atom.state });\n const subscribe = useCallback(\n (watcher: () => void) =>\n atom.watch(() => {\n if (!sameAtomState(stateSnapshot.current, atom.state)) {\n stateSnapshot.current = { ...atom.state };\n watcher();\n }\n }),\n [atom],\n );\n const getStateSnapshot = useCallback(() => {\n // avoid https://github.com/facebook/react/issues/31730\n try {\n atom.get();\n } catch (_) {}\n if (!sameAtomState(stateSnapshot.current, atom.state)) {\n stateSnapshot.current = { ...atom.state };\n }\n return stateSnapshot.current;\n }, [atom]);\n const getServerStateSnapshot = useCallback(\n () =>\n getServerSnapshot\n ? {\n active: true,\n error: undefined,\n promise: undefined,\n value: getServerSnapshot(),\n }\n : stateSnapshot.current,\n [getServerSnapshot],\n );\n return useSyncExternalStore(\n getServerSnapshot ? nop : subscribe,\n getStateSnapshot,\n getServerSnapshot === undefined ? getStateSnapshot : getServerStateSnapshot,\n );\n}) as UseAtomState;\n\nexport const useAtom = <Value,>(atom: PrimitiveAtom<Value>) => {\n atom = useScopedAtom(atom);\n const setAtom = useMemo(() => (newState: AtomUpdater<Value>) => atom.set(newState), [atom]);\n return [useAtomValue(atom), setAtom] as const;\n};\n\nexport const ScopeProvider = ({\n value,\n children,\n}: {\n value?: AtomValuePair<any>[];\n children: React.ReactNode;\n}) => <ScopeContext.Provider value={useForkedScope(value)}>{children}</ScopeContext.Provider>;\n\nexport type UseScopedAtom = {\n <Value>(baseAtom: PrimitiveAtom<Value>): PrimitiveAtom<Value>;\n <Value>(baseAtom: DerivedAtom<Value>): DerivedAtom<Value>;\n <Value>(baseAtom: Atom<Value>): Atom<Value>;\n};\n"],"mappings":";;;;;AAsBA,MAAa,eAAe,eAA0B,MAAM,EAAS;AAErE,MAAM,sCAAsB,IAAI,SAA+B;AAC/D,MAAa,kBAA0B,SAAsB;CAC3D,MAAM,QAAQ,WAAW,aAAa;AACtC,KAAI,oBAAoB,IAAI,KAAK,KAAK,MAAO,QAAO;AACpD,QAAO,MAAM,KAAK;;AAGpB,MAAM,kBAAkB,oBAA2C;CACjE,MAAM,cAAc,WAAW,aAAa;CAC5C,MAAM,OAAO,iBAAiB,MAAM,IAAI,EAAE;AAC1C,MAAK,KAAK,YAAY;AAEtB,QAAO,cAAc,YAAY,mBAAmB,aAAa,gBAAgB,EAAE,KAAK;;AAG1F,MAAa,iBACX,MACA,oBACG;AACH,QAAO,eAAe,gBAAgB,CAAC,KAAK;AAC5C,qBAAoB,IAAI,MAAM,WAAW,aAAa,CAAC;AACvD,QAAO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