state-jet 2.2.3 → 2.4.0
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.cjs +1 -19
- package/dist/index.mjs +1 -19
- package/package.json +3 -10
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=
|
|
2
|
-
/**
|
|
3
|
-
* @license React
|
|
4
|
-
* use-sync-external-store-shim.production.js
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/var Z,ee,te={};
|
|
11
|
-
/**
|
|
12
|
-
* @license React
|
|
13
|
-
* use-sync-external-store-shim.development.js
|
|
14
|
-
*
|
|
15
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
-
*
|
|
17
|
-
* This source code is licensed under the MIT license found in the
|
|
18
|
-
* LICENSE file in the root directory of this source tree.
|
|
19
|
-
*/var re=(ee||(ee=1,"production"===process.env.NODE_ENV?Y.exports=function(){if(X)return Q;X=1;var t=e,r="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=t.useState,o=t.useEffect,a=t.useLayoutEffect,s=t.useDebugValue;function i(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}var c=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?function(e,t){return t()}:function(e,t){var r=t(),c=n({inst:{value:r,getSnapshot:t}}),u=c[0].inst,f=c[1];return a((function(){u.value=r,u.getSnapshot=t,i(u)&&f({inst:u})}),[e,r,t]),o((function(){return i(u)&&f({inst:u}),e((function(){i(u)&&f({inst:u})}))}),[e]),s(r),r};return Q.useSyncExternalStore=void 0!==t.useSyncExternalStore?t.useSyncExternalStore:c,Q}():Y.exports=(Z||(Z=1,"production"!==process.env.NODE_ENV&&function(){function t(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch{return!0}}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=e,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=r.useState,a=r.useEffect,s=r.useLayoutEffect,i=r.useDebugValue,c=!1,u=!1,f=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?function(e,t){return t()}:function(e,f){c||void 0===r.startTransition||(c=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=f();if(!u){var p=f();n(l,p)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var d=(p=o({inst:{value:l,getSnapshot:f}}))[0].inst,_=p[1];return s((function(){d.value=l,d.getSnapshot=f,t(d)&&_({inst:d})}),[e,l,f]),a((function(){return t(d)&&_({inst:d}),e((function(){t(d)&&_({inst:d})}))}),[e]),i(l),l};te.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:f,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),te)),Y.exports);const ne={},oe={},ae={},se=B.__STATE_JET_DEVTOOLS__,ie=(e,t)=>{ne[e]||(ne[e]=[]),void 0===oe[e]&&(oe[e]=-1),ne[e]=ne[e].slice(0,oe[e]+1),ne[e].push(t),oe[e]++,se?.updateState&&se.updateState(e,t,[...ne[e]])},ce=(e,t)=>{ae[e]||(ae[e]=[]);const r=performance.now();t();const n=performance.now()-r;ae[e].push(n),se?.updatePerformance&&se.updatePerformance(e,n)},ue=new Set,fe=new Map,le=new Map,pe={};let de=!1;const _e=e=>(fe.has(e)||fe.set(e,{}),(t,r,n)=>{const o=fe.get(e),a=`${e}:${t}`;if(!o[t]){let e=r;n?.persist&&(e=n?.encrypt?W(a,r):J(a,r)),o[t]={value:e,listeners:new Set,...n}}const s=o[t],i=async()=>{de=!1;const e=Array.from(le.entries());le.clear();for(const[t,r]of e){const[e,n]=t.split(":"),o=fe.get(e);if(!o)continue;const a=o[n];if(!a)continue;if(ue.has(t)){console.warn(`[state-jet] Skipping recursive middleware for: ${t}`);continue}let s=r;const i=a.value;if(pe[t]||(pe[t]={past:[],present:i,future:[]}),pe[t].past.push(i),pe[t].present=s,pe[t].future=[],ue.add(t),a?.middleware)for(const e of a.middleware)try{console.log(`[state-jet] Running middleware for ${t}`);const r=e(t,i,s,(e=>{s=e}));if(void 0!==r)if(r instanceof Promise){const e=await r;void 0!==e&&(s=e)}else s=r}catch(e){console.error(`[state-jet] Middleware error in ${t}:`,e)}ue.delete(t),"function"==typeof s?a.value=U(a.value,s):i!==s&&(a.value=s,a.listeners.forEach((e=>e())),ie(`${e}.${n}`,s),ce(`${e}.${n}`,(()=>{})),a?.persist&&(a?.encrypt?q(t,s):H(t,s)))}};return{useState:()=>re.useSyncExternalStore((e=>(s.listeners.add(e),()=>s.listeners.delete(e))),(()=>s.value)),set:async(r,n=!1)=>{const o=s.value,c="function"==typeof r?r(o):r;if(n)return s.value=c,s.listeners.forEach((e=>e())),void ie(`${e}.${t}`,c);le.set(a,c),de||(de=!0,s.frameSync&&B?.requestAnimationFrame?await new Promise((e=>B.requestAnimationFrame((()=>e(i()))))):await i())},get:()=>s.value,undo:()=>{pe[a]?.past.length&&(pe[a].future.unshift(pe[a].present),pe[a].present=pe[a].past.pop(),s.value=pe[a].present,s.listeners.forEach((e=>e())),(e=>{if(oe[e]>0)oe[e]--,ne[e][oe[e]]})(a),ie(`${e}.undo`,pe[a].present))},redo:()=>{pe[a]?.future.length&&(pe[a].past.push(pe[a].present),pe[a].present=pe[a].future.shift(),s.value=pe[a].present,s.listeners.forEach((e=>e())),(e=>{if(oe[e]<ne[e]?.length-1)oe[e]++,ne[e][oe[e]]})(a),ie(`${e}.redo`,pe[a].present))},clear:()=>{s.value=r,fe.clear(),Object.keys(pe).forEach((e=>delete pe[e])),ie(`${e}.clear`,r)}}}),ye=(e,t)=>({...e,...t,lastUpdated:Date.now()});exports.derivedState=(e,t)=>()=>{const r=e.map((e=>e.useState()));return t(...r)},exports.mergeCRDT=ye,exports.optimisticUpdate=async(e,t,r,n)=>{const o=e.useState(),a=t(o);e.set(a);try{await r()}catch(t){console.error("API request failed:",t),e.set(n?n(o):o)}},exports.restoreEncryptedState=W,exports.restoreState=J,exports.saveEncryptedState=q,exports.saveState=H,exports.syncCRDT=(e,t)=>{const r=t.useState(),n=ye(r,e);t.set(n)},exports.useSlice=_e,exports.useStateGlobal=(e,t,r)=>_e("global")(e,t,r),exports.useStore=t=>{const r=e.useRef(null);return r.current||(r.current=t()),r.current};
|
|
1
|
+
"use strict";var e=require("react"),t=require("immer"),r=require("use-sync-external-store/shim");const o=(()=>{if("object"==typeof globalThis&&globalThis)return globalThis;if("object"==typeof self&&self)return self;if("object"==typeof window&&window)return window;if(typeof global<"u"&&"object"==typeof global&&global)return global;throw new Error("Unable to locate global `this`")})(),s=(e,t)=>{typeof o?.localStorage<"u"&&o.localStorage.setItem(e,JSON.stringify(t))},a=(e,t)=>{if(typeof o?.localStorage<"u"){const r=o.localStorage?.getItem(e);return r?JSON.parse(r):t}return t},n=(e,t)=>{typeof o?.localStorage<"u"&&o.localStorage.setItem(e,(e=>btoa(JSON.stringify(e)))(t))},l=(e,t)=>{if(typeof o?.localStorage<"u"){const r=o.localStorage?.getItem(e);return r?(e=>JSON.parse(atob(e)))(r):t}return t},c={},i={},u={},p=o.__STATE_JET_DEVTOOLS__,f=(e,t)=>{c[e]||(c[e]=[]),void 0===i[e]&&(i[e]=-1),c[e]=c[e].slice(0,i[e]+1),c[e].push(t),i[e]++,p?.updateState&&p.updateState(e,t,[...c[e]])},d=(e,t)=>{u[e]||(u[e]=[]);const r=performance.now();t();const o=performance.now()-r;u[e].push(o),p?.updatePerformance&&p.updatePerformance(e,o)},S=new Set,g=new Map,y=new Map,m={};let w=!1;const h=e=>(g.has(e)||g.set(e,{}),(u,p,h)=>{const v=g.get(e),b=`${e}:${u}`;if(!v[u]){let e=p;h?.persist&&(e=h?.encrypt?l(b,p):a(b,p)),v[u]={value:e,listeners:new Set,...h}}const $=v[u],x=async()=>{w=!1;const e=Array.from(y.entries());y.clear();for(const[r,o]of e){const[e,a]=r.split(":"),l=g.get(e);if(!l)continue;const c=l[a];if(!c)continue;if(S.has(r)){console.warn(`[state-jet] Skipping recursive middleware for: ${r}`);continue}let i=o;const u=c.value;if(m[r]||(m[r]={past:[],present:u,future:[]}),m[r].past.push(u),m[r].present=i,m[r].future=[],S.add(r),c?.middleware)for(const e of c.middleware)try{console.log(`[state-jet] Running middleware for ${r}`);const t=e(r,u,i,(e=>{i=e}));if(void 0!==t)if(t instanceof Promise){const e=await t;void 0!==e&&(i=e)}else i=t}catch(e){console.error(`[state-jet] Middleware error in ${r}:`,e)}S.delete(r),"function"==typeof i?c.value=t.produce(c.value,i):u!==i&&(c.value=i,c.listeners.forEach((e=>e())),f(`${e}.${a}`,i),d(`${e}.${a}`,(()=>{})),c?.persist&&(c?.encrypt?n(r,i):s(r,i)))}};return{useState:()=>r.useSyncExternalStore((e=>($.listeners.add(e),()=>$.listeners.delete(e))),(()=>$.value)),set:async(t,r=!1)=>{const s=$.value,a="function"==typeof t?t(s):t;if(r)return $.value=a,$.listeners.forEach((e=>e())),void f(`${e}.${u}`,a);y.set(b,a),w||(w=!0,$.frameSync&&o?.requestAnimationFrame?await new Promise((e=>o.requestAnimationFrame((()=>e(x()))))):await x())},get:()=>$.value,undo:()=>{m[b]?.past.length&&(m[b].future.unshift(m[b].present),m[b].present=m[b].past.pop(),$.value=m[b].present,$.listeners.forEach((e=>e())),(e=>{if(i[e]>0)i[e]--,c[e][i[e]]})(b),f(`${e}.undo`,m[b].present))},redo:()=>{m[b]?.future.length&&(m[b].past.push(m[b].present),m[b].present=m[b].future.shift(),$.value=m[b].present,$.listeners.forEach((e=>e())),(e=>{if(i[e]<c[e]?.length-1)i[e]++,c[e][i[e]]})(b),f(`${e}.redo`,m[b].present))},clear:()=>{$.value=p,g.clear(),Object.keys(m).forEach((e=>delete m[e])),f(`${e}.clear`,p)}}}),v=(e,t)=>({...e,...t,lastUpdated:Date.now()});exports.derivedState=(e,t)=>()=>{const r=e.map((e=>e.useState()));return t(...r)},exports.mergeCRDT=v,exports.optimisticUpdate=async(e,t,r,o)=>{const s=e.useState(),a=t(s);e.set(a);try{await r()}catch(t){console.error("API request failed:",t),e.set(o?o(s):s)}},exports.restoreEncryptedState=l,exports.restoreState=a,exports.saveEncryptedState=n,exports.saveState=s,exports.syncCRDT=(e,t)=>{const r=t.useState(),o=v(r,e);t.set(o)},exports.useSlice=h,exports.useStateGlobal=(e,t,r)=>h("global")(e,t,r),exports.useStore=t=>{const r=e.useRef(null);return r.current||(r.current=t()),r.current};
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
3
|
-
* @license React
|
|
4
|
-
* use-sync-external-store-shim.production.js
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/var ee,te,re={};
|
|
11
|
-
/**
|
|
12
|
-
* @license React
|
|
13
|
-
* use-sync-external-store-shim.development.js
|
|
14
|
-
*
|
|
15
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
-
*
|
|
17
|
-
* This source code is licensed under the MIT license found in the
|
|
18
|
-
* LICENSE file in the root directory of this source tree.
|
|
19
|
-
*/var ne=(te||(te=1,"production"===process.env.NODE_ENV?Q.exports=function(){if(Y)return Z;Y=1;var t=e,r="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=t.useState,o=t.useEffect,a=t.useLayoutEffect,s=t.useDebugValue;function i(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}var c=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?function(e,t){return t()}:function(e,t){var r=t(),c=n({inst:{value:r,getSnapshot:t}}),u=c[0].inst,f=c[1];return a((function(){u.value=r,u.getSnapshot=t,i(u)&&f({inst:u})}),[e,r,t]),o((function(){return i(u)&&f({inst:u}),e((function(){i(u)&&f({inst:u})}))}),[e]),s(r),r};return Z.useSyncExternalStore=void 0!==t.useSyncExternalStore?t.useSyncExternalStore:c,Z}():Q.exports=(ee||(ee=1,"production"!==process.env.NODE_ENV&&function(){function t(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch{return!0}}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=e,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=r.useState,a=r.useEffect,s=r.useLayoutEffect,i=r.useDebugValue,c=!1,u=!1,f=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?function(e,t){return t()}:function(e,f){c||void 0===r.startTransition||(c=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=f();if(!u){var p=f();n(l,p)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var d=(p=o({inst:{value:l,getSnapshot:f}}))[0].inst,_=p[1];return s((function(){d.value=l,d.getSnapshot=f,t(d)&&_({inst:d})}),[e,l,f]),a((function(){return t(d)&&_({inst:d}),e((function(){t(d)&&_({inst:d})}))}),[e]),i(l),l};re.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:f,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),re)),Q.exports);const oe={},ae={},se={},ie=H.__STATE_JET_DEVTOOLS__,ce=(e,t)=>{oe[e]||(oe[e]=[]),void 0===ae[e]&&(ae[e]=-1),oe[e]=oe[e].slice(0,ae[e]+1),oe[e].push(t),ae[e]++,ie?.updateState&&ie.updateState(e,t,[...oe[e]])},ue=(e,t)=>{se[e]||(se[e]=[]);const r=performance.now();t();const n=performance.now()-r;se[e].push(n),ie?.updatePerformance&&ie.updatePerformance(e,n)},fe=new Set,le=new Map,pe=new Map,de={};let _e=!1;const ye=(e,t,r)=>he("global")(e,t,r),he=e=>(le.has(e)||le.set(e,{}),(t,r,n)=>{const o=le.get(e),a=`${e}:${t}`;if(!o[t]){let e=r;n?.persist&&(e=n?.encrypt?X(a,r):W(a,r)),o[t]={value:e,listeners:new Set,...n}}const s=o[t],i=async()=>{_e=!1;const e=Array.from(pe.entries());pe.clear();for(const[t,r]of e){const[e,n]=t.split(":"),o=le.get(e);if(!o)continue;const a=o[n];if(!a)continue;if(fe.has(t)){console.warn(`[state-jet] Skipping recursive middleware for: ${t}`);continue}let s=r;const i=a.value;if(de[t]||(de[t]={past:[],present:i,future:[]}),de[t].past.push(i),de[t].present=s,de[t].future=[],fe.add(t),a?.middleware)for(const e of a.middleware)try{console.log(`[state-jet] Running middleware for ${t}`);const r=e(t,i,s,(e=>{s=e}));if(void 0!==r)if(r instanceof Promise){const e=await r;void 0!==e&&(s=e)}else s=r}catch(e){console.error(`[state-jet] Middleware error in ${t}:`,e)}fe.delete(t),"function"==typeof s?a.value=B(a.value,s):i!==s&&(a.value=s,a.listeners.forEach((e=>e())),ce(`${e}.${n}`,s),ue(`${e}.${n}`,(()=>{})),a?.persist&&(a?.encrypt?q(t,s):J(t,s)))}};return{useState:()=>ne.useSyncExternalStore((e=>(s.listeners.add(e),()=>s.listeners.delete(e))),(()=>s.value)),set:async(r,n=!1)=>{const o=s.value,c="function"==typeof r?r(o):r;if(n)return s.value=c,s.listeners.forEach((e=>e())),void ce(`${e}.${t}`,c);pe.set(a,c),_e||(_e=!0,s.frameSync&&H?.requestAnimationFrame?await new Promise((e=>H.requestAnimationFrame((()=>e(i()))))):await i())},get:()=>s.value,undo:()=>{de[a]?.past.length&&(de[a].future.unshift(de[a].present),de[a].present=de[a].past.pop(),s.value=de[a].present,s.listeners.forEach((e=>e())),(e=>{if(ae[e]>0)ae[e]--,oe[e][ae[e]]})(a),ce(`${e}.undo`,de[a].present))},redo:()=>{de[a]?.future.length&&(de[a].past.push(de[a].present),de[a].present=de[a].future.shift(),s.value=de[a].present,s.listeners.forEach((e=>e())),(e=>{if(ae[e]<oe[e]?.length-1)ae[e]++,oe[e][ae[e]]})(a),ce(`${e}.redo`,de[a].present))},clear:()=>{s.value=r,le.clear(),Object.keys(de).forEach((e=>delete de[e])),ce(`${e}.clear`,r)}}}),be=e=>{const r=t(null);return r.current||(r.current=e()),r.current},me=async(e,t,r,n)=>{const o=e.useState(),a=t(o);e.set(a);try{await r()}catch(t){console.error("API request failed:",t),e.set(n?n(o):o)}},Se=(e,t)=>({...e,...t,lastUpdated:Date.now()}),ge=(e,t)=>{const r=t.useState(),n=Se(r,e);t.set(n)},ve=(e,t)=>()=>{const r=e.map((e=>e.useState()));return t(...r)};export{ve as derivedState,Se as mergeCRDT,me as optimisticUpdate,X as restoreEncryptedState,W as restoreState,q as saveEncryptedState,J as saveState,ge as syncCRDT,he as useSlice,ye as useStateGlobal,be as useStore};
|
|
1
|
+
import{useRef as e}from"react";import{produce as t}from"immer";import{useSyncExternalStore as r}from"use-sync-external-store/shim";const a=(()=>{if("object"==typeof globalThis&&globalThis)return globalThis;if("object"==typeof self&&self)return self;if("object"==typeof window&&window)return window;if(typeof global<"u"&&"object"==typeof global&&global)return global;throw new Error("Unable to locate global `this`")})(),s=(e,t)=>{typeof a?.localStorage<"u"&&a.localStorage.setItem(e,JSON.stringify(t))},o=(e,t)=>{if(typeof a?.localStorage<"u"){const r=a.localStorage?.getItem(e);return r?JSON.parse(r):t}return t},n=(e,t)=>{typeof a?.localStorage<"u"&&a.localStorage.setItem(e,(e=>btoa(JSON.stringify(e)))(t))},l=(e,t)=>{if(typeof a?.localStorage<"u"){const r=a.localStorage?.getItem(e);return r?(e=>JSON.parse(atob(e)))(r):t}return t},c={},i={},u={},f=a.__STATE_JET_DEVTOOLS__,p=(e,t)=>{c[e]||(c[e]=[]),void 0===i[e]&&(i[e]=-1),c[e]=c[e].slice(0,i[e]+1),c[e].push(t),i[e]++,f?.updateState&&f.updateState(e,t,[...c[e]])},d=(e,t)=>{u[e]||(u[e]=[]);const r=performance.now();t();const a=performance.now()-r;u[e].push(a),f?.updatePerformance&&f.updatePerformance(e,a)},S=new Set,m=new Map,g=new Map,y={};let w=!1;const h=(e,t,r)=>v("global")(e,t,r),v=e=>(m.has(e)||m.set(e,{}),(u,f,h)=>{const v=m.get(e),b=`${e}:${u}`;if(!v[u]){let e=f;h?.persist&&(e=h?.encrypt?l(b,f):o(b,f)),v[u]={value:e,listeners:new Set,...h}}const $=v[u],E=async()=>{w=!1;const e=Array.from(g.entries());g.clear();for(const[r,a]of e){const[e,o]=r.split(":"),l=m.get(e);if(!l)continue;const c=l[o];if(!c)continue;if(S.has(r)){console.warn(`[state-jet] Skipping recursive middleware for: ${r}`);continue}let i=a;const u=c.value;if(y[r]||(y[r]={past:[],present:u,future:[]}),y[r].past.push(u),y[r].present=i,y[r].future=[],S.add(r),c?.middleware)for(const e of c.middleware)try{console.log(`[state-jet] Running middleware for ${r}`);const t=e(r,u,i,(e=>{i=e}));if(void 0!==t)if(t instanceof Promise){const e=await t;void 0!==e&&(i=e)}else i=t}catch(e){console.error(`[state-jet] Middleware error in ${r}:`,e)}S.delete(r),"function"==typeof i?c.value=t(c.value,i):u!==i&&(c.value=i,c.listeners.forEach((e=>e())),p(`${e}.${o}`,i),d(`${e}.${o}`,(()=>{})),c?.persist&&(c?.encrypt?n(r,i):s(r,i)))}};return{useState:()=>r((e=>($.listeners.add(e),()=>$.listeners.delete(e))),(()=>$.value)),set:async(t,r=!1)=>{const s=$.value,o="function"==typeof t?t(s):t;if(r)return $.value=o,$.listeners.forEach((e=>e())),void p(`${e}.${u}`,o);g.set(b,o),w||(w=!0,$.frameSync&&a?.requestAnimationFrame?await new Promise((e=>a.requestAnimationFrame((()=>e(E()))))):await E())},get:()=>$.value,undo:()=>{y[b]?.past.length&&(y[b].future.unshift(y[b].present),y[b].present=y[b].past.pop(),$.value=y[b].present,$.listeners.forEach((e=>e())),(e=>{if(i[e]>0)i[e]--,c[e][i[e]]})(b),p(`${e}.undo`,y[b].present))},redo:()=>{y[b]?.future.length&&(y[b].past.push(y[b].present),y[b].present=y[b].future.shift(),$.value=y[b].present,$.listeners.forEach((e=>e())),(e=>{if(i[e]<c[e]?.length-1)i[e]++,c[e][i[e]]})(b),p(`${e}.redo`,y[b].present))},clear:()=>{$.value=f,m.clear(),Object.keys(y).forEach((e=>delete y[e])),p(`${e}.clear`,f)}}}),b=t=>{const r=e(null);return r.current||(r.current=t()),r.current},$=async(e,t,r,a)=>{const s=e.useState(),o=t(s);e.set(o);try{await r()}catch(t){console.error("API request failed:",t),e.set(a?a(s):s)}},E=(e,t)=>({...e,...t,lastUpdated:Date.now()}),T=(e,t)=>{const r=t.useState(),a=E(r,e);t.set(a)},j=(e,t)=>()=>{const r=e.map((e=>e.useState()));return t(...r)};export{j as derivedState,E as mergeCRDT,$ as optimisticUpdate,l as restoreEncryptedState,o as restoreState,n as saveEncryptedState,s as saveState,T as syncCRDT,v as useSlice,h as useStateGlobal,b as useStore};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-jet",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Ultra-lightweight global state management for React",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,25 +19,19 @@
|
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/venkateshsundaram/state-jet.git"
|
|
22
|
+
"url": "git+https://github.com/venkateshsundaram/state-jet.git"
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://statejet.org",
|
|
25
25
|
"keywords": [
|
|
26
26
|
"react",
|
|
27
27
|
"state",
|
|
28
|
-
"redux",
|
|
29
28
|
"state-management",
|
|
30
29
|
"global-state",
|
|
31
30
|
"global-state-management",
|
|
32
|
-
"signals",
|
|
33
31
|
"state-jet",
|
|
34
32
|
"statejet",
|
|
35
33
|
"state-jet-react",
|
|
36
|
-
"jet",
|
|
37
|
-
"react-jet",
|
|
38
|
-
"jetstate",
|
|
39
|
-
"jet-state",
|
|
40
|
-
"react-jetstate",
|
|
34
|
+
"react-state-jet",
|
|
41
35
|
"react-hooks",
|
|
42
36
|
"store",
|
|
43
37
|
"hooks",
|
|
@@ -45,7 +39,6 @@
|
|
|
45
39
|
"typescript",
|
|
46
40
|
"global",
|
|
47
41
|
"react-state-management",
|
|
48
|
-
"state-manager",
|
|
49
42
|
"global-state-hooks",
|
|
50
43
|
"state-hooks",
|
|
51
44
|
"use-store",
|