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.1 to 5.0.0-alpha.2

esm/react.mjs

58

index.js
'use strict';
var vanilla = require('zustand/vanilla');
var ReactExports = require('react');
var react = require('zustand/react');
var useDebugValue = ReactExports.useDebugValue,
useMemo = ReactExports.useMemo,
useSyncExternalStore = ReactExports.useSyncExternalStore;
var identity = function identity(arg) {
return arg;
};
var useMemoSelector = function useMemoSelector(getState, selector) {
return useMemo(function () {
var lastSlice;
var lastState;
return function () {
var state = getState();
if (!Object.is(lastState, state)) {
lastSlice = selector(state);
lastState = state;
}
return lastSlice;
};
}, [getState, selector]);
};
function useStore(api, selector) {
if (selector === void 0) {
selector = identity;
}
var 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);
};
Object.assign(useBoundStore, api);
return useBoundStore;
};
var create = function create(createState) {
return createState ? createImpl(createState) : createImpl;
};
exports.create = create;
exports.useStore = useStore;
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]; }
});
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]; }
});
});
{
"name": "zustand",
"private": false,
"version": "5.0.0-alpha.1",
"version": "5.0.0-alpha.2",
"publishConfig": {

@@ -6,0 +6,0 @@ "tag": "next"

'use strict';
var ReactExports = require('react');
var shallow = require('zustand/vanilla/shallow');
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++]
};
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function shallow(objA, objB) {
if (Object.is(objA, objB)) {
return true;
}
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 (!Object.is(value, objB.get(key))) {
return false;
}
}
return true;
}
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)) {
return false;
}
}
return true;
}
var 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]])) {
return false;
}
}
return true;
}
var useRef = ReactExports.useRef;

@@ -83,3 +11,3 @@ function useShallow(selector) {

var next = selector(state);
return shallow(prev.current, next) ? prev.current : prev.current = next;
return shallow.shallow(prev.current, next) ? prev.current : prev.current = next;
};

@@ -86,0 +14,0 @@ }

'use strict';
var ReactExports = require('react');
var shallow = require('zustand/vanilla/shallow');
var shallow$1 = require('zustand/react/shallow');
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++]
};
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function shallow(objA, objB) {
if (Object.is(objA, objB)) {
return true;
}
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 (!Object.is(value, objB.get(key))) {
return false;
}
}
return true;
}
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)) {
return false;
}
}
return true;
}
var 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]])) {
return false;
}
}
return true;
}
var useRef = ReactExports.useRef;
function useShallow(selector) {
var prev = useRef();
return function (state) {
var next = selector(state);
return shallow(prev.current, next) ? prev.current : prev.current = next;
};
}
exports.shallow = shallow;
exports.useShallow = useShallow;
Object.defineProperty(exports, "shallow", {
enumerable: true,
get: function () { return shallow.shallow; }
});
Object.defineProperty(exports, "useShallow", {
enumerable: true,
get: function () { return shallow$1.useShallow; }
});

Sorry, the diff of this file is not supported yet

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