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

zustand-utils

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zustand-utils - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

2

es/context.d.ts

@@ -20,3 +20,3 @@ import type { ReactNode } from 'react';

createStore: () => S;
children: any;
children: ReactNode;
}) => import("react").FunctionComponentElement<import("react").ProviderProps<S | undefined>>;

@@ -23,0 +23,0 @@ useStore: UseContextStore<S>;

@@ -5,3 +5,11 @@ import { StoreApi } from 'zustand';

};
export declare const createStoreUpdater: <T>(storeApi: WithoutCallSignature<StoreApi<T>>) => (key: keyof T, value: any, deps?: any[], setStoreState?: ((param: any) => void) | undefined) => void;
/**
* 该函数接收四个参数:key,value 、 deps setStoreState
* @param {key}:需要更新的 Store 中的 key
* @param value:需要更新的值
* @param deps:依赖项数组,默认为 [value]
* @param setStoreState:一个可选的回调函数,用于更新 Store 状态
*/
export declare type UseStoreUpdater<T> = (key: keyof T, value: any, deps: any[], setStateFn?: (state: T) => void) => void;
export declare const createStoreUpdater: <T>(storeApi: WithoutCallSignature<StoreApi<T>>) => UseStoreUpdater<T>;
export {};

@@ -5,23 +5,21 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

export var createStoreUpdater = function createStoreUpdater(storeApi) {
return (
// 该函数接收三个参数:key,value 和 deps
// key:需要更新的 Store 中的 key
// value:需要更新的值
// deps:依赖项数组,默认为 [value]
// setStoreState:一个可选的回调函数,用于更新 Store 状态
function (key, value) {
var deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [value];
var setStoreState = arguments.length > 3 ? arguments[3] : undefined;
// 获取 Store 更新函数
var setState = setStoreState !== null && setStoreState !== void 0 ? setStoreState : storeApi.setState;
// 使用 useEffect 监听依赖项变化
useEffect(function () {
// 如果 value 不为 undefined,就更新 Store 中的指定 key 的值
if (typeof value !== 'undefined') {
// @ts-ignore
setState(_defineProperty({}, key, value));
}
}, deps);
}
);
return function (key, value) {
var deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [value];
var setStateFn = arguments.length > 3 ? arguments[3] : undefined;
// 获取 Store 更新函数
var setState = setStateFn !== null && setStateFn !== void 0 ? setStateFn : storeApi.setState;
// 使用 useEffect 监听依赖项变化
useEffect(function () {
// 如果 value 不为 undefined,就更新 Store 中的指定 key 的值
if (typeof value !== 'undefined') {
// @ts-ignore
setState(_defineProperty({}, key, value), false, {
type: "\uD83D\uDCAD useStoreUpdater/ ".concat(key),
payload: {
value: value
}
});
}
}, deps);
};
};

@@ -20,3 +20,3 @@ import type { ReactNode } from 'react';

createStore: () => S;
children: any;
children: ReactNode;
}) => import("react").FunctionComponentElement<import("react").ProviderProps<S | undefined>>;

@@ -23,0 +23,0 @@ useStore: UseContextStore<S>;

@@ -5,3 +5,11 @@ import { StoreApi } from 'zustand';

};
export declare const createStoreUpdater: <T>(storeApi: WithoutCallSignature<StoreApi<T>>) => (key: keyof T, value: any, deps?: any[], setStoreState?: ((param: any) => void) | undefined) => void;
/**
* 该函数接收四个参数:key,value 、 deps setStoreState
* @param {key}:需要更新的 Store 中的 key
* @param value:需要更新的值
* @param deps:依赖项数组,默认为 [value]
* @param setStoreState:一个可选的回调函数,用于更新 Store 状态
*/
export declare type UseStoreUpdater<T> = (key: keyof T, value: any, deps: any[], setStateFn?: (state: T) => void) => void;
export declare const createStoreUpdater: <T>(storeApi: WithoutCallSignature<StoreApi<T>>) => UseStoreUpdater<T>;
export {};

@@ -12,24 +12,22 @@ "use strict";

var createStoreUpdater = function createStoreUpdater(storeApi) {
return (
// 该函数接收三个参数:key,value 和 deps
// key:需要更新的 Store 中的 key
// value:需要更新的值
// deps:依赖项数组,默认为 [value]
// setStoreState:一个可选的回调函数,用于更新 Store 状态
function (key, value) {
var deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [value];
var setStoreState = arguments.length > 3 ? arguments[3] : undefined;
// 获取 Store 更新函数
var setState = setStoreState !== null && setStoreState !== void 0 ? setStoreState : storeApi.setState;
// 使用 useEffect 监听依赖项变化
(0, _react.useEffect)(function () {
// 如果 value 不为 undefined,就更新 Store 中的指定 key 的值
if (typeof value !== 'undefined') {
// @ts-ignore
setState((0, _defineProperty2.default)({}, key, value));
}
}, deps);
}
);
return function (key, value) {
var deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [value];
var setStateFn = arguments.length > 3 ? arguments[3] : undefined;
// 获取 Store 更新函数
var setState = setStateFn !== null && setStateFn !== void 0 ? setStateFn : storeApi.setState;
// 使用 useEffect 监听依赖项变化
(0, _react.useEffect)(function () {
// 如果 value 不为 undefined,就更新 Store 中的指定 key 的值
if (typeof value !== 'undefined') {
// @ts-ignore
setState((0, _defineProperty2.default)({}, key, value), false, {
type: "\uD83D\uDCAD useStoreUpdater/ ".concat(key),
payload: {
value: value
}
});
}
}, deps);
};
};
exports.createStoreUpdater = createStoreUpdater;
{
"name": "zustand-utils",
"version": "1.2.2",
"version": "1.2.3",
"description": "some utils for zustand",

@@ -41,5 +41,5 @@ "keywords": [

"start": "dumi dev",
"test": "jest --passWithNoTests",
"test:coverage": "jest --coverage --passWithNoTests",
"test:update": "jest --update-snapshot",
"test": "vitest",
"test:coverage": "vitest run --coverage",
"test:update": "vitest -u",
"type-check": "tsc -p tsconfig-check.json"

@@ -65,10 +65,7 @@ },

"@commitlint/cli": "^17",
"@testing-library/jest-dom": "^5",
"@testing-library/react": "^13",
"@types/jest": "^27",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/testing-library__jest-dom": "^5",
"@umijs/lint": "^4",
"@umijs/test": "^4",
"@vitest/coverage-c8": "latest",
"antd": "^5",

@@ -85,4 +82,3 @@ "commitlint": "^17",

"husky": "^8",
"jest": "^29",
"jest-environment-jsdom": "^29",
"jsdom": "^21",
"lint-staged": "^13",

@@ -97,5 +93,4 @@ "prettier": "^2",

"stylelint": "^14",
"ts-jest": "^29",
"ts-node": "^10",
"typescript": "^4",
"typescript": "^5",
"vitest": "latest",
"zustand": "^4"

@@ -102,0 +97,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