bansa 0.0.43 → 0.0.44

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":";;;;;cAqBa,YAAA,EAAY,KAAA,CAAA,OAAA,CAAA,SAAA;AAAA,cAEZ,aAAA,EACwB,aAAA;AAAA,cAUxB,aAAA,UACX,IAAA,EAAM,WAAA,CAAY,KAAA,GAClB,eAAA,GAAkB,aAAA,YAAoB,WAAA,CAAA,KAAA;AAAA,cAM3B,YAAA,UAAwB,IAAA,EAAM,IAAA,CAAK,KAAA,MAAM,KAAA;AAAA,cAsBzC,YAAA,UAAwB,IAAA,EAAM,WAAA,CAAY,KAAA;;;;;;;;;;;;;;;;;;;;;cA0B1C,OAAA,UAAmB,IAAA,EAAM,aAAA,CAAc,KAAA,gBAAM,KAAA,GAAA,QAAA,EAEf,WAAA,CAAY,KAAA;AAAA,cAI1C,aAAA;EAAiB,KAAA;EAAA;AAAA;EAI5B,KAAA,GAAQ,aAAA;EACR,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA,MACjB,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,KAEW,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,cAGZ,aAAA,EAIP,aAAA;AAAA,cAUO,aAAA,UACX,IAAA,EAAM,WAAA,CAAY,KAAA,GAClB,eAAA,GAAkB,aAAA,YAAoB,WAAA,CAAA,KAAA;AAAA,cAU3B,YAAA,UAAwB,IAAA,EAAM,IAAA,CAAK,KAAA,MAAM,KAAA;AAAA,cAsBzC,YAAA,UAAwB,IAAA,EAAM,WAAA,CAAY,KAAA;;;;;;;;;;;;;;;;;;;;;cA0B1C,OAAA,UAAmB,IAAA,EAAM,aAAA,CAAc,KAAA,gBAAM,KAAA,GAAA,QAAA,EAEf,WAAA,CAAY,KAAA;AAAA,cAI1C,aAAA;EAAiB,KAAA;EAAA;AAAA;EAI5B,KAAA,GAAQ,aAAA;EACR,QAAA,EAAU,KAAA,CAAM,SAAA;AAAA,MACjB,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,KAEW,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
@@ -4,14 +4,23 @@ import { createContext, useCallback, useContext, useMemo, useRef, useSyncExterna
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  //#region src/react.tsx
6
6
  const ScopeContext = createContext((x) => x);
7
- const useScopedAtom = ((atom) => useContext(ScopeContext)(atom));
7
+ const forkedAtomParentMap = /* @__PURE__ */ new WeakMap();
8
+ const useScopedAtom = ((atom) => {
9
+ const scope = useContext(ScopeContext);
10
+ if (forkedAtomParentMap.get(atom) === scope) return atom;
11
+ return scope(atom);
12
+ });
8
13
  const useForkedScope = (injectedEntries) => {
9
14
  const parentScope = useContext(ScopeContext);
10
15
  const deps = injectedEntries?.flat() || [];
11
16
  deps.push(parentScope);
12
17
  return useMemo(() => createScope(injectedEntries && parentScope, injectedEntries), deps);
13
18
  };
14
- const useForkedAtom = (atom, injectedEntries) => useForkedScope(injectedEntries)(atom);
19
+ const useForkedAtom = (atom, injectedEntries) => {
20
+ atom = useForkedScope(injectedEntries)(atom);
21
+ forkedAtomParentMap.set(atom, useContext(ScopeContext));
22
+ return atom;
23
+ };
15
24
  const REACT_USE = (parseInt(version || "19", 10) || 19) >= 19 && "use" in React;
16
25
  const useAtomValue = (atom) => {
17
26
  atom = useScopedAtom(atom);
@@ -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 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 useScopedAtom = (<Value,>(atom: Atom<Value>) =>\n useContext(ScopeContext)(atom)) 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) => useForkedScope(injectedEntries)(atom);\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,>(atom: Atom<Value>) => {\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(subscribe, getSnapshot, getSnapshot);\n};\n\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\nexport const useAtomState = <Value,>(atom: DerivedAtom<Value>) => {\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 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 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":";;;;;AAqBA,MAAa,eAAe,eAA0B,MAAM,EAAS;AAErE,MAAa,kBAA0B,SACrC,WAAW,aAAa,CAAC,KAAK;AAEhC,MAAM,kBAAkB,oBAA2C;CACjE,MAAM,cAAc,WAAW,aAAa;CAC5C,MAAM,OAAO,iBAAiB,MAAM,IAAI,EAAE;AAC1C,MAAK,KAAK,YAAY;A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V,QAAO,qBAAqB,WAAW,aAAa,YAAY;;AAGlE,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;;AAGtC,MAAa,iBAAiB,EAC5B,OACA,eAII,oBAAC,aAAa,UAAd;CAAuB,OAAO,eAAe,MAAM;CAAG;CAAiC,CAAA"}
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\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,>(atom: Atom<Value>) => {\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(subscribe, getSnapshot, getSnapshot);\n};\n\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\nexport const useAtomState = <Value,>(atom: DerivedAtom<Value>) => {\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 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 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>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