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

zustand

Package Overview
Dependencies
Maintainers
1
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 0.0.5 to 0.0.6

14

.size-snapshot.json
{
"dist/index.js": {
"bundled": 1877,
"minified": 829,
"gzipped": 394,
"bundled": 2208,
"minified": 1103,
"gzipped": 524,
"treeshaked": {

@@ -12,3 +12,3 @@ "rollup": {

"webpack": {
"code": 998
"code": 1030
}

@@ -18,6 +18,6 @@ }

"dist/index.cjs.js": {
"bundled": 2665,
"minified": 1184,
"gzipped": 469
"bundled": 2833,
"minified": 1415,
"gzipped": 578
}
}

@@ -37,16 +37,5 @@ 'use strict';

// Get fresh selected state
var selected = selector ? selector(state.current) : state.current; // If state is not equal from the get go and not an atomic then shallow equal it
var selected = selector ? selector(state.current) : state.current; // Refresh local slice, functional initial b/c selected itself could be a function
if (sliceRef.current !== selected && selected === Object(selected)) {
selected = Object.entries(selected).reduce(function (acc, _ref) {
var _Object$assign;
var key = _ref[0],
value = _ref[1];
return sliceRef.current[key] !== value ? Object.assign({}, acc, (_Object$assign = {}, _Object$assign[key] = value, _Object$assign)) : acc;
}, sliceRef.current);
} // Refresh local slice, functional initial b/c selected itself could be a function
if (sliceRef.current !== selected) set(function () {
if (!shallowEqual(sliceRef.current, selected)) set(function () {
return selected;

@@ -82,3 +71,37 @@ });

}
var hasOwn = Object.prototype.hasOwnProperty;
function is(x, y) {
if (x === y) {
return x !== 0 || y !== 0 || 1 / x === 1 / y;
} else {
return x !== x && y !== y;
}
}
function shallowEqual(objA, objB) {
if (is(objA, objB)) {
return true;
}
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
for (var i = 0; i < keysA.length; i++) {
if (!hasOwn.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
return false;
}
}
return true;
}
module.exports = create;

@@ -22,12 +22,5 @@ import React from 'react';

// Get fresh selected state
let selected = selector ? selector(state.current) : state.current; // If state is not equal from the get go and not an atomic then shallow equal it
let selected = selector ? selector(state.current) : state.current; // Refresh local slice, functional initial b/c selected itself could be a function
if (sliceRef.current !== selected && selected === Object(selected)) {
selected = Object.entries(selected).reduce((acc, [key, value]) => sliceRef.current[key] !== value ? Object.assign({}, acc, {
[key]: value
}) : acc, sliceRef.current);
} // Refresh local slice, functional initial b/c selected itself could be a function
if (sliceRef.current !== selected) set(() => selected);
if (!shallowEqual(sliceRef.current, selected)) set(() => selected);
};

@@ -49,3 +42,37 @@

}
const hasOwn = Object.prototype.hasOwnProperty;
function is(x, y) {
if (x === y) {
return x !== 0 || y !== 0 || 1 / x === 1 / y;
} else {
return x !== x && y !== y;
}
}
function shallowEqual(objA, objB) {
if (is(objA, objB)) {
return true;
}
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
return false;
}
const keysA = Object.keys(objA);
const keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
for (let i = 0; i < keysA.length; i++) {
if (!hasOwn.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
return false;
}
}
return true;
}
export default create;
{
"name": "zustand",
"version": "0.0.5",
"version": "0.0.6",
"description": "🐻 Bear necessities for state management in React",

@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js",

@@ -27,14 +27,4 @@ import React from 'react'

let selected = selector ? selector(state.current) : state.current
// If state is not equal from the get go and not an atomic then shallow equal it
if (sliceRef.current !== selected && selected === Object(selected)) {
selected = Object.entries(selected).reduce(
(acc, [key, value]) =>
sliceRef.current[key] !== value
? Object.assign({}, acc, { [key]: value })
: acc,
sliceRef.current
)
}
// Refresh local slice, functional initial b/c selected itself could be a function
if (sliceRef.current !== selected) set(() => selected)
if (!shallowEqual(sliceRef.current, selected)) set(() => selected)
}

@@ -57,1 +47,34 @@ state.listeners.push(ping)

}
const hasOwn = Object.prototype.hasOwnProperty
function is(x, y) {
if (x === y) {
return x !== 0 || y !== 0 || 1 / x === 1 / y
} else {
return x !== x && y !== y
}
}
function shallowEqual(objA, objB) {
if (is(objA, objB)) {
return true
}
if (
typeof objA !== 'object' ||
objA === null ||
typeof objB !== 'object' ||
objB === null
) {
return false
}
const keysA = Object.keys(objA)
const keysB = Object.keys(objB)
if (keysA.length !== keysB.length) {
return false
}
for (let i = 0; i < keysA.length; i++) {
if (!hasOwn.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
return false
}
}
return true
}

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

import React, { useEffect } from 'react'
import React, { useEffect, useRef } from 'react'
import { cleanup, render } from 'react-testing-library'

@@ -18,2 +18,4 @@ import create from '../src/index'

const { count, inc, dec } = useStore()
const renderCount = useRef(0)
useEffect(() => {

@@ -24,4 +26,10 @@ dec()

console.log('r', count)
expect(count).toBe(1)
useEffect(() => {
if (renderCount.current === 0) {
expect(count).toBe(1)
} else if (renderCount.current >= 1) {
expect(count).toBe(0)
}
})
useEffect(() => void ++renderCount.current)
return count

@@ -28,0 +36,0 @@ }

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