@iadev93/zuno-react 0.0.9 → 0.0.11
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/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var zuno=require('@iadev93/zuno'),e=require('react');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var e__namespace=/*#__PURE__*/_interopNamespace(e);var l=Object.is,R=a=>{let T=(r,u,n=l)=>{let o=e__namespace.useMemo(()=>u??(t=>t),[u]),s=e__namespace.useRef(null),c=e__namespace.useRef(false),i=e__namespace.useCallback(()=>{let t=o(r.getSnapshot());if(!c.current)return c.current=true,s.current=t,t;let S=s.current;return n(S,t)?S:(s.current=t,t)},[r,o,n]),p=e__namespace.useCallback(t=>r.subscribe(t),[r]),d=e__namespace.useCallback(()=>{let t=r.getServerSnapshot?r.getServerSnapshot():r.getSnapshot();return o(t)},[r,o]);return e__namespace.useEffect(()=>{c.current=false,s.current=null;},[o,n]),e__namespace.useSyncExternalStore(p,i,d)};return {...a,store:(r,u)=>{let n=a.store(r,u);return {...n,use:(o,s=l)=>{let c=e__namespace.useMemo(()=>zuno.toReadable(n.raw()),[]);return T(c,o,s)}}}}},x=a=>{let T=zuno.createZuno(a);return R(T)};exports.bindReact=R;exports.createZunoReact=x;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["defaultEq","bindReact","zuno","useExternalStore","readable","selector","equalityFn","select","e","s","lastRef","hasLast","getSnapshot","next","prev","subscribe","onChange","getServerSnapshot","storeKey","init","base","toReadable","createZunoReact","opts","createZuno"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["defaultEq","bindReact","zuno","useExternalStore","readable","selector","equalityFn","select","e","s","lastRef","hasLast","getSnapshot","next","prev","subscribe","onChange","getServerSnapshot","storeKey","init","base","toReadable","createZunoReact","opts","createZuno"],"mappings":"waA4BA,IAAMA,CAAAA,CAA6B,OAAO,EAAA,CAgD7BC,CAAAA,CAAaC,GAAmB,CAI5C,IAAMC,EAAmB,CACxBC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAAoCN,CAAAA,GACrB,CACf,IAAMO,CAAAA,CAAeC,YAAA,CAAA,OAAA,CAAQ,IACpBH,CAAAA,GACLI,CAAAA,EAAcA,GAIf,CAACJ,CAAQ,CAAC,CAAA,CAEPK,CAAAA,CAAgBF,YAAA,CAAA,MAAA,CAAyB,IAAI,CAAA,CAC7CG,CAAAA,CAAgBH,oBAAO,KAAK,CAAA,CAE5BI,EAAoBJ,YAAA,CAAA,WAAA,CAAY,IAAM,CAC3C,IAAMK,CAAAA,CAAON,CAAAA,CAAOH,EAAS,WAAA,EAAa,EAE1C,GAAI,CAACO,EAAQ,OAAA,CACZ,OAAAA,CAAAA,CAAQ,OAAA,CAAU,IAAA,CAClBD,CAAAA,CAAQ,QAAUG,CAAAA,CACXA,CAAAA,CAGR,IAAMC,CAAAA,CAAOJ,CAAAA,CAAQ,QACrB,OAAIJ,CAAAA,CAAWQ,CAAAA,CAAMD,CAAI,CAAA,CAAUC,CAAAA,EAEnCJ,EAAQ,OAAA,CAAUG,CAAAA,CACXA,EAER,CAAA,CAAG,CAACT,EAAUG,CAAAA,CAAQD,CAAU,CAAC,CAAA,CAE3BS,CAAAA,CAAkBP,YAAA,CAAA,WAAA,CACtBQ,GAAyBZ,CAAAA,CAAS,SAAA,CAAUY,CAAQ,CAAA,CACrD,CAACZ,CAAQ,CACV,CAAA,CAGMa,CAAAA,CAA0BT,YAAA,CAAA,WAAA,CAAY,IAAM,CACjD,IAAMC,CAAAA,CAAIL,CAAAA,CAAS,kBAChBA,CAAAA,CAAS,iBAAA,GACTA,CAAAA,CAAS,WAAA,EAAY,CACxB,OAAOG,CAAAA,CAAOE,CAAC,CAChB,CAAA,CAAG,CAACL,EAAUG,CAAM,CAAC,EAGrB,OAAMC,YAAA,CAAA,SAAA,CAAU,IAAM,CACrBG,CAAAA,CAAQ,OAAA,CAAU,MAClBD,CAAAA,CAAQ,OAAA,CAAU,KACnB,CAAA,CAAG,CAACH,EAAQD,CAAU,CAAC,CAAA,CAEVE,YAAA,CAAA,oBAAA,CACZO,CAAAA,CACAH,CAAAA,CACAK,CACD,CACD,CAAA,CAuBA,OAAO,CACN,GAAGf,EACH,KAAA,CApBa,CAAIgB,CAAAA,CAAkBC,CAAAA,GAAsC,CACzE,IAAMC,EAAOlB,CAAAA,CAAK,KAAA,CAASgB,EAAUC,CAAI,CAAA,CAEzC,OAAO,CACN,GAAGC,CAAAA,CACH,GAAA,CAAK,CACJf,CAAAA,CACAC,EAAoCN,CAAAA,GAChC,CACJ,IAAMI,CAAAA,CAAiBI,YAAA,CAAA,OAAA,CACtB,IAAMa,eAAAA,CAAWD,CAAAA,CAAK,GAAA,EAAiC,CAAA,CACvD,EACD,CAAA,CACA,OAAOjB,EAA+BC,CAAAA,CAAUC,CAAAA,CAAUC,CAAU,CACrE,CACD,CACD,CAKA,CACD,CAAA,CAQagB,EAAmBC,CAAAA,EAA4B,CAC3D,IAAMrB,CAAAA,CAAOsB,eAAAA,CAAWD,CAAI,CAAA,CAC5B,OAAOtB,CAAAA,CAAUC,CAAI,CACtB","file":"index.js","sourcesContent":["import {\n\ttype CreateZunoOptions,\n\tcreateZuno,\n\ttoReadable,\n\ttype ZunoReadable,\n\ttype ZunoSubscribableStore,\n} from \"@iadev93/zuno\";\nimport * as React from \"react\";\n\n/**\n * Type definition for an equality function.\n * It takes two values of the same type and returns true if they are considered equal, false otherwise.\n * Used to prevent unnecessary re-renders in React hooks when the selected state hasn't \"meaningfully\" changed.\n */\nexport type EqualityFn<T> = (a: T, b: T) => boolean;\n\n/**\n * Type definition for a selector function.\n * It takes the full state of a store and returns a selected portion of that state.\n * This allows components to subscribe only to the parts of the state they care about,\n * optimizing performance by avoiding re-renders for unrelated state changes.\n */\nexport type Selector<TState, TSelected> = (state: TState) => TSelected;\n\n/**\n * The default equality function, using `Object.is` for strict equality comparison.\n * This is a common and safe default for comparing primitive values and references.\n */\nconst defaultEq: EqualityFn<any> = Object.is;\n\n/**\n * An extended interface for a Zuno store that includes methods for setting state\n * and a unique key identifier. This represents a store that has been \"bound\" or registered.\n */\nexport type BoundStore<T> = {\n\tkey: string;\n\tget: () => T;\n\tset: (next: T | ((prev: T) => T)) => Promise<any>;\n\tsubscribe: (cb: (state: T) => void) => () => void;\n\traw: () => ZunoSubscribableStore<T>;\n};\n\n/**\n * The core interface for the Zuno library, providing methods to create,\n * retrieve, and update stores.\n */\nexport type ZunoCore = {\n\tstore<T>(storeKey: string, init: () => T): BoundStore<T>;\n\tset<T>(\n\t\tstoreKey: string,\n\t\tnext: T | ((prev: T) => T),\n\t\tinit?: () => T,\n\t): Promise<any>;\n\tget<T>(storeKey: string, init?: () => T): T;\n\tstop?: () => void;\n};\n\n/**\n * An extended interface for a Zuno store that includes React-specific features.\n */\nexport type ReactBoundStore<T> = BoundStore<T> & {\n\t/**\n\t * React hook for this store.\n\t * Optional selector + equality for derived values and avoiding rerenders.\n\t */\n\tuse: <TSelected = T>(\n\t\tselector?: Selector<T, TSelected>,\n\t\tequalityFn?: EqualityFn<TSelected>,\n\t) => TSelected;\n};\n\n/**\n * Binds Zuno to React.\n * @param zuno The Zuno instance to bind.\n * @returns A React-enhanced Zuno instance.\n */\nexport const bindReact = (zuno: ZunoCore) => {\n\t/**\n\t * A custom hook for accessing a Zuno store in a React component.\n\t */\n\tconst useExternalStore = <TState, TSelected = TState>(\n\t\treadable: ZunoReadable<TState>,\n\t\tselector?: Selector<TState, TSelected>,\n\t\tequalityFn: EqualityFn<TSelected> = defaultEq,\n\t): TSelected => {\n\t\tconst select = React.useMemo(() => {\n\t\t\treturn (selector ??\n\t\t\t\t((s: TState) => s as unknown as TSelected)) as Selector<\n\t\t\t\tTState,\n\t\t\t\tTSelected\n\t\t\t>;\n\t\t}, [selector]);\n\n\t\tconst lastRef = React.useRef<TSelected | null>(null);\n\t\tconst hasLast = React.useRef(false);\n\n\t\tconst getSnapshot = React.useCallback(() => {\n\t\t\tconst next = select(readable.getSnapshot());\n\n\t\t\tif (!hasLast.current) {\n\t\t\t\thasLast.current = true;\n\t\t\t\tlastRef.current = next;\n\t\t\t\treturn next;\n\t\t\t}\n\n\t\t\tconst prev = lastRef.current as TSelected;\n\t\t\tif (equalityFn(prev, next)) return prev;\n\n\t\t\tlastRef.current = next;\n\t\t\treturn next;\n\t\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: select and equalityFn are local/stable\n\t\t}, [readable, select, equalityFn]);\n\n\t\tconst subscribe = React.useCallback(\n\t\t\t(onChange: () => void) => readable.subscribe(onChange),\n\t\t\t[readable],\n\t\t);\n\n\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: select is local/stable\n\t\tconst getServerSnapshot = React.useCallback(() => {\n\t\t\tconst s = readable.getServerSnapshot\n\t\t\t\t? readable.getServerSnapshot()\n\t\t\t\t: readable.getSnapshot();\n\t\t\treturn select(s);\n\t\t}, [readable, select]);\n\n\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: select and equalityFn are local/stable\n\t\tReact.useEffect(() => {\n\t\t\thasLast.current = false;\n\t\t\tlastRef.current = null;\n\t\t}, [select, equalityFn]);\n\n\t\treturn React.useSyncExternalStore(\n\t\t\tsubscribe,\n\t\t\tgetSnapshot,\n\t\t\tgetServerSnapshot,\n\t\t);\n\t};\n\n\t/**\n\t * Creates a React-enhanced store.\n\t */\n\tconst store = <T>(storeKey: string, init: () => T): ReactBoundStore<T> => {\n\t\tconst base = zuno.store<T>(storeKey, init);\n\n\t\treturn {\n\t\t\t...base,\n\t\t\tuse: <TSelected = T>(\n\t\t\t\tselector?: Selector<T, TSelected>,\n\t\t\t\tequalityFn: EqualityFn<TSelected> = defaultEq,\n\t\t\t) => {\n\t\t\t\tconst readable = React.useMemo(\n\t\t\t\t\t() => toReadable(base.raw() as ZunoSubscribableStore<T>),\n\t\t\t\t\t[],\n\t\t\t\t);\n\t\t\t\treturn useExternalStore<T, TSelected>(readable, selector, equalityFn);\n\t\t\t},\n\t\t};\n\t};\n\n\treturn {\n\t\t...zuno,\n\t\tstore,\n\t};\n};\n\n/**\n * Creates a Zuno instance and returns a React-enhanced instance.\n *\n * @param opts The options for the Zuno instance.\n * @returns An object with a `store` method that returns stores with a `use` hook.\n */\nexport const createZunoReact = (opts: CreateZunoOptions) => {\n\tconst zuno = createZuno(opts);\n\treturn bindReact(zuno);\n};\n\n// Convenience re-export\nexport type { ZunoReadable } from \"@iadev93/zuno\";\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {toReadable,createZuno}from'@iadev93/zuno';import*as e from'react';var l=Object.is,R=a=>{let T=(r,u,n=l)=>{let o=e.useMemo(()=>u??(t=>t),[u]),s=e.useRef(null),c=e.useRef(false),i=e.useCallback(()=>{let t=o(r.getSnapshot());if(!c.current)return c.current=true,s.current=t,t;let S=s.current;return n(S,t)?S:(s.current=t,t)},[r,o,n]),p=e.useCallback(t=>r.subscribe(t),[r]),d=e.useCallback(()=>{let t=r.getServerSnapshot?r.getServerSnapshot():r.getSnapshot();return o(t)},[r,o]);return e.useEffect(()=>{c.current=false,s.current=null;},[o,n]),e.useSyncExternalStore(p,i,d)};return {...a,store:(r,u)=>{let n=a.store(r,u);return {...n,use:(o,s=l)=>{let c=e.useMemo(()=>toReadable(n.raw()),[]);return T(c,o,s)}}}}},x=a=>{let T=createZuno(a);return R(T)};export{R as bindReact,x as createZunoReact};//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["defaultEq","bindReact","zuno","useExternalStore","readable","selector","equalityFn","select","s","lastRef","hasLast","getSnapshot","next","prev","subscribe","onChange","getServerSnapshot","storeKey","init","base","toReadable","createZunoReact","opts","createZuno"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["defaultEq","bindReact","zuno","useExternalStore","readable","selector","equalityFn","select","s","lastRef","hasLast","getSnapshot","next","prev","subscribe","onChange","getServerSnapshot","storeKey","init","base","toReadable","createZunoReact","opts","createZuno"],"mappings":"0EA4BA,IAAMA,CAAAA,CAA6B,OAAO,EAAA,CAgD7BC,CAAAA,CAAaC,GAAmB,CAI5C,IAAMC,EAAmB,CACxBC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CAAoCN,CAAAA,GACrB,CACf,IAAMO,CAAAA,CAAe,CAAA,CAAA,OAAA,CAAQ,IACpBF,CAAAA,GACLG,CAAAA,EAAcA,GAIf,CAACH,CAAQ,CAAC,CAAA,CAEPI,CAAAA,CAAgB,CAAA,CAAA,MAAA,CAAyB,IAAI,CAAA,CAC7CC,CAAAA,CAAgB,SAAO,KAAK,CAAA,CAE5BC,EAAoB,CAAA,CAAA,WAAA,CAAY,IAAM,CAC3C,IAAMC,CAAAA,CAAOL,CAAAA,CAAOH,EAAS,WAAA,EAAa,EAE1C,GAAI,CAACM,EAAQ,OAAA,CACZ,OAAAA,CAAAA,CAAQ,OAAA,CAAU,IAAA,CAClBD,CAAAA,CAAQ,QAAUG,CAAAA,CACXA,CAAAA,CAGR,IAAMC,CAAAA,CAAOJ,CAAAA,CAAQ,QACrB,OAAIH,CAAAA,CAAWO,CAAAA,CAAMD,CAAI,CAAA,CAAUC,CAAAA,EAEnCJ,EAAQ,OAAA,CAAUG,CAAAA,CACXA,EAER,CAAA,CAAG,CAACR,EAAUG,CAAAA,CAAQD,CAAU,CAAC,CAAA,CAE3BQ,CAAAA,CAAkB,CAAA,CAAA,WAAA,CACtBC,GAAyBX,CAAAA,CAAS,SAAA,CAAUW,CAAQ,CAAA,CACrD,CAACX,CAAQ,CACV,CAAA,CAGMY,CAAAA,CAA0B,CAAA,CAAA,WAAA,CAAY,IAAM,CACjD,IAAMR,CAAAA,CAAIJ,CAAAA,CAAS,kBAChBA,CAAAA,CAAS,iBAAA,GACTA,CAAAA,CAAS,WAAA,EAAY,CACxB,OAAOG,CAAAA,CAAOC,CAAC,CAChB,CAAA,CAAG,CAACJ,EAAUG,CAAM,CAAC,EAGrB,OAAM,CAAA,CAAA,SAAA,CAAU,IAAM,CACrBG,CAAAA,CAAQ,OAAA,CAAU,MAClBD,CAAAA,CAAQ,OAAA,CAAU,KACnB,CAAA,CAAG,CAACF,EAAQD,CAAU,CAAC,CAAA,CAEV,CAAA,CAAA,oBAAA,CACZQ,CAAAA,CACAH,CAAAA,CACAK,CACD,CACD,CAAA,CAuBA,OAAO,CACN,GAAGd,EACH,KAAA,CApBa,CAAIe,CAAAA,CAAkBC,CAAAA,GAAsC,CACzE,IAAMC,EAAOjB,CAAAA,CAAK,KAAA,CAASe,EAAUC,CAAI,CAAA,CAEzC,OAAO,CACN,GAAGC,CAAAA,CACH,GAAA,CAAK,CACJd,CAAAA,CACAC,EAAoCN,CAAAA,GAChC,CACJ,IAAMI,CAAAA,CAAiB,CAAA,CAAA,OAAA,CACtB,IAAMgB,UAAAA,CAAWD,CAAAA,CAAK,GAAA,EAAiC,CAAA,CACvD,EACD,CAAA,CACA,OAAOhB,EAA+BC,CAAAA,CAAUC,CAAAA,CAAUC,CAAU,CACrE,CACD,CACD,CAKA,CACD,CAAA,CAQae,EAAmBC,CAAAA,EAA4B,CAC3D,IAAMpB,CAAAA,CAAOqB,UAAAA,CAAWD,CAAI,CAAA,CAC5B,OAAOrB,CAAAA,CAAUC,CAAI,CACtB","file":"index.mjs","sourcesContent":["import {\n\ttype CreateZunoOptions,\n\tcreateZuno,\n\ttoReadable,\n\ttype ZunoReadable,\n\ttype ZunoSubscribableStore,\n} from \"@iadev93/zuno\";\nimport * as React from \"react\";\n\n/**\n * Type definition for an equality function.\n * It takes two values of the same type and returns true if they are considered equal, false otherwise.\n * Used to prevent unnecessary re-renders in React hooks when the selected state hasn't \"meaningfully\" changed.\n */\nexport type EqualityFn<T> = (a: T, b: T) => boolean;\n\n/**\n * Type definition for a selector function.\n * It takes the full state of a store and returns a selected portion of that state.\n * This allows components to subscribe only to the parts of the state they care about,\n * optimizing performance by avoiding re-renders for unrelated state changes.\n */\nexport type Selector<TState, TSelected> = (state: TState) => TSelected;\n\n/**\n * The default equality function, using `Object.is` for strict equality comparison.\n * This is a common and safe default for comparing primitive values and references.\n */\nconst defaultEq: EqualityFn<any> = Object.is;\n\n/**\n * An extended interface for a Zuno store that includes methods for setting state\n * and a unique key identifier. This represents a store that has been \"bound\" or registered.\n */\nexport type BoundStore<T> = {\n\tkey: string;\n\tget: () => T;\n\tset: (next: T | ((prev: T) => T)) => Promise<any>;\n\tsubscribe: (cb: (state: T) => void) => () => void;\n\traw: () => ZunoSubscribableStore<T>;\n};\n\n/**\n * The core interface for the Zuno library, providing methods to create,\n * retrieve, and update stores.\n */\nexport type ZunoCore = {\n\tstore<T>(storeKey: string, init: () => T): BoundStore<T>;\n\tset<T>(\n\t\tstoreKey: string,\n\t\tnext: T | ((prev: T) => T),\n\t\tinit?: () => T,\n\t): Promise<any>;\n\tget<T>(storeKey: string, init?: () => T): T;\n\tstop?: () => void;\n};\n\n/**\n * An extended interface for a Zuno store that includes React-specific features.\n */\nexport type ReactBoundStore<T> = BoundStore<T> & {\n\t/**\n\t * React hook for this store.\n\t * Optional selector + equality for derived values and avoiding rerenders.\n\t */\n\tuse: <TSelected = T>(\n\t\tselector?: Selector<T, TSelected>,\n\t\tequalityFn?: EqualityFn<TSelected>,\n\t) => TSelected;\n};\n\n/**\n * Binds Zuno to React.\n * @param zuno The Zuno instance to bind.\n * @returns A React-enhanced Zuno instance.\n */\nexport const bindReact = (zuno: ZunoCore) => {\n\t/**\n\t * A custom hook for accessing a Zuno store in a React component.\n\t */\n\tconst useExternalStore = <TState, TSelected = TState>(\n\t\treadable: ZunoReadable<TState>,\n\t\tselector?: Selector<TState, TSelected>,\n\t\tequalityFn: EqualityFn<TSelected> = defaultEq,\n\t): TSelected => {\n\t\tconst select = React.useMemo(() => {\n\t\t\treturn (selector ??\n\t\t\t\t((s: TState) => s as unknown as TSelected)) as Selector<\n\t\t\t\tTState,\n\t\t\t\tTSelected\n\t\t\t>;\n\t\t}, [selector]);\n\n\t\tconst lastRef = React.useRef<TSelected | null>(null);\n\t\tconst hasLast = React.useRef(false);\n\n\t\tconst getSnapshot = React.useCallback(() => {\n\t\t\tconst next = select(readable.getSnapshot());\n\n\t\t\tif (!hasLast.current) {\n\t\t\t\thasLast.current = true;\n\t\t\t\tlastRef.current = next;\n\t\t\t\treturn next;\n\t\t\t}\n\n\t\t\tconst prev = lastRef.current as TSelected;\n\t\t\tif (equalityFn(prev, next)) return prev;\n\n\t\t\tlastRef.current = next;\n\t\t\treturn next;\n\t\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: select and equalityFn are local/stable\n\t\t}, [readable, select, equalityFn]);\n\n\t\tconst subscribe = React.useCallback(\n\t\t\t(onChange: () => void) => readable.subscribe(onChange),\n\t\t\t[readable],\n\t\t);\n\n\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: select is local/stable\n\t\tconst getServerSnapshot = React.useCallback(() => {\n\t\t\tconst s = readable.getServerSnapshot\n\t\t\t\t? readable.getServerSnapshot()\n\t\t\t\t: readable.getSnapshot();\n\t\t\treturn select(s);\n\t\t}, [readable, select]);\n\n\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: select and equalityFn are local/stable\n\t\tReact.useEffect(() => {\n\t\t\thasLast.current = false;\n\t\t\tlastRef.current = null;\n\t\t}, [select, equalityFn]);\n\n\t\treturn React.useSyncExternalStore(\n\t\t\tsubscribe,\n\t\t\tgetSnapshot,\n\t\t\tgetServerSnapshot,\n\t\t);\n\t};\n\n\t/**\n\t * Creates a React-enhanced store.\n\t */\n\tconst store = <T>(storeKey: string, init: () => T): ReactBoundStore<T> => {\n\t\tconst base = zuno.store<T>(storeKey, init);\n\n\t\treturn {\n\t\t\t...base,\n\t\t\tuse: <TSelected = T>(\n\t\t\t\tselector?: Selector<T, TSelected>,\n\t\t\t\tequalityFn: EqualityFn<TSelected> = defaultEq,\n\t\t\t) => {\n\t\t\t\tconst readable = React.useMemo(\n\t\t\t\t\t() => toReadable(base.raw() as ZunoSubscribableStore<T>),\n\t\t\t\t\t[],\n\t\t\t\t);\n\t\t\t\treturn useExternalStore<T, TSelected>(readable, selector, equalityFn);\n\t\t\t},\n\t\t};\n\t};\n\n\treturn {\n\t\t...zuno,\n\t\tstore,\n\t};\n};\n\n/**\n * Creates a Zuno instance and returns a React-enhanced instance.\n *\n * @param opts The options for the Zuno instance.\n * @returns An object with a `store` method that returns stores with a `use` hook.\n */\nexport const createZunoReact = (opts: CreateZunoOptions) => {\n\tconst zuno = createZuno(opts);\n\treturn bindReact(zuno);\n};\n\n// Convenience re-export\nexport type { ZunoReadable } from \"@iadev93/zuno\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iadev93/zuno-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -11,18 +11,19 @@
|
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"peerDependencies": {
|
|
18
19
|
"react": ">=18",
|
|
19
|
-
"@iadev93/zuno": "0.0.
|
|
20
|
+
"@iadev93/zuno": "0.0.8"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@types/react": "^18.0.0",
|
|
23
24
|
"tsup": "^8.5.1",
|
|
24
25
|
"typescript": "^5.9.3",
|
|
25
|
-
"@iadev93/zuno": "0.0.
|
|
26
|
+
"@iadev93/zuno": "0.0.8"
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|
|
28
29
|
"zuno",
|