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 5.0.0-alpha.3 to 5.0.0-alpha.4

35

index.js
'use strict';
var vanilla = require('zustand/vanilla');
var react = require('zustand/react');
Object.keys(vanilla).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return vanilla[k]; }
});
});
Object.keys(react).forEach(function (k) {
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return react[k]; }
});
});
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var src_exports = {};
module.exports = __toCommonJS(src_exports);
__reExport(src_exports, require("./vanilla.ts"), module.exports);
__reExport(src_exports, require("./react.ts"), module.exports);
'use strict';
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return target;
}
var reduxImpl = function reduxImpl(reducer, initial) {
return function (set, _get, api) {
api.dispatch = function (action) {
set(function (state) {
return reducer(state, action);
}, false, action);
return action;
};
api.dispatchFromDevtools = true;
return _extends({
dispatch: function dispatch() {
var _ref;
return (_ref = api).dispatch.apply(_ref, arguments);
}
}, initial);
};
return to;
};
var redux = reduxImpl;
var _excluded = ["enabled", "anonymousActionType", "store"],
_excluded2 = ["connection"];
var trackedConnections = new Map();
var getTrackedConnectionState = function getTrackedConnectionState(name) {
var api = trackedConnections.get(name);
if (!api) return {};
return Object.fromEntries(Object.entries(api.stores).map(function (_ref) {
var key = _ref[0],
api = _ref[1];
return [key, api.getState()];
}));
};
var extractConnectionInformation = function extractConnectionInformation(store, extensionConnector, options) {
if (store === undefined) {
return {
type: 'untracked',
connection: extensionConnector.connect(options)
};
}
var existingConnection = trackedConnections.get(options.name);
if (existingConnection) {
return _extends({
type: 'tracked',
store: store
}, existingConnection);
}
var newConnection = {
connection: extensionConnector.connect(options),
stores: {}
};
trackedConnections.set(options.name, newConnection);
return _extends({
type: 'tracked',
store: store
}, newConnection);
};
var devtoolsImpl = function devtoolsImpl(fn, devtoolsOptions) {
if (devtoolsOptions === void 0) {
devtoolsOptions = {};
}
return function (set, get, api) {
var _devtoolsOptions = devtoolsOptions,
enabled = _devtoolsOptions.enabled,
anonymousActionType = _devtoolsOptions.anonymousActionType,
store = _devtoolsOptions.store,
options = _objectWithoutPropertiesLoose(_devtoolsOptions, _excluded);
var extensionConnector;
try {
extensionConnector = (enabled != null ? enabled : process.env.NODE_ENV !== 'production') && window.__REDUX_DEVTOOLS_EXTENSION__;
} catch (e) {}
if (!extensionConnector) {
if (process.env.NODE_ENV !== 'production' && enabled) {
console.warn('[zustand devtools middleware] Please install/enable Redux devtools extension');
}
return fn(set, get, api);
}
var _extractConnectionInf = extractConnectionInformation(store, extensionConnector, options),
connection = _extractConnectionInf.connection,
connectionInformation = _objectWithoutPropertiesLoose(_extractConnectionInf, _excluded2);
var isRecording = true;
api.setState = function (state, replace, nameOrAction) {
var _extends2;
var r = set(state, replace);
if (!isRecording) return r;
var action = nameOrAction === undefined ? {
type: anonymousActionType || 'anonymous'
} : typeof nameOrAction === 'string' ? {
type: nameOrAction
} : nameOrAction;
if (store === undefined) {
connection == null || connection.send(action, get());
return r;
}
connection == null || connection.send(_extends({}, action, {
type: store + "/" + action.type
}), _extends({}, getTrackedConnectionState(options.name), (_extends2 = {}, _extends2[store] = api.getState(), _extends2)));
return r;
};
var setStateFromDevtools = function setStateFromDevtools() {
var originalIsRecording = isRecording;
isRecording = false;
set.apply(void 0, arguments);
isRecording = originalIsRecording;
};
var initialState = fn(api.setState, get, api);
if (connectionInformation.type === 'untracked') {
connection == null || connection.init(initialState);
} else {
connectionInformation.stores[connectionInformation.store] = api;
connection == null || connection.init(Object.fromEntries(Object.entries(connectionInformation.stores).map(function (_ref2) {
var key = _ref2[0],
store = _ref2[1];
return [key, key === connectionInformation.store ? initialState : store.getState()];
})));
}
if (api.dispatchFromDevtools && typeof api.dispatch === 'function') {
var didWarnAboutReservedActionType = false;
var originalDispatch = api.dispatch;
api.dispatch = function () {
for (var _len = arguments.length, a = new Array(_len), _key = 0; _key < _len; _key++) {
a[_key] = arguments[_key];
}
if (process.env.NODE_ENV !== 'production' && a[0].type === '__setState' && !didWarnAboutReservedActionType) {
console.warn('[zustand devtools middleware] "__setState" action type is reserved ' + 'to set state from the devtools. Avoid using it.');
didWarnAboutReservedActionType = true;
}
originalDispatch.apply(void 0, a);
};
}
connection.subscribe(function (message) {
switch (message.type) {
case 'ACTION':
if (typeof message.payload !== 'string') {
console.error('[zustand devtools middleware] Unsupported action format');
return;
}
return parseJsonThen(message.payload, function (action) {
if (action.type === '__setState') {
if (store === undefined) {
setStateFromDevtools(action.state);
return;
}
if (Object.keys(action.state).length !== 1) {
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 stateFromDevtools = action.state[store];
if (stateFromDevtools === undefined || stateFromDevtools === null) {
return;
}
if (JSON.stringify(api.getState()) !== JSON.stringify(stateFromDevtools)) {
setStateFromDevtools(stateFromDevtools);
}
return;
}
if (!api.dispatchFromDevtools) return;
if (typeof api.dispatch !== 'function') return;
api.dispatch(action);
});
case 'DISPATCH':
switch (message.payload.type) {
case 'RESET':
setStateFromDevtools(initialState);
if (store === undefined) {
return connection == null ? void 0 : connection.init(api.getState());
}
return connection == null ? void 0 : connection.init(getTrackedConnectionState(options.name));
case 'COMMIT':
if (store === undefined) {
connection == null || connection.init(api.getState());
return;
}
return connection == null ? void 0 : connection.init(getTrackedConnectionState(options.name));
case 'ROLLBACK':
return parseJsonThen(message.state, function (state) {
if (store === undefined) {
setStateFromDevtools(state);
connection == null || connection.init(api.getState());
return;
}
setStateFromDevtools(state[store]);
connection == null || connection.init(getTrackedConnectionState(options.name));
});
case 'JUMP_TO_STATE':
case 'JUMP_TO_ACTION':
return parseJsonThen(message.state, function (state) {
if (store === undefined) {
setStateFromDevtools(state);
return;
}
if (JSON.stringify(api.getState()) !== JSON.stringify(state[store])) {
setStateFromDevtools(state[store]);
}
});
case 'IMPORT_STATE':
{
var _nextLiftedState$comp;
var nextLiftedState = message.payload.nextLiftedState;
var lastComputedState = (_nextLiftedState$comp = nextLiftedState.computedStates.slice(-1)[0]) == null ? void 0 : _nextLiftedState$comp.state;
if (!lastComputedState) return;
if (store === undefined) {
setStateFromDevtools(lastComputedState);
} else {
setStateFromDevtools(lastComputedState[store]);
}
connection == null || connection.send(null, nextLiftedState);
return;
}
case 'PAUSE_RECORDING':
return isRecording = !isRecording;
}
return;
}
});
return initialState;
};
};
var devtools = devtoolsImpl;
var parseJsonThen = function parseJsonThen(stringified, f) {
var parsed;
try {
parsed = JSON.parse(stringified);
} catch (e) {
console.error('[zustand devtools middleware] Could not parse the received json', e);
}
if (parsed !== undefined) f(parsed);
};
var subscribeWithSelectorImpl = function subscribeWithSelectorImpl(fn) {
return function (set, get, api) {
var origSubscribe = api.subscribe;
api.subscribe = function (selector, optListener, options) {
var listener = selector;
if (optListener) {
var equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
var currentSlice = selector(api.getState());
listener = function listener(state) {
var nextSlice = selector(state);
if (!equalityFn(currentSlice, nextSlice)) {
var previousSlice = currentSlice;
optListener(currentSlice = nextSlice, previousSlice);
}
};
if (options != null && options.fireImmediately) {
optListener(currentSlice, currentSlice);
}
}
return origSubscribe(listener);
};
var initialState = fn(set, get, api);
return initialState;
};
};
var subscribeWithSelector = subscribeWithSelectorImpl;
var combine = function combine(initialState, create) {
return function () {
return Object.assign({}, initialState, create.apply(void 0, arguments));
};
};
function createJSONStorage(getStorage, options) {
var storage;
try {
storage = getStorage();
} catch (e) {
return;
}
var persistStorage = {
getItem: function getItem(name) {
var _getItem;
var parse = function parse(str) {
if (str === null) {
return null;
}
return JSON.parse(str, options == null ? void 0 : options.reviver);
};
var str = (_getItem = storage.getItem(name)) != null ? _getItem : null;
if (str instanceof Promise) {
return str.then(parse);
}
return parse(str);
},
setItem: function setItem(name, newValue) {
return storage.setItem(name, JSON.stringify(newValue, options == null ? void 0 : options.replacer));
},
removeItem: function removeItem(name) {
return storage.removeItem(name);
}
};
return persistStorage;
}
var toThenable = function toThenable(fn) {
return function (input) {
try {
var result = fn(input);
if (result instanceof Promise) {
return result;
}
return {
then: function then(onFulfilled) {
return toThenable(onFulfilled)(result);
},
catch: function _catch(_onRejected) {
return this;
}
};
} catch (e) {
return {
then: function then(_onFulfilled) {
return this;
},
catch: function _catch(onRejected) {
return toThenable(onRejected)(e);
}
};
}
};
};
var persistImpl = function persistImpl(config, baseOptions) {
return function (set, get, api) {
var options = _extends({
storage: createJSONStorage(function () {
return localStorage;
}),
partialize: function partialize(state) {
return state;
},
version: 0,
merge: function merge(persistedState, currentState) {
return _extends({}, currentState, persistedState);
}
}, baseOptions);
var _hasHydrated = false;
var hydrationListeners = new Set();
var finishHydrationListeners = new Set();
var storage = options.storage;
if (!storage) {
return config(function () {
console.warn("[zustand persist middleware] Unable to update item '" + options.name + "', the given storage is currently unavailable.");
set.apply(void 0, arguments);
}, get, api);
}
var setItem = function setItem() {
var state = options.partialize(_extends({}, get()));
return storage.setItem(options.name, {
state: state,
version: options.version
});
};
var savedSetState = api.setState;
api.setState = function (state, replace) {
savedSetState(state, replace);
void setItem();
};
var configResult = config(function () {
set.apply(void 0, arguments);
void setItem();
}, get, api);
api.getInitialState = function () {
return configResult;
};
var stateFromStorage;
var hydrate = function hydrate() {
var _get2;
if (!storage) return;
_hasHydrated = false;
hydrationListeners.forEach(function (cb) {
var _get;
return cb((_get = get()) != null ? _get : configResult);
});
var postRehydrationCallback = (options.onRehydrateStorage == null ? void 0 : options.onRehydrateStorage((_get2 = get()) != null ? _get2 : configResult)) || undefined;
return toThenable(storage.getItem.bind(storage))(options.name).then(function (deserializedStorageValue) {
if (deserializedStorageValue) {
if (typeof deserializedStorageValue.version === 'number' && deserializedStorageValue.version !== options.version) {
if (options.migrate) {
return options.migrate(deserializedStorageValue.state, deserializedStorageValue.version);
}
console.error("State loaded from storage couldn't be migrated since no migrate function was provided");
} else {
return deserializedStorageValue.state;
}
}
}).then(function (migratedState) {
var _get3;
stateFromStorage = options.merge(migratedState, (_get3 = get()) != null ? _get3 : configResult);
set(stateFromStorage, true);
return setItem();
}).then(function () {
postRehydrationCallback == null || postRehydrationCallback(stateFromStorage, undefined);
stateFromStorage = get();
_hasHydrated = true;
finishHydrationListeners.forEach(function (cb) {
return cb(stateFromStorage);
});
}).catch(function (e) {
postRehydrationCallback == null || postRehydrationCallback(undefined, e);
});
};
api.persist = {
setOptions: function setOptions(newOptions) {
options = _extends({}, options, newOptions);
if (newOptions.storage) {
storage = newOptions.storage;
}
},
clearStorage: function clearStorage() {
var _storage;
(_storage = storage) == null || _storage.removeItem(options.name);
},
getOptions: function getOptions() {
return options;
},
rehydrate: function rehydrate() {
return hydrate();
},
hasHydrated: function hasHydrated() {
return _hasHydrated;
},
onHydrate: function onHydrate(cb) {
hydrationListeners.add(cb);
return function () {
hydrationListeners.delete(cb);
};
},
onFinishHydration: function onFinishHydration(cb) {
finishHydrationListeners.add(cb);
return function () {
finishHydrationListeners.delete(cb);
};
}
};
if (!options.skipHydration) {
hydrate();
}
return stateFromStorage || configResult;
};
};
var persist = persistImpl;
exports.combine = combine;
exports.createJSONStorage = createJSONStorage;
exports.devtools = devtools;
exports.persist = persist;
exports.redux = redux;
exports.subscribeWithSelector = subscribeWithSelector;
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var middleware_exports = {};
module.exports = __toCommonJS(middleware_exports);
__reExport(middleware_exports, require("./middleware/redux.ts"), module.exports);
__reExport(middleware_exports, require("./middleware/devtools.ts"), module.exports);
__reExport(middleware_exports, require("./middleware/subscribeWithSelector.ts"), module.exports);
__reExport(middleware_exports, require("./middleware/combine.ts"), module.exports);
__reExport(middleware_exports, require("./middleware/persist.ts"), module.exports);
'use strict';
var immer$1 = require('immer');
var immerImpl = function immerImpl(initializer) {
return function (set, get, store) {
store.setState = function (updater, replace) {
var nextState = typeof updater === 'function' ? immer$1.produce(updater) : updater;
for (var _len = arguments.length, a = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
a[_key - 2] = arguments[_key];
}
return set.apply(void 0, [nextState, replace].concat(a));
};
return initializer(store.setState, get, store);
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var immer_exports = {};
__export(immer_exports, {
immer: () => immer
});
module.exports = __toCommonJS(immer_exports);
var import_immer = require("immer");
const immerImpl = (initializer) => (set, get, store) => {
store.setState = (updater, replace, ...a) => {
const nextState = typeof updater === "function" ? (0, import_immer.produce)(updater) : updater;
return set(nextState, replace, ...a);
};
return initializer(store.setState, get, store);
};
var immer = immerImpl;
exports.immer = immer;
const immer = immerImpl;

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

*/
migrate?: (persistedState: unknown, version: number) => S | Promise<S>;
migrate?: (persistedState: unknown, version: number) => PersistedState | Promise<PersistedState>;
/**

@@ -57,0 +57,0 @@ * A function to perform custom hydration merges when combining the stored state with the current one.

{
"name": "zustand",
"private": false,
"version": "5.0.0-alpha.3",
"version": "5.0.0-alpha.4",
"publishConfig": {

@@ -100,3 +100,4 @@ "tag": "next"

}
}
},
"packageManager": "yarn@1.22.21+sha256.dbed5b7e10c552ba0e1a545c948d5473bc6c5a28ce22a8fd27e493e3e5eb6370"
}
'use strict';
var ReactExports = require('react');
var vanilla = require('zustand/vanilla');
var useDebugValue = ReactExports.useDebugValue,
useMemo = ReactExports.useMemo,
useSyncExternalStore = ReactExports.useSyncExternalStore;
var identity = function identity(arg) {
return arg;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var useMemoSelector = function useMemoSelector(getState, selector) {
return useMemo(function () {
var prev;
return function () {
var state = getState();
if (!prev || !Object.is(prev[0], state)) {
prev = [state, selector(state)];
}
return prev[1];
};
}, [getState, selector]);
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
function useStore(api, selector) {
if (selector === void 0) {
selector = identity;
}
var slice = useSyncExternalStore(api.subscribe, useMemoSelector(api.getState, selector), useMemoSelector(api.getInitialState, selector));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var react_exports = {};
__export(react_exports, {
create: () => create,
useStore: () => useStore
});
module.exports = __toCommonJS(react_exports);
var import_react = __toESM(require("react"));
var import_vanilla = require("./vanilla.ts");
const { useDebugValue, useMemo, useSyncExternalStore } = import_react.default;
const identity = (arg) => arg;
const useMemoSelector = (getState, selector) => useMemo(() => {
let prev;
return () => {
const state = getState();
if (!prev || !Object.is(prev[0], state)) {
prev = [state, selector(state)];
}
return prev[1];
};
}, [getState, selector]);
function useStore(api, selector = identity) {
const slice = useSyncExternalStore(
api.subscribe,
useMemoSelector(api.getState, selector),
useMemoSelector(api.getInitialState, selector)
);
useDebugValue(slice);
return slice;
}
var createImpl = function createImpl(createState) {
var api = vanilla.createStore(createState);
var useBoundStore = function useBoundStore(selector) {
return useStore(api, selector);
};
const createImpl = (createState) => {
const api = (0, import_vanilla.createStore)(createState);
const useBoundStore = (selector) => useStore(api, selector);
Object.assign(useBoundStore, api);
return useBoundStore;
};
var create = function create(createState) {
return createState ? createImpl(createState) : createImpl;
};
exports.create = create;
exports.useStore = useStore;
const create = (createState) => createState ? createImpl(createState) : createImpl;
'use strict';
var ReactExports = require('react');
var shallow = require('zustand/vanilla/shallow');
var useRef = ReactExports.useRef;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var shallow_exports = {};
__export(shallow_exports, {
useShallow: () => useShallow
});
module.exports = __toCommonJS(shallow_exports);
var import_react = __toESM(require("react"));
var import_shallow = require("../vanilla/shallow.ts");
const { useRef } = import_react.default;
function useShallow(selector) {
var prev = useRef();
return function (state) {
var next = selector(state);
return shallow.shallow(prev.current, next) ? prev.current : prev.current = next;
const prev = useRef();
return (state) => {
const next = selector(state);
return (0, import_shallow.shallow)(prev.current, next) ? prev.current : prev.current = next;
};
}
exports.useShallow = useShallow;
'use strict';
var shallow = require('zustand/vanilla/shallow');
var shallow$1 = require('zustand/react/shallow');
Object.defineProperty(exports, "shallow", {
enumerable: true,
get: function () { return shallow.shallow; }
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var shallow_exports = {};
__export(shallow_exports, {
shallow: () => import_shallow.shallow,
useShallow: () => import_shallow2.useShallow
});
Object.defineProperty(exports, "useShallow", {
enumerable: true,
get: function () { return shallow$1.useShallow; }
});
module.exports = __toCommonJS(shallow_exports);
var import_shallow = require("./vanilla/shallow.ts");
var import_shallow2 = require("./react/shallow.ts");
'use strict';
var ReactExports = require('react');
var useSyncExternalStoreExports = require('use-sync-external-store/shim/with-selector');
var vanilla = require('zustand/vanilla');
var useDebugValue = ReactExports.useDebugValue;
var useSyncExternalStoreWithSelector = useSyncExternalStoreExports.useSyncExternalStoreWithSelector;
var identity = function identity(arg) {
return arg;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
function useStoreWithEqualityFn(api, selector, equalityFn) {
if (selector === void 0) {
selector = identity;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
var slice = useSyncExternalStoreWithSelector(api.subscribe, api.getState, api.getInitialState, selector, equalityFn);
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var traditional_exports = {};
__export(traditional_exports, {
createWithEqualityFn: () => createWithEqualityFn,
useStoreWithEqualityFn: () => useStoreWithEqualityFn
});
module.exports = __toCommonJS(traditional_exports);
var import_react = __toESM(require("react"));
var import_with_selector = __toESM(require("use-sync-external-store/shim/with-selector"));
var import_vanilla = require("./vanilla.ts");
const { useDebugValue } = import_react.default;
const { useSyncExternalStoreWithSelector } = import_with_selector.default;
const identity = (arg) => arg;
function useStoreWithEqualityFn(api, selector = identity, equalityFn) {
const slice = useSyncExternalStoreWithSelector(
api.subscribe,
api.getState,
api.getInitialState,
selector,
equalityFn
);
useDebugValue(slice);
return slice;
}
var createWithEqualityFnImpl = function createWithEqualityFnImpl(createState, defaultEqualityFn) {
var api = vanilla.createStore(createState);
var useBoundStoreWithEqualityFn = function useBoundStoreWithEqualityFn(selector, equalityFn) {
if (equalityFn === void 0) {
equalityFn = defaultEqualityFn;
}
return useStoreWithEqualityFn(api, selector, equalityFn);
};
const createWithEqualityFnImpl = (createState, defaultEqualityFn) => {
const api = (0, import_vanilla.createStore)(createState);
const useBoundStoreWithEqualityFn = (selector, equalityFn = defaultEqualityFn) => useStoreWithEqualityFn(api, selector, equalityFn);
Object.assign(useBoundStoreWithEqualityFn, api);
return useBoundStoreWithEqualityFn;
};
var createWithEqualityFn = function createWithEqualityFn(createState, defaultEqualityFn) {
return createState ? createWithEqualityFnImpl(createState, defaultEqualityFn) : createWithEqualityFnImpl;
};
exports.createWithEqualityFn = createWithEqualityFn;
exports.useStoreWithEqualityFn = useStoreWithEqualityFn;
const createWithEqualityFn = (createState, defaultEqualityFn) => createState ? createWithEqualityFnImpl(createState, defaultEqualityFn) : createWithEqualityFnImpl;
'use strict';
var createStoreImpl = function createStoreImpl(createState) {
var state;
var listeners = new Set();
var setState = function setState(partial, replace) {
var nextState = typeof partial === 'function' ? partial(state) : partial;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var vanilla_exports = {};
__export(vanilla_exports, {
createStore: () => createStore
});
module.exports = __toCommonJS(vanilla_exports);
const createStoreImpl = (createState) => {
let state;
const listeners = /* @__PURE__ */ new Set();
const setState = (partial, replace) => {
const nextState = typeof partial === "function" ? partial(state) : partial;
if (!Object.is(nextState, state)) {
var previousState = state;
state = (replace != null ? replace : typeof nextState !== 'object' || nextState === null) ? nextState : Object.assign({}, state, nextState);
listeners.forEach(function (listener) {
return listener(state, previousState);
});
const previousState = state;
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
listeners.forEach((listener) => listener(state, previousState));
}
};
var getState = function getState() {
return state;
};
var getInitialState = function getInitialState() {
return initialState;
};
var subscribe = function subscribe(listener) {
const getState = () => state;
const getInitialState = () => initialState;
const subscribe = (listener) => {
listeners.add(listener);
return function () {
return listeners.delete(listener);
};
return () => listeners.delete(listener);
};
var api = {
setState: setState,
getState: getState,
getInitialState: getInitialState,
subscribe: subscribe
};
var initialState = state = createState(setState, getState, api);
const api = { setState, getState, getInitialState, subscribe };
const initialState = state = createState(setState, getState, api);
return api;
};
var createStore = function createStore(createState) {
return createState ? createStoreImpl(createState) : createStoreImpl;
};
exports.createStore = createStore;
const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
'use strict';
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (it) return (it = it.call(o)).next.bind(it);
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
};
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var shallow_exports = {};
__export(shallow_exports, {
shallow: () => shallow
});
module.exports = __toCommonJS(shallow_exports);
function shallow(objA, objB) {

@@ -39,11 +29,9 @@ if (Object.is(objA, objB)) {

}
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
return false;
}
if (objA instanceof Map && objB instanceof Map) {
if (objA.size !== objB.size) return false;
for (var _iterator = _createForOfIteratorHelperLoose(objA), _step; !(_step = _iterator()).done;) {
var _step$value = _step.value,
key = _step$value[0],
value = _step$value[1];
if (objA.size !== objB.size)
return false;
for (const [key, value] of objA) {
if (!Object.is(value, objB.get(key))) {

@@ -56,6 +44,6 @@ return false;

if (objA instanceof Set && objB instanceof Set) {
if (objA.size !== objB.size) return false;
for (var _iterator2 = _createForOfIteratorHelperLoose(objA), _step2; !(_step2 = _iterator2()).done;) {
var _value = _step2.value;
if (!objB.has(_value)) {
if (objA.size !== objB.size)
return false;
for (const value of objA) {
if (!objB.has(value)) {
return false;

@@ -66,8 +54,8 @@ }

}
var keysA = Object.keys(objA);
const keysA = Object.keys(objA);
if (keysA.length !== Object.keys(objB).length) {
return false;
}
for (var i = 0; i < keysA.length; i++) {
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
for (const keyA of keysA) {
if (!Object.hasOwn(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {
return false;

@@ -78,3 +66,1 @@ }

}
exports.shallow = shallow;

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