bansa 0.0.27 → 0.0.28

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.
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.mts","names":[],"sources":["../src/react.tsx"],"mappings":";;;;;cAaa,YAAA,EAAY,KAAA,CAAA,OAAA,CAAA,SAAA;AAAA,cAEZ,aAAA;EAAiB,KAAA;EAAA;AAAA;EAI5B,KAAA,GAAQ,aAAA;EACR,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA,MACjB,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,cAgBY,YAAA,UAAwB,IAAA,EAAM,IAAA,CAAK,KAAA,MAAM,KAAA;AAAA,cAkBzC,YAAA,UAAwB,IAAA,EAAM,WAAA,CAAY,KAAA;;;;;;;;;;;;;;;;;;;;;cA0B1C,aAAA,EACwB,aAAA;AAAA,cAExB,OAAA,UAAmB,IAAA,EAAM,aAAA,CAAc,KAAA,gBAAM,KAAA,GAAA,QAAA,EAEf,WAAA,CAAY,KAAA;AAAA,KAI3C,aAAA;EAAA,QACF,QAAA,EAAU,aAAA,CAAc,KAAA,IAAS,aAAA,CAAc,KAAA;EAAA,QAC/C,QAAA,EAAU,WAAA,CAAY,KAAA,IAAS,WAAA,CAAY,KAAA;EAAA,QAC3C,QAAA,EAAU,IAAA,CAAK,KAAA,IAAS,IAAA,CAAK,KAAA;AAAA"}
1
+ {"version":3,"file":"react.d.mts","names":[],"sources":["../src/react.tsx"],"mappings":";;;;;cAqBa,YAAA,EAAY,KAAA,CAAA,OAAA,CAAA,SAAA;AAAA,cAEZ,aAAA;EAAiB,KAAA;EAAA;AAAA;EAI5B,KAAA,GAAQ,aAAA;EACR,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA,MACjB,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,cAgBY,YAAA,UAAwB,IAAA,EAAM,IAAA,CAAK,KAAA,MAAM,KAAA;AAAA,cAmBzC,YAAA,UAAwB,IAAA,EAAM,WAAA,CAAY,KAAA;;;;;;;;;;;;;;;;;;;;;cA0B1C,aAAA,EACwB,aAAA;AAAA,cAExB,OAAA,UAAmB,IAAA,EAAM,aAAA,CAAc,KAAA,gBAAM,KAAA,GAAA,QAAA,EAEf,WAAA,CAAY,KAAA;AAAA,KAI3C,aAAA;EAAA,QACF,QAAA,EAAU,aAAA,CAAc,KAAA,IAAS,aAAA,CAAc,KAAA;EAAA,QAC/C,QAAA,EAAU,WAAA,CAAY,KAAA,IAAS,WAAA,CAAY,KAAA;EAAA,QAC3C,QAAA,EAAU,IAAA,CAAK,KAAA,IAAS,IAAA,CAAK,KAAA;AAAA"}
package/dist/react.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createScope } from "./atom.mjs";
2
2
  import * as React from "react";
3
- import { createContext, useContext, useMemo, useRef, useSyncExternalStore, version } from "react";
3
+ import { createContext, useCallback, useContext, useMemo, useRef, useSyncExternalStore, version } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  //#region src/react.tsx
6
6
  const ScopeContext = createContext((x) => x);
@@ -16,7 +16,8 @@ const sameAtomState = (a, b) => a.promise === b.promise && Object.is(a.error, b.
16
16
  const REACT_USE = (parseInt(version || "19", 10) || 19) >= 19 && "use" in React;
17
17
  const useAtomValue = (atom) => {
18
18
  atom = useContext(ScopeContext)(atom);
19
- const getSnapshot = () => {
19
+ const subscribe = useCallback((watcher) => atom.watch(watcher), [atom]);
20
+ const getSnapshot = useCallback(() => {
20
21
  try {
21
22
  return atom.get();
22
23
  } catch (_) {
@@ -27,25 +28,26 @@ const useAtomValue = (atom) => {
27
28
  }
28
29
  throw atom.state.error;
29
30
  }
30
- };
31
- return useSyncExternalStore((watcher) => atom.watch(watcher), getSnapshot, getSnapshot);
31
+ }, [atom]);
32
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
32
33
  };
33
34
  const useAtomState = (atom) => {
34
35
  atom = useContext(ScopeContext)(atom);
35
36
  const stateSnapshot = useRef({ ...atom.state });
36
- const getSnapshot = () => {
37
+ const subscribe = useCallback((watcher) => atom.watch(() => {
38
+ if (!sameAtomState(stateSnapshot.current, atom.state)) {
39
+ stateSnapshot.current = { ...atom.state };
40
+ watcher();
41
+ }
42
+ }), [atom]);
43
+ const getSnapshot = useCallback(() => {
37
44
  try {
38
45
  atom.get();
39
46
  } catch (_) {}
40
47
  if (!sameAtomState(stateSnapshot.current, atom.state)) stateSnapshot.current = { ...atom.state };
41
48
  return stateSnapshot.current;
42
- };
43
- return useSyncExternalStore((watcher) => atom.watch(() => {
44
- if (!sameAtomState(stateSnapshot.current, atom.state)) {
45
- stateSnapshot.current = { ...atom.state };
46
- watcher();
47
- }
48
- }), getSnapshot, getSnapshot);
49
+ }, [atom]);
50
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
49
51
  };
50
52
  const useScopedAtom = ((atom) => useContext(ScopeContext)(atom));
51
53
  const useAtom = (atom) => {
@@ -1 +1 @@
1
- {"version":3,"file":"react.mjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { createContext, useContext, useMemo, useRef, useSyncExternalStore, version } from \"react\";\nimport { createScope } from \"./atom.ts\";\nimport type {\n Atom,\n AtomScope,\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\nexport const ScopeProvider = ({\n value,\n children,\n}: {\n value?: AtomValuePair<unknown>[];\n children: React.ReactNode;\n}) => {\n const parentScope = useContext(ScopeContext);\n const scope = useMemo(\n () => createScope(value && parentScope, value),\n // oxlint-disable-next-line exhaustive-deps\n [parentScope, ...(value || []).flat()],\n );\n return <ScopeContext.Provider value={scope}>{children}</ScopeContext.Provider>;\n};\n\n// TODO: cleanup\nconst sameAtomState = <Value,>(a: AtomState<Value>, b: AtomState<Value>) =>\n a.promise === b.promise && Object.is(a.error, b.error) && Object.is(a.value, b.value);\n\nconst REACT_MAJOR_VERSION = parseInt(version || \"19\", 10) || 19;\nconst REACT_USE = REACT_MAJOR_VERSION >= 19 && \"use\" in React;\nexport const useAtomValue = <Value,>(atom: Atom<Value>) => {\n atom = useContext(ScopeContext)(atom);\n const getSnapshot = () => {\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 };\n return useSyncExternalStore((watcher) => atom.watch(watcher), getSnapshot, getSnapshot);\n};\n\nexport const useAtomState = <Value,>(atom: DerivedAtom<Value>) => {\n atom = useContext(ScopeContext)(atom);\n const stateSnapshot = useRef({ ...atom.state });\n const getSnapshot = () => {\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 };\n return useSyncExternalStore(\n (watcher) =>\n atom.watch(() => {\n if (!sameAtomState(stateSnapshot.current, atom.state)) {\n stateSnapshot.current = { ...atom.state };\n watcher();\n }\n }),\n getSnapshot,\n getSnapshot,\n );\n};\n\nexport const useScopedAtom = (<Value,>(atom: Atom<Value>) =>\n useContext(ScopeContext)(atom)) as UseScopedAtom;\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 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":";;;;;AAaA,MAAa,eAAe,eAA0B,MAAM,EAAS;AAErE,MAAa,iBAAiB,EAC5B,OACA,eAII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,MAAa,kBAA0B,SACrC,WAAW,aAAa,CAAC,KAAK;AAEhC,MAAa,WAAmB,SAA+B;AAC7D,QAAO,cAAc,KAAK;CAC1B,MAAM,UAAU,eAAe,aAAiC,KAAK,IAAI,SAAS,EAAE,CAAC,KAAK,CAAC;AAC3F,QAAO,CAAC,aAAa,KAAK,EAAE,QAAQ"}
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 AtomState,\n AtomUpdater,\n AtomValuePair,\n DerivedAtom,\n PrimitiveAtom,\n} from \"./atom.ts\";\n\nexport const ScopeContext = createContext<AtomScope>((x) => x as any);\n\nexport const ScopeProvider = ({\n value,\n children,\n}: {\n value?: AtomValuePair<unknown>[];\n children: React.ReactNode;\n}) => {\n const parentScope = useContext(ScopeContext);\n const scope = useMemo(\n () => createScope(value && parentScope, value),\n // oxlint-disable-next-line exhaustive-deps\n [parentScope, ...(value || []).flat()],\n );\n return <ScopeContext.Provider value={scope}>{children}</ScopeContext.Provider>;\n};\n\n// TODO: cleanup\nconst sameAtomState = <Value,>(a: AtomState<Value>, b: AtomState<Value>) =>\n a.promise === b.promise && Object.is(a.error, b.error) && Object.is(a.value, b.value);\n\nconst REACT_MAJOR_VERSION = parseInt(version || \"19\", 10) || 19;\nconst REACT_USE = REACT_MAJOR_VERSION >= 19 && \"use\" in React;\nexport const useAtomValue = <Value,>(atom: Atom<Value>) => {\n atom = useContext(ScopeContext)(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(subscribe, getSnapshot, getSnapshot);\n};\n\nexport const useAtomState = <Value,>(atom: DerivedAtom<Value>) => {\n atom = useContext(ScopeContext)(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 getSnapshot = 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 return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n};\n\nexport const useScopedAtom = (<Value,>(atom: Atom<Value>) =>\n useContext(ScopeContext)(atom)) as UseScopedAtom;\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 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":";;;;;AAqBA,MAAa,eAAe,eAA0B,MAAM,EAAS;AAErE,MAAa,iBAAiB,EAC5B,OACA,eAII;CACJ,MAAM,cAAc,WAAW,aAAa;CAC5C,MAAM,QAAQ,cACN,YAAY,SAAS,aAAa,MAAM,EAE9C,CAAC,aAAa,IAAI,SAAS,EAAE,EAAE,MAAM,CAAC,CACvC;AACD,QAAO,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAAQ;EAAiC,CAAA;;AAIhF,MAAM,iBAAyB,GAAqB,MAClD,EAAE,YAAY,EAAE,WAAW,OAAO,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