Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zustand

Package Overview
Dependencies
Maintainers
3
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zustand - npm Package Compare versions

Comparing version 4.3.7 to 4.3.8

9

esm/middleware.js

@@ -254,3 +254,3 @@ const reduxImpl = (reducer, initial) => (set, _get, api) => {

function createJSONStorage(getStorage) {
function createJSONStorage(getStorage, options) {
let storage;

@@ -269,3 +269,3 @@ try {

}
return JSON.parse(str2);
return JSON.parse(str2, options == null ? void 0 : options.reviver);
};

@@ -278,3 +278,6 @@ const str = (_a = storage.getItem(name)) != null ? _a : null;

},
setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue)),
setItem: (name, newValue) => storage.setItem(
name,
JSON.stringify(newValue, options == null ? void 0 : options.replacer)
),
removeItem: (name) => storage.removeItem(name)

@@ -281,0 +284,0 @@ };

@@ -16,3 +16,7 @@ import type { StateCreator, StoreMutatorIdentifier } from '../vanilla';

}
export declare function createJSONStorage<S>(getStorage: () => StateStorage): PersistStorage<S> | undefined;
type JsonStorageOptions = {
reviver?: (key: string, value: unknown) => unknown;
replacer?: (key: string, value: unknown) => unknown;
};
export declare function createJSONStorage<S>(getStorage: () => StateStorage, options?: JsonStorageOptions): PersistStorage<S> | undefined;
export interface PersistOptions<S, PersistedState = S> {

@@ -19,0 +23,0 @@ /** Name of the storage (must be unique) */

@@ -289,3 +289,3 @@ 'use strict';

function createJSONStorage(getStorage) {
function createJSONStorage(getStorage, options) {
var storage;

@@ -304,3 +304,3 @@ try {

}
return JSON.parse(str);
return JSON.parse(str, options == null ? void 0 : options.reviver);
};

@@ -314,3 +314,3 @@ var str = (_getItem = storage.getItem(name)) != null ? _getItem : null;

setItem: function setItem(name, newValue) {
return storage.setItem(name, JSON.stringify(newValue));
return storage.setItem(name, JSON.stringify(newValue, options == null ? void 0 : options.replacer));
},

@@ -317,0 +317,0 @@ removeItem: function removeItem(name) {

@@ -16,3 +16,7 @@ import type { StateCreator, StoreMutatorIdentifier } from '../vanilla';

}
export declare function createJSONStorage<S>(getStorage: () => StateStorage): PersistStorage<S> | undefined;
type JsonStorageOptions = {
reviver?: (key: string, value: unknown) => unknown;
replacer?: (key: string, value: unknown) => unknown;
};
export declare function createJSONStorage<S>(getStorage: () => StateStorage, options?: JsonStorageOptions): PersistStorage<S> | undefined;
export interface PersistOptions<S, PersistedState = S> {

@@ -19,0 +23,0 @@ /** Name of the storage (must be unique) */

{
"name": "zustand",
"private": false,
"version": "4.3.7",
"version": "4.3.8",
"description": "🐻 Bear necessities for state management in React",

@@ -6,0 +6,0 @@ "main": "./index.js",

@@ -515,3 +515,3 @@ <p align="center">

- [Calling actions outside a React event handler in pre React 18](./docs/guides/event-handler-in-pre-react-18.md).
- [Testing](./docs/guides/testing.mdx)
- [Testing](./docs/guides/testing.md)

@@ -518,0 +518,0 @@ ## Third-Party Libraries

@@ -261,3 +261,3 @@ System.register([], (function (exports) {

function createJSONStorage(getStorage) {
function createJSONStorage(getStorage, options) {
let storage;

@@ -276,3 +276,3 @@ try {

}
return JSON.parse(str2);
return JSON.parse(str2, options == null ? void 0 : options.reviver);
};

@@ -285,3 +285,6 @@ const str = (_a = storage.getItem(name)) != null ? _a : null;

},
setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue)),
setItem: (name, newValue) => storage.setItem(
name,
JSON.stringify(newValue, options == null ? void 0 : options.replacer)
),
removeItem: (name) => storage.removeItem(name)

@@ -288,0 +291,0 @@ };

@@ -1,5 +0,5 @@

System.register([],function(b){"use strict";return{execute:function(){b("createJSONStorage",E);const j=b("redux",(d,c)=>(a,r,o)=>(o.dispatch=e=>(a(v=>d(v,e),!1,e),e),o.dispatchFromDevtools=!0,{dispatch:(...e)=>o.dispatch(...e),...c})),I=new Map,w=d=>{const c=I.get(d);return c?Object.fromEntries(Object.entries(c.stores).map(([a,r])=>[a,r.getState()])):{}},T=(d,c,a)=>{if(d===void 0)return{type:"untracked",connection:c.connect(a)};const r=I.get(a.name);if(r)return{type:"tracked",store:d,...r};const o={connection:c.connect(a),stores:{}};return I.set(a.name,o),{type:"tracked",store:d,...o}},P=b("devtools",(d,c={})=>(a,r,o)=>{const{enabled:e,anonymousActionType:v,store:u,...h}=c;let m;try{m=(e!=null?e:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!m)return d(a,r,o);const{connection:l,...y}=T(u,m,h);let f=!0;o.setState=(n,s,i)=>{const t=a(n,s);if(!f)return t;const p=i===void 0?{type:v||"anonymous"}:typeof i=="string"?{type:i}:i;return u===void 0?(l==null||l.send(p,r()),t):(l==null||l.send({...p,type:`${u}/${p.type}`},{...w(h.name),[u]:o.getState()}),t)};const g=(...n)=>{const s=f;f=!1,a(...n),f=s},S=d(o.setState,r,o);if(y.type==="untracked"?l==null||l.init(S):(y.stores[y.store]=o,l==null||l.init(Object.fromEntries(Object.entries(y.stores).map(([n,s])=>[n,n===y.store?S:s.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){const n=o.dispatch;o.dispatch=(...s)=>{n(...s)}}return l.subscribe(n=>{var s;switch(n.type){case"ACTION":if(typeof n.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return _(n.payload,i=>{if(i.type==="__setState"){if(u===void 0){g(i.state);return}Object.keys(i.state).length!==1&&console.error(`
System.register([],function(b){"use strict";return{execute:function(){b("createJSONStorage",E);const j=b("redux",(d,c)=>(a,o,n)=>(n.dispatch=e=>(a(g=>d(g,e),!1,e),e),n.dispatchFromDevtools=!0,{dispatch:(...e)=>n.dispatch(...e),...c})),I=new Map,w=d=>{const c=I.get(d);return c?Object.fromEntries(Object.entries(c.stores).map(([a,o])=>[a,o.getState()])):{}},T=(d,c,a)=>{if(d===void 0)return{type:"untracked",connection:c.connect(a)};const o=I.get(a.name);if(o)return{type:"tracked",store:d,...o};const n={connection:c.connect(a),stores:{}};return I.set(a.name,n),{type:"tracked",store:d,...n}},P=b("devtools",(d,c={})=>(a,o,n)=>{const{enabled:e,anonymousActionType:g,store:u,...h}=c;let m;try{m=(e!=null?e:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!m)return d(a,o,n);const{connection:l,...y}=T(u,m,h);let p=!0;n.setState=(r,s,i)=>{const t=a(r,s);if(!p)return t;const f=i===void 0?{type:g||"anonymous"}:typeof i=="string"?{type:i}:i;return u===void 0?(l==null||l.send(f,o()),t):(l==null||l.send({...f,type:`${u}/${f.type}`},{...w(h.name),[u]:n.getState()}),t)};const v=(...r)=>{const s=p;p=!1,a(...r),p=s},S=d(n.setState,o,n);if(y.type==="untracked"?l==null||l.init(S):(y.stores[y.store]=n,l==null||l.init(Object.fromEntries(Object.entries(y.stores).map(([r,s])=>[r,r===y.store?S:s.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){const r=n.dispatch;n.dispatch=(...s)=>{r(...s)}}return l.subscribe(r=>{var s;switch(r.type){case"ACTION":if(typeof r.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return _(r.payload,i=>{if(i.type==="__setState"){if(u===void 0){v(i.state);return}Object.keys(i.state).length!==1&&console.error(`
[zustand devtools middleware] Unsupported __setState action format.
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
`);const t=i.state[u];if(t==null)return;JSON.stringify(o.getState())!==JSON.stringify(t)&&g(t);return}o.dispatchFromDevtools&&typeof o.dispatch=="function"&&o.dispatch(i)});case"DISPATCH":switch(n.payload.type){case"RESET":return g(S),u===void 0?l==null?void 0:l.init(o.getState()):l==null?void 0:l.init(w(h.name));case"COMMIT":if(u===void 0){l==null||l.init(o.getState());return}return l==null?void 0:l.init(w(h.name));case"ROLLBACK":return _(n.state,i=>{if(u===void 0){g(i),l==null||l.init(o.getState());return}g(i[u]),l==null||l.init(w(h.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return _(n.state,i=>{if(u===void 0){g(i);return}JSON.stringify(o.getState())!==JSON.stringify(i[u])&&g(i[u])});case"IMPORT_STATE":{const{nextLiftedState:i}=n.payload,t=(s=i.computedStates.slice(-1)[0])==null?void 0:s.state;if(!t)return;g(u===void 0?t:t[u]),l==null||l.send(null,i);return}case"PAUSE_RECORDING":return f=!f}return}}),S}),_=(d,c)=>{let a;try{a=JSON.parse(d)}catch(r){console.error("[zustand devtools middleware] Could not parse the received json",r)}a!==void 0&&c(a)},k=b("subscribeWithSelector",d=>(c,a,r)=>{const o=r.subscribe;return r.subscribe=(e,v,u)=>{let h=e;if(v){const m=(u==null?void 0:u.equalityFn)||Object.is;let l=e(r.getState());h=y=>{const f=e(y);if(!m(l,f)){const g=l;v(l=f,g)}},u!=null&&u.fireImmediately&&v(l,l)}return o(h)},d(c,a,r)}),H=b("combine",(d,c)=>(...a)=>Object.assign({},d,c(...a)));function E(d){let c;try{c=d()}catch{return}return{getItem:a=>{var r;const o=v=>v===null?null:JSON.parse(v),e=(r=c.getItem(a))!=null?r:null;return e instanceof Promise?e.then(o):o(e)},setItem:(a,r)=>c.setItem(a,JSON.stringify(r)),removeItem:a=>c.removeItem(a)}}const O=d=>c=>{try{const a=d(c);return a instanceof Promise?a:{then(r){return O(r)(a)},catch(r){return this}}}catch(a){return{then(r){return this},catch(r){return O(r)(a)}}}},N=(d,c)=>(a,r,o)=>{let e={getStorage:()=>localStorage,serialize:JSON.stringify,deserialize:JSON.parse,partialize:s=>s,version:0,merge:(s,i)=>({...i,...s}),...c},v=!1;const u=new Set,h=new Set;let m;try{m=e.getStorage()}catch{}if(!m)return d((...s)=>{console.warn(`[zustand persist middleware] Unable to update item '${e.name}', the given storage is currently unavailable.`),a(...s)},r,o);const l=O(e.serialize),y=()=>{const s=e.partialize({...r()});let i;const t=l({state:s,version:e.version}).then(p=>m.setItem(e.name,p)).catch(p=>{i=p});if(i)throw i;return t},f=o.setState;o.setState=(s,i)=>{f(s,i),y()};const g=d((...s)=>{a(...s),y()},r,o);let S;const n=()=>{var s;if(!m)return;v=!1,u.forEach(t=>t(r()));const i=((s=e.onRehydrateStorage)==null?void 0:s.call(e,r()))||void 0;return O(m.getItem.bind(m))(e.name).then(t=>{if(t)return e.deserialize(t)}).then(t=>{if(t)if(typeof t.version=="number"&&t.version!==e.version){if(e.migrate)return e.migrate(t.state,t.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return t.state}).then(t=>{var p;return S=e.merge(t,(p=r())!=null?p:g),a(S,!0),y()}).then(()=>{i==null||i(S,void 0),v=!0,h.forEach(t=>t(S))}).catch(t=>{i==null||i(void 0,t)})};return o.persist={setOptions:s=>{e={...e,...s},s.getStorage&&(m=s.getStorage())},clearStorage:()=>{m==null||m.removeItem(e.name)},getOptions:()=>e,rehydrate:()=>n(),hasHydrated:()=>v,onHydrate:s=>(u.add(s),()=>{u.delete(s)}),onFinishHydration:s=>(h.add(s),()=>{h.delete(s)})},n(),S||g},z=(d,c)=>(a,r,o)=>{let e={storage:E(()=>localStorage),partialize:n=>n,version:0,merge:(n,s)=>({...s,...n}),...c},v=!1;const u=new Set,h=new Set;let m=e.storage;if(!m)return d((...n)=>{console.warn(`[zustand persist middleware] Unable to update item '${e.name}', the given storage is currently unavailable.`),a(...n)},r,o);const l=()=>{const n=e.partialize({...r()});return m.setItem(e.name,{state:n,version:e.version})},y=o.setState;o.setState=(n,s)=>{y(n,s),l()};const f=d((...n)=>{a(...n),l()},r,o);let g;const S=()=>{var n,s;if(!m)return;v=!1,u.forEach(t=>{var p;return t((p=r())!=null?p:f)});const i=((s=e.onRehydrateStorage)==null?void 0:s.call(e,(n=r())!=null?n:f))||void 0;return O(m.getItem.bind(m))(e.name).then(t=>{if(t)if(typeof t.version=="number"&&t.version!==e.version){if(e.migrate)return e.migrate(t.state,t.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return t.state}).then(t=>{var p;return g=e.merge(t,(p=r())!=null?p:f),a(g,!0),l()}).then(()=>{i==null||i(g,void 0),g=r(),v=!0,h.forEach(t=>t(g))}).catch(t=>{i==null||i(void 0,t)})};return o.persist={setOptions:n=>{e={...e,...n},n.storage&&(m=n.storage)},clearStorage:()=>{m==null||m.removeItem(e.name)},getOptions:()=>e,rehydrate:()=>S(),hasHydrated:()=>v,onHydrate:n=>(u.add(n),()=>{u.delete(n)}),onFinishHydration:n=>(h.add(n),()=>{h.delete(n)})},e.skipHydration||S(),g||f},U=b("persist",(d,c)=>"getStorage"in c||"serialize"in c||"deserialize"in c?N(d,c):z(d,c))}}});
`);const t=i.state[u];if(t==null)return;JSON.stringify(n.getState())!==JSON.stringify(t)&&v(t);return}n.dispatchFromDevtools&&typeof n.dispatch=="function"&&n.dispatch(i)});case"DISPATCH":switch(r.payload.type){case"RESET":return v(S),u===void 0?l==null?void 0:l.init(n.getState()):l==null?void 0:l.init(w(h.name));case"COMMIT":if(u===void 0){l==null||l.init(n.getState());return}return l==null?void 0:l.init(w(h.name));case"ROLLBACK":return _(r.state,i=>{if(u===void 0){v(i),l==null||l.init(n.getState());return}v(i[u]),l==null||l.init(w(h.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return _(r.state,i=>{if(u===void 0){v(i);return}JSON.stringify(n.getState())!==JSON.stringify(i[u])&&v(i[u])});case"IMPORT_STATE":{const{nextLiftedState:i}=r.payload,t=(s=i.computedStates.slice(-1)[0])==null?void 0:s.state;if(!t)return;v(u===void 0?t:t[u]),l==null||l.send(null,i);return}case"PAUSE_RECORDING":return p=!p}return}}),S}),_=(d,c)=>{let a;try{a=JSON.parse(d)}catch(o){console.error("[zustand devtools middleware] Could not parse the received json",o)}a!==void 0&&c(a)},k=b("subscribeWithSelector",d=>(c,a,o)=>{const n=o.subscribe;return o.subscribe=(e,g,u)=>{let h=e;if(g){const m=(u==null?void 0:u.equalityFn)||Object.is;let l=e(o.getState());h=y=>{const p=e(y);if(!m(l,p)){const v=l;g(l=p,v)}},u!=null&&u.fireImmediately&&g(l,l)}return n(h)},d(c,a,o)}),H=b("combine",(d,c)=>(...a)=>Object.assign({},d,c(...a)));function E(d,c){let a;try{a=d()}catch{return}return{getItem:o=>{var n;const e=u=>u===null?null:JSON.parse(u,c==null?void 0:c.reviver),g=(n=a.getItem(o))!=null?n:null;return g instanceof Promise?g.then(e):e(g)},setItem:(o,n)=>a.setItem(o,JSON.stringify(n,c==null?void 0:c.replacer)),removeItem:o=>a.removeItem(o)}}const O=d=>c=>{try{const a=d(c);return a instanceof Promise?a:{then(o){return O(o)(a)},catch(o){return this}}}catch(a){return{then(o){return this},catch(o){return O(o)(a)}}}},N=(d,c)=>(a,o,n)=>{let e={getStorage:()=>localStorage,serialize:JSON.stringify,deserialize:JSON.parse,partialize:s=>s,version:0,merge:(s,i)=>({...i,...s}),...c},g=!1;const u=new Set,h=new Set;let m;try{m=e.getStorage()}catch{}if(!m)return d((...s)=>{console.warn(`[zustand persist middleware] Unable to update item '${e.name}', the given storage is currently unavailable.`),a(...s)},o,n);const l=O(e.serialize),y=()=>{const s=e.partialize({...o()});let i;const t=l({state:s,version:e.version}).then(f=>m.setItem(e.name,f)).catch(f=>{i=f});if(i)throw i;return t},p=n.setState;n.setState=(s,i)=>{p(s,i),y()};const v=d((...s)=>{a(...s),y()},o,n);let S;const r=()=>{var s;if(!m)return;g=!1,u.forEach(t=>t(o()));const i=((s=e.onRehydrateStorage)==null?void 0:s.call(e,o()))||void 0;return O(m.getItem.bind(m))(e.name).then(t=>{if(t)return e.deserialize(t)}).then(t=>{if(t)if(typeof t.version=="number"&&t.version!==e.version){if(e.migrate)return e.migrate(t.state,t.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return t.state}).then(t=>{var f;return S=e.merge(t,(f=o())!=null?f:v),a(S,!0),y()}).then(()=>{i==null||i(S,void 0),g=!0,h.forEach(t=>t(S))}).catch(t=>{i==null||i(void 0,t)})};return n.persist={setOptions:s=>{e={...e,...s},s.getStorage&&(m=s.getStorage())},clearStorage:()=>{m==null||m.removeItem(e.name)},getOptions:()=>e,rehydrate:()=>r(),hasHydrated:()=>g,onHydrate:s=>(u.add(s),()=>{u.delete(s)}),onFinishHydration:s=>(h.add(s),()=>{h.delete(s)})},r(),S||v},z=(d,c)=>(a,o,n)=>{let e={storage:E(()=>localStorage),partialize:r=>r,version:0,merge:(r,s)=>({...s,...r}),...c},g=!1;const u=new Set,h=new Set;let m=e.storage;if(!m)return d((...r)=>{console.warn(`[zustand persist middleware] Unable to update item '${e.name}', the given storage is currently unavailable.`),a(...r)},o,n);const l=()=>{const r=e.partialize({...o()});return m.setItem(e.name,{state:r,version:e.version})},y=n.setState;n.setState=(r,s)=>{y(r,s),l()};const p=d((...r)=>{a(...r),l()},o,n);let v;const S=()=>{var r,s;if(!m)return;g=!1,u.forEach(t=>{var f;return t((f=o())!=null?f:p)});const i=((s=e.onRehydrateStorage)==null?void 0:s.call(e,(r=o())!=null?r:p))||void 0;return O(m.getItem.bind(m))(e.name).then(t=>{if(t)if(typeof t.version=="number"&&t.version!==e.version){if(e.migrate)return e.migrate(t.state,t.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return t.state}).then(t=>{var f;return v=e.merge(t,(f=o())!=null?f:p),a(v,!0),l()}).then(()=>{i==null||i(v,void 0),v=o(),g=!0,h.forEach(t=>t(v))}).catch(t=>{i==null||i(void 0,t)})};return n.persist={setOptions:r=>{e={...e,...r},r.storage&&(m=r.storage)},clearStorage:()=>{m==null||m.removeItem(e.name)},getOptions:()=>e,rehydrate:()=>S(),hasHydrated:()=>g,onHydrate:r=>(u.add(r),()=>{u.delete(r)}),onFinishHydration:r=>(h.add(r),()=>{h.delete(r)})},e.skipHydration||S(),v||p},U=b("persist",(d,c)=>"getStorage"in c||"serialize"in c||"deserialize"in c?N(d,c):z(d,c))}}});

@@ -16,3 +16,7 @@ import { StateCreator, StoreMutatorIdentifier } from '../vanilla';

}
export declare function createJSONStorage<S>(getStorage: () => StateStorage): PersistStorage<S> | undefined;
type JsonStorageOptions = {
reviver?: (key: string, value: unknown) => unknown;
replacer?: (key: string, value: unknown) => unknown;
};
export declare function createJSONStorage<S>(getStorage: () => StateStorage, options?: JsonStorageOptions): PersistStorage<S> | undefined;
export interface PersistOptions<S, PersistedState = S> {

@@ -19,0 +23,0 @@ /** Name of the storage (must be unique) */

@@ -16,3 +16,7 @@ import { StateCreator, StoreMutatorIdentifier } from '../vanilla';

}
export declare function createJSONStorage<S>(getStorage: () => StateStorage): PersistStorage<S> | undefined;
type JsonStorageOptions = {
reviver?: (key: string, value: unknown) => unknown;
replacer?: (key: string, value: unknown) => unknown;
};
export declare function createJSONStorage<S>(getStorage: () => StateStorage, options?: JsonStorageOptions): PersistStorage<S> | undefined;
export interface PersistOptions<S, PersistedState = S> {

@@ -19,0 +23,0 @@ /** Name of the storage (must be unique) */

@@ -293,3 +293,3 @@ (function (global, factory) {

function createJSONStorage(getStorage) {
function createJSONStorage(getStorage, options) {
var storage;

@@ -308,3 +308,3 @@ try {

}
return JSON.parse(str);
return JSON.parse(str, options == null ? void 0 : options.reviver);
};

@@ -318,3 +318,3 @@ var str = (_getItem = storage.getItem(name)) != null ? _getItem : null;

setItem: function setItem(name, newValue) {
return storage.setItem(name, JSON.stringify(newValue));
return storage.setItem(name, JSON.stringify(newValue, options == null ? void 0 : options.replacer));
},

@@ -321,0 +321,0 @@ removeItem: function removeItem(name) {

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).zustandMiddleware={})}(this,(function(t){"use strict";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},e.apply(this,arguments)}function n(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(i[n]=t[n]);return i}var r=function(t,n){return function(r,i,o){return o.dispatch=function(e){return r((function(n){return t(n,e)}),!1,e),e},o.dispatchFromDevtools=!0,e({dispatch:function(){var t;return(t=o).dispatch.apply(t,arguments)}},n)}},i=["enabled","anonymousActionType","store"],o=["connection"],a=new Map,u=function(t){var e=a.get(t);return e?Object.fromEntries(Object.entries(e.stores).map((function(t){return[t[0],t[1].getState()]}))):{}},s=function(t,r){return void 0===r&&(r={}),function(s,f,l){var d,v=r,p=v.enabled,y=v.anonymousActionType,g=v.store,m=n(v,i);try{d=null!=p&&p&&window.__REDUX_DEVTOOLS_EXTENSION__}catch(t){}if(!d)return t(s,f,l);var h=function(t,n,r){if(void 0===t)return{type:"untracked",connection:n.connect(r)};var i=a.get(r.name);if(i)return e({type:"tracked",store:t},i);var o={connection:n.connect(r),stores:{}};return a.set(r.name,o),e({type:"tracked",store:t},o)}(g,d,m),S=h.connection,b=n(h,o),O=!0;l.setState=function(t,n,r){var i,o=s(t,n);if(!O)return o;var a=void 0===r?{type:y||"anonymous"}:"string"==typeof r?{type:r}:r;return void 0===g?(null==S||S.send(a,f()),o):(null==S||S.send(e({},a,{type:g+"/"+a.type}),e({},u(m.name),((i={})[g]=l.getState(),i))),o)};var w=function(){var t=O;O=!1,s.apply(void 0,arguments),O=t},I=t(l.setState,f,l);if("untracked"===b.type?null==S||S.init(I):(b.stores[b.store]=l,null==S||S.init(Object.fromEntries(Object.entries(b.stores).map((function(t){var e=t[0],n=t[1];return[e,e===b.store?I:n.getState()]}))))),l.dispatchFromDevtools&&"function"==typeof l.dispatch){var T=l.dispatch;l.dispatch=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];T.apply(void 0,e)}}return S.subscribe((function(t){switch(t.type){case"ACTION":return"string"!=typeof t.payload?void console.error("[zustand devtools middleware] Unsupported action format"):c(t.payload,(function(t){if("__setState"!==t.type)l.dispatchFromDevtools&&"function"==typeof l.dispatch&&l.dispatch(t);else{if(void 0===g)return void w(t.state);1!==Object.keys(t.state).length&&console.error('\n [zustand devtools middleware] Unsupported __setState action format. \n When using \'store\' option in devtools(), the \'state\' should have only one key, which is a value of \'store\' that was passed in devtools(),\n and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }\n ');var e=t.state[g];if(null==e)return;JSON.stringify(l.getState())!==JSON.stringify(e)&&w(e)}}));case"DISPATCH":switch(t.payload.type){case"RESET":return w(I),void 0===g?null==S?void 0:S.init(l.getState()):null==S?void 0:S.init(u(m.name));case"COMMIT":return void 0===g?void(null==S||S.init(l.getState())):null==S?void 0:S.init(u(m.name));case"ROLLBACK":return c(t.state,(function(t){if(void 0===g)return w(t),void(null==S||S.init(l.getState()));w(t[g]),null==S||S.init(u(m.name))}));case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return c(t.state,(function(t){void 0!==g?JSON.stringify(l.getState())!==JSON.stringify(t[g])&&w(t[g]):w(t)}));case"IMPORT_STATE":var e,n=t.payload.nextLiftedState,r=null==(e=n.computedStates.slice(-1)[0])?void 0:e.state;if(!r)return;return w(void 0===g?r:r[g]),void(null==S||S.send(null,n));case"PAUSE_RECORDING":return O=!O}return}})),I}},c=function(t,e){var n;try{n=JSON.parse(t)}catch(t){console.error("[zustand devtools middleware] Could not parse the received json",t)}void 0!==n&&e(n)},f=function(t){return function(e,n,r){var i=r.subscribe;return r.subscribe=function(t,e,n){var o=t;if(e){var a=(null==n?void 0:n.equalityFn)||Object.is,u=t(r.getState());o=function(n){var r=t(n);if(!a(u,r)){var i=u;e(u=r,i)}},null!=n&&n.fireImmediately&&e(u,u)}return i(o)},t(e,n,r)}};function l(t){var e;try{e=t()}catch(t){return}return{getItem:function(t){var n,r=function(t){return null===t?null:JSON.parse(t)},i=null!=(n=e.getItem(t))?n:null;return i instanceof Promise?i.then(r):r(i)},setItem:function(t,n){return e.setItem(t,JSON.stringify(n))},removeItem:function(t){return e.removeItem(t)}}}var d=function t(e){return function(n){try{var r=e(n);return r instanceof Promise?r:{then:function(e){return t(e)(r)},catch:function(t){return this}}}catch(e){return{then:function(t){return this},catch:function(n){return t(n)(e)}}}}},v=function(t,n){return"getStorage"in n||"serialize"in n||"deserialize"in n?function(t,n){return function(r,i,o){var a,u=e({getStorage:function(){return localStorage},serialize:JSON.stringify,deserialize:JSON.parse,partialize:function(t){return t},version:0,merge:function(t,n){return e({},n,t)}},n),s=!1,c=new Set,f=new Set;try{a=u.getStorage()}catch(t){}if(!a)return t((function(){console.warn("[zustand persist middleware] Unable to update item '"+u.name+"', the given storage is currently unavailable."),r.apply(void 0,arguments)}),i,o);var l=d(u.serialize),v=function(){var t,n=u.partialize(e({},i())),r=l({state:n,version:u.version}).then((function(t){return a.setItem(u.name,t)})).catch((function(e){t=e}));if(t)throw t;return r},p=o.setState;o.setState=function(t,e){p(t,e),v()};var y,g=t((function(){r.apply(void 0,arguments),v()}),i,o),m=function(){if(a){s=!1,c.forEach((function(t){return t(i())}));var t=(null==u.onRehydrateStorage?void 0:u.onRehydrateStorage(i()))||void 0;return d(a.getItem.bind(a))(u.name).then((function(t){if(t)return u.deserialize(t)})).then((function(t){if(t){if("number"!=typeof t.version||t.version===u.version)return t.state;if(u.migrate)return u.migrate(t.state,t.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}})).then((function(t){var e;return y=u.merge(t,null!=(e=i())?e:g),r(y,!0),v()})).then((function(){null==t||t(y,void 0),s=!0,f.forEach((function(t){return t(y)}))})).catch((function(e){null==t||t(void 0,e)}))}};return o.persist={setOptions:function(t){u=e({},u,t),t.getStorage&&(a=t.getStorage())},clearStorage:function(){var t;null==(t=a)||t.removeItem(u.name)},getOptions:function(){return u},rehydrate:function(){return m()},hasHydrated:function(){return s},onHydrate:function(t){return c.add(t),function(){c.delete(t)}},onFinishHydration:function(t){return f.add(t),function(){f.delete(t)}}},m(),y||g}}(t,n):function(t,n){return function(r,i,o){var a=e({storage:l((function(){return localStorage})),partialize:function(t){return t},version:0,merge:function(t,n){return e({},n,t)}},n),u=!1,s=new Set,c=new Set,f=a.storage;if(!f)return t((function(){console.warn("[zustand persist middleware] Unable to update item '"+a.name+"', the given storage is currently unavailable."),r.apply(void 0,arguments)}),i,o);var v=function(){var t=a.partialize(e({},i()));return f.setItem(a.name,{state:t,version:a.version})},p=o.setState;o.setState=function(t,e){p(t,e),v()};var y,g=t((function(){r.apply(void 0,arguments),v()}),i,o),m=function(){var t;if(f){u=!1,s.forEach((function(t){var e;return t(null!=(e=i())?e:g)}));var e=(null==a.onRehydrateStorage?void 0:a.onRehydrateStorage(null!=(t=i())?t:g))||void 0;return d(f.getItem.bind(f))(a.name).then((function(t){if(t){if("number"!=typeof t.version||t.version===a.version)return t.state;if(a.migrate)return a.migrate(t.state,t.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}})).then((function(t){var e;return y=a.merge(t,null!=(e=i())?e:g),r(y,!0),v()})).then((function(){null==e||e(y,void 0),y=i(),u=!0,c.forEach((function(t){return t(y)}))})).catch((function(t){null==e||e(void 0,t)}))}};return o.persist={setOptions:function(t){a=e({},a,t),t.storage&&(f=t.storage)},clearStorage:function(){var t;null==(t=f)||t.removeItem(a.name)},getOptions:function(){return a},rehydrate:function(){return m()},hasHydrated:function(){return u},onHydrate:function(t){return s.add(t),function(){s.delete(t)}},onFinishHydration:function(t){return c.add(t),function(){c.delete(t)}}},a.skipHydration||m(),y||g}}(t,n)};t.combine=function(t,e){return function(){return Object.assign({},t,e.apply(void 0,arguments))}},t.createJSONStorage=l,t.devtools=s,t.persist=v,t.redux=r,t.subscribeWithSelector=f}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).zustandMiddleware={})}(this,(function(t){"use strict";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},e.apply(this,arguments)}function n(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(i[n]=t[n]);return i}var r=function(t,n){return function(r,i,o){return o.dispatch=function(e){return r((function(n){return t(n,e)}),!1,e),e},o.dispatchFromDevtools=!0,e({dispatch:function(){var t;return(t=o).dispatch.apply(t,arguments)}},n)}},i=["enabled","anonymousActionType","store"],o=["connection"],a=new Map,u=function(t){var e=a.get(t);return e?Object.fromEntries(Object.entries(e.stores).map((function(t){return[t[0],t[1].getState()]}))):{}},s=function(t,r){return void 0===r&&(r={}),function(s,f,l){var d,v=r,p=v.enabled,y=v.anonymousActionType,g=v.store,m=n(v,i);try{d=null!=p&&p&&window.__REDUX_DEVTOOLS_EXTENSION__}catch(t){}if(!d)return t(s,f,l);var h=function(t,n,r){if(void 0===t)return{type:"untracked",connection:n.connect(r)};var i=a.get(r.name);if(i)return e({type:"tracked",store:t},i);var o={connection:n.connect(r),stores:{}};return a.set(r.name,o),e({type:"tracked",store:t},o)}(g,d,m),S=h.connection,b=n(h,o),O=!0;l.setState=function(t,n,r){var i,o=s(t,n);if(!O)return o;var a=void 0===r?{type:y||"anonymous"}:"string"==typeof r?{type:r}:r;return void 0===g?(null==S||S.send(a,f()),o):(null==S||S.send(e({},a,{type:g+"/"+a.type}),e({},u(m.name),((i={})[g]=l.getState(),i))),o)};var w=function(){var t=O;O=!1,s.apply(void 0,arguments),O=t},I=t(l.setState,f,l);if("untracked"===b.type?null==S||S.init(I):(b.stores[b.store]=l,null==S||S.init(Object.fromEntries(Object.entries(b.stores).map((function(t){var e=t[0],n=t[1];return[e,e===b.store?I:n.getState()]}))))),l.dispatchFromDevtools&&"function"==typeof l.dispatch){var T=l.dispatch;l.dispatch=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];T.apply(void 0,e)}}return S.subscribe((function(t){switch(t.type){case"ACTION":return"string"!=typeof t.payload?void console.error("[zustand devtools middleware] Unsupported action format"):c(t.payload,(function(t){if("__setState"!==t.type)l.dispatchFromDevtools&&"function"==typeof l.dispatch&&l.dispatch(t);else{if(void 0===g)return void w(t.state);1!==Object.keys(t.state).length&&console.error('\n [zustand devtools middleware] Unsupported __setState action format. \n When using \'store\' option in devtools(), the \'state\' should have only one key, which is a value of \'store\' that was passed in devtools(),\n and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }\n ');var e=t.state[g];if(null==e)return;JSON.stringify(l.getState())!==JSON.stringify(e)&&w(e)}}));case"DISPATCH":switch(t.payload.type){case"RESET":return w(I),void 0===g?null==S?void 0:S.init(l.getState()):null==S?void 0:S.init(u(m.name));case"COMMIT":return void 0===g?void(null==S||S.init(l.getState())):null==S?void 0:S.init(u(m.name));case"ROLLBACK":return c(t.state,(function(t){if(void 0===g)return w(t),void(null==S||S.init(l.getState()));w(t[g]),null==S||S.init(u(m.name))}));case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return c(t.state,(function(t){void 0!==g?JSON.stringify(l.getState())!==JSON.stringify(t[g])&&w(t[g]):w(t)}));case"IMPORT_STATE":var e,n=t.payload.nextLiftedState,r=null==(e=n.computedStates.slice(-1)[0])?void 0:e.state;if(!r)return;return w(void 0===g?r:r[g]),void(null==S||S.send(null,n));case"PAUSE_RECORDING":return O=!O}return}})),I}},c=function(t,e){var n;try{n=JSON.parse(t)}catch(t){console.error("[zustand devtools middleware] Could not parse the received json",t)}void 0!==n&&e(n)},f=function(t){return function(e,n,r){var i=r.subscribe;return r.subscribe=function(t,e,n){var o=t;if(e){var a=(null==n?void 0:n.equalityFn)||Object.is,u=t(r.getState());o=function(n){var r=t(n);if(!a(u,r)){var i=u;e(u=r,i)}},null!=n&&n.fireImmediately&&e(u,u)}return i(o)},t(e,n,r)}};function l(t,e){var n;try{n=t()}catch(t){return}return{getItem:function(t){var r,i=function(t){return null===t?null:JSON.parse(t,null==e?void 0:e.reviver)},o=null!=(r=n.getItem(t))?r:null;return o instanceof Promise?o.then(i):i(o)},setItem:function(t,r){return n.setItem(t,JSON.stringify(r,null==e?void 0:e.replacer))},removeItem:function(t){return n.removeItem(t)}}}var d=function t(e){return function(n){try{var r=e(n);return r instanceof Promise?r:{then:function(e){return t(e)(r)},catch:function(t){return this}}}catch(e){return{then:function(t){return this},catch:function(n){return t(n)(e)}}}}},v=function(t,n){return"getStorage"in n||"serialize"in n||"deserialize"in n?function(t,n){return function(r,i,o){var a,u=e({getStorage:function(){return localStorage},serialize:JSON.stringify,deserialize:JSON.parse,partialize:function(t){return t},version:0,merge:function(t,n){return e({},n,t)}},n),s=!1,c=new Set,f=new Set;try{a=u.getStorage()}catch(t){}if(!a)return t((function(){console.warn("[zustand persist middleware] Unable to update item '"+u.name+"', the given storage is currently unavailable."),r.apply(void 0,arguments)}),i,o);var l=d(u.serialize),v=function(){var t,n=u.partialize(e({},i())),r=l({state:n,version:u.version}).then((function(t){return a.setItem(u.name,t)})).catch((function(e){t=e}));if(t)throw t;return r},p=o.setState;o.setState=function(t,e){p(t,e),v()};var y,g=t((function(){r.apply(void 0,arguments),v()}),i,o),m=function(){if(a){s=!1,c.forEach((function(t){return t(i())}));var t=(null==u.onRehydrateStorage?void 0:u.onRehydrateStorage(i()))||void 0;return d(a.getItem.bind(a))(u.name).then((function(t){if(t)return u.deserialize(t)})).then((function(t){if(t){if("number"!=typeof t.version||t.version===u.version)return t.state;if(u.migrate)return u.migrate(t.state,t.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}})).then((function(t){var e;return y=u.merge(t,null!=(e=i())?e:g),r(y,!0),v()})).then((function(){null==t||t(y,void 0),s=!0,f.forEach((function(t){return t(y)}))})).catch((function(e){null==t||t(void 0,e)}))}};return o.persist={setOptions:function(t){u=e({},u,t),t.getStorage&&(a=t.getStorage())},clearStorage:function(){var t;null==(t=a)||t.removeItem(u.name)},getOptions:function(){return u},rehydrate:function(){return m()},hasHydrated:function(){return s},onHydrate:function(t){return c.add(t),function(){c.delete(t)}},onFinishHydration:function(t){return f.add(t),function(){f.delete(t)}}},m(),y||g}}(t,n):function(t,n){return function(r,i,o){var a=e({storage:l((function(){return localStorage})),partialize:function(t){return t},version:0,merge:function(t,n){return e({},n,t)}},n),u=!1,s=new Set,c=new Set,f=a.storage;if(!f)return t((function(){console.warn("[zustand persist middleware] Unable to update item '"+a.name+"', the given storage is currently unavailable."),r.apply(void 0,arguments)}),i,o);var v=function(){var t=a.partialize(e({},i()));return f.setItem(a.name,{state:t,version:a.version})},p=o.setState;o.setState=function(t,e){p(t,e),v()};var y,g=t((function(){r.apply(void 0,arguments),v()}),i,o),m=function(){var t;if(f){u=!1,s.forEach((function(t){var e;return t(null!=(e=i())?e:g)}));var e=(null==a.onRehydrateStorage?void 0:a.onRehydrateStorage(null!=(t=i())?t:g))||void 0;return d(f.getItem.bind(f))(a.name).then((function(t){if(t){if("number"!=typeof t.version||t.version===a.version)return t.state;if(a.migrate)return a.migrate(t.state,t.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}})).then((function(t){var e;return y=a.merge(t,null!=(e=i())?e:g),r(y,!0),v()})).then((function(){null==e||e(y,void 0),y=i(),u=!0,c.forEach((function(t){return t(y)}))})).catch((function(t){null==e||e(void 0,t)}))}};return o.persist={setOptions:function(t){a=e({},a,t),t.storage&&(f=t.storage)},clearStorage:function(){var t;null==(t=f)||t.removeItem(a.name)},getOptions:function(){return a},rehydrate:function(){return m()},hasHydrated:function(){return u},onHydrate:function(t){return s.add(t),function(){s.delete(t)}},onFinishHydration:function(t){return c.add(t),function(){c.delete(t)}}},a.skipHydration||m(),y||g}}(t,n)};t.combine=function(t,e){return function(){return Object.assign({},t,e.apply(void 0,arguments))}},t.createJSONStorage=l,t.devtools=s,t.persist=v,t.redux=r,t.subscribeWithSelector=f}));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc