Socket
Socket
Sign inDemoInstall

zustand-fetching

Package Overview
Dependencies
11
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.4.3 to 2.4.4

2

dist/examples/controllers/6_Controller_GroupRequest.js

@@ -14,3 +14,3 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";

fulfilled: ({ result, payload }) => {
console.log("everything ok", result.type, payload);
// console.log("everything ok", result.type, payload);
},

@@ -17,0 +17,0 @@ });

@@ -17,3 +17,3 @@ export const getUser = async (id, signal) => {

setTimeout(() => {
console.log(user); // send to server
// console.log(user); // send to server
resolve();

@@ -20,0 +20,0 @@ }, 2000);

@@ -22,3 +22,3 @@ import { StoreApi } from "zustand/esm";

interface ILeitenGroupRequestOption<Payload, Result> extends ILeitenRequestOptions<ILeitenGroupRequestParams<Payload>, Result> {
initialContent?: Result;
initialContent?: Result | ((key: string) => Result);
}

@@ -28,3 +28,5 @@ interface ILeitenGroupRequestArrayOption<Payload, Result> extends ILeitenGroupRequestOption<Payload, Result> {

}
export declare const leitenGroupRequest: <Store extends object, P extends DotNestedKeys<Store>, Payload, Result>(store: StoreApi<Store>, path: P extends string ? DotNestedValue<Store, P> extends Record<string, Result> | Result[] ? P : never : never, payloadCreator: (params: ILeitenGroupRequestParams<Payload>) => Promise<Result>, options?: (DotNestedValue<Store, P> extends Record<string, Result> ? ILeitenGroupRequestOption<Payload, Result> : ILeitenGroupRequestArrayOption<Payload, Result>) | undefined) => ILeitenGroupRequest<Payload, Result>;
type AcceptableType<Store extends object> = void | DotNestedValue<Store, DotNestedKeys<Store>> | null;
/** @deprecated use leitenGroupRequest from leiten-zustand library instead */
export declare const leitenGroupRequest: <Store extends object, P extends DotNestedKeys<Store>, Payload, Result extends DotNestedValue<Store, P> extends Record<string, AcceptableType<Store>> ? DotNestedValue<Store, P>[string] : DotNestedValue<Store, P> extends AcceptableType<Store>[] ? DotNestedValue<Store, P>[number] : DotNestedValue<Store, P>>(store: StoreApi<Store>, path: P extends string ? Result extends void ? P : DotNestedValue<Store, P> extends Record<string, Result> | Result[] ? P : never : never, payloadCreator: (params: ILeitenGroupRequestParams<Payload>) => Promise<Result>, options?: (DotNestedValue<Store, P> extends Record<string, AcceptableType<Store>> ? ILeitenGroupRequestOption<Payload, Result> : ILeitenGroupRequestArrayOption<Payload, Result>) | undefined) => ILeitenGroupRequest<Payload, Result>;
export {};

@@ -7,2 +7,3 @@ import { produce } from "immer";

import { leitenRequest, } from "./leitenRequest";
/** @deprecated use leitenGroupRequest from leiten-zustand library instead */
export const leitenGroupRequest = (store, path, payloadCreator, options) => {

@@ -13,3 +14,4 @@ const initialRequestState = initialLeitenLoading(options === null || options === void 0 ? void 0 : options.initialStatus);

const getPathToArrayItem = (key) => {
const source = get(store.getState(), path, []);
const raw = get(store.getState(), path, []);
const source = Array.isArray(raw) ? raw : [];
const find = source.findIndex((s) => {

@@ -24,4 +26,2 @@ var _a;

const add = (key) => {
// const state = requests[key];
// if (!state) {
let pathWithKey = "";

@@ -47,10 +47,13 @@ let payload = payloadCreator;

pathWithKey = (path + `.${key}`);
const nextState = produce(store.getState(), (draft) => {
var _a;
set(draft, pathWithKey, (_a = options === null || options === void 0 ? void 0 : options.initialContent) !== null && _a !== void 0 ? _a : null);
});
store.setState(nextState);
if (options === null || options === void 0 ? void 0 : options.initialContent) {
const initial = checkInitial(options.initialContent)
? options.initialContent(key)
: options.initialContent;
const nextState = produce(store.getState(), (draft) => {
set(draft, pathWithKey, initial);
});
store.setState(nextState);
}
}
requests[key] = leitenRequest(store, pathWithKey, payload, options);
// }
};

@@ -107,12 +110,15 @@ const call = (params, options) => {

}
const resettable = store.getState()["_resettableLifeCycle"] !== undefined;
if (resettable) {
store.subscribe((next) => {
if (next["_resettableLifeCycle"] === false)
clear();
});
}
setTimeout(() => {
const resettable = store.getState()["_resettableLifeCycle"] !== undefined;
if (resettable) {
store.subscribe((next, prev) => {
if (next["_resettableLifeCycle"] === false &&
prev["_resettableLifeCycle"] === true)
clear();
});
}
}, 0);
return Object.assign(hook, { clear, call, requests });
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const nonTypedReturn = (value) => value;
const checkInitial = (value) => typeof value === "function";

@@ -18,3 +18,4 @@ import { StoreApi } from "zustand/esm";

}
/** @deprecated use leitenList from leiten-zustand library instead */
export declare const leitenList: <Store extends object, P extends DotNestedKeys<Store>>(store: StoreApi<Store>, path: P extends string ? DotNestedValue<Store, P> extends any[] | null ? P : never : never, params?: ILeitenListEffects<ArrayElement<DotNestedValue<Store, P>>, Store> | undefined) => ILeitenList<ArrayElement<DotNestedValue<Store, P>>>;
export {};
import { produce } from "immer";
import { get, isArray, set } from "lodash-es";
/** @deprecated use leitenList from leiten-zustand library instead */
export const leitenList = (store,

@@ -8,3 +9,3 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any

if (initialValue === "_empty") {
throw new Error("[leitenList] The defined path does not exist");
throw new Error("[leitenList] The defined path does not match the required structure");
}

@@ -11,0 +12,0 @@ const compare = (params === null || params === void 0 ? void 0 : params.compare) || defaultCompareList;

@@ -14,2 +14,3 @@ import { StoreApi } from "zustand";

}
/** @deprecated use leitenModal from leiten-zustand library instead */
export declare const leitenModal: <Store extends object, P extends DotNestedKeys<Store>>(store: StoreApi<Store>, path: P extends string ? P : never, extra?: {

@@ -16,0 +17,0 @@ reaction?: ((params: {

@@ -6,2 +6,3 @@ import { produce } from "immer";

import { leitenModalManagerAction, useLeitenModalStack, } from "../hooks/useLeitenModals";
/** @deprecated use leitenModal from leiten-zustand library instead */
export const leitenModal = (store, path, extra) => {

@@ -47,3 +48,3 @@ const initialData = get(store.getState(), path, "_empty");

const open = (data, replace) => {
action({ type: "OPEN", payload: data || initialData, replace });
action({ type: "OPEN", payload: data, replace });
};

@@ -50,0 +51,0 @@ const close = () => action({ type: "CLOSE" });

@@ -6,2 +6,3 @@ import { StoreApi } from "zustand/esm";

type ValueOf<T> = T extends Record<infer _K, infer V> ? V : never;
/** @deprecated use leitenNormalizedList from leiten-zustand library instead */
export declare const leitenNormalizedList: <Store extends object, P extends DotNestedKeys<Store>>(store: StoreApi<Store>, path: P extends string ? DotNestedValue<Store, P> extends Record<string, unknown> ? P : never : never, params: {

@@ -8,0 +9,0 @@ compare?: ((left: ValueOf<DotNestedValue<Store, P>>, right: ValueOf<DotNestedValue<Store, P>>) => boolean) | undefined;

import { produce } from "immer";
import { get, set } from "lodash-es";
/** @deprecated use leitenNormalizedList from leiten-zustand library instead */
export const leitenNormalizedList = (store, path, params) => {

@@ -4,0 +5,0 @@ const initialValue = get(store.getState(), path, "_empty");

@@ -14,3 +14,4 @@ import { StoreApi } from "zustand";

};
/** @deprecated use leitenPrimitive from leiten-zustand library instead */
export declare const leitenPrimitive: <Store extends object, P extends DotNestedKeys<Store>>(store: StoreApi<Store>, path: P extends string ? P : never, effects?: ILeitenPrimitiveEffects<DotNestedValue<Store, P>, Store> | undefined) => ILeitenPrimitive<DotNestedValue<Store, P>>;
export {};
import { produce } from "immer";
import { get, set } from "lodash-es";
/** @deprecated use leitenPrimitive from leiten-zustand library instead */
export const leitenPrimitive = (store, path, effects) => {

@@ -12,13 +13,13 @@ const initialValue = get(store.getState(), path, "_empty");

};
const setState = (value) => {
const setState = (next) => {
var _a;
const prev = getState();
const draftState = produce(store.getState(), (draft) => {
set(draft, path, value);
set(draft, path, next);
});
const nextState = (effects === null || effects === void 0 ? void 0 : effects.patchEffect)
? { ...effects.patchEffect(value), ...draftState }
? { ...effects.patchEffect(next), ...draftState }
: draftState;
store.setState(nextState);
(_a = effects === null || effects === void 0 ? void 0 : effects.sideEffect) === null || _a === void 0 ? void 0 : _a.call(effects, { prev, next: value });
(_a = effects === null || effects === void 0 ? void 0 : effects.sideEffect) === null || _a === void 0 ? void 0 : _a.call(effects, { prev, next });
};

@@ -25,0 +26,0 @@ const clear = () => {

@@ -15,3 +15,4 @@ import { StoreApi } from "zustand/esm";

}
/** @deprecated use leitenRecord from leiten-zustand library instead */
export declare const leitenRecord: <Store extends object, P extends DotNestedKeys<Store>>(store: StoreApi<Store>, path: P extends string ? DotNestedValue<Store, P> extends any[] ? never : DotNestedValue<Store, P> extends object | null ? P : never : never, effects?: ILeitenRecordEffects<DotNestedValue<Store, P>, Store> | undefined) => ILeitenRecord<DotNestedValue<Store, P>>;
export {};
import { produce } from "immer";
import { get, set } from "lodash-es";
/** @deprecated use leitenRecord from leiten-zustand library instead */
export const leitenRecord = (store, path, effects) => {

@@ -12,13 +13,13 @@ const initialValue = get(store.getState(), path, "_empty");

};
const setState = (value) => {
const setState = (next) => {
var _a;
const prev = getState();
const draftState = produce(store.getState(), (draft) => {
set(draft, path, value);
set(draft, path, next);
});
const nextState = (effects === null || effects === void 0 ? void 0 : effects.patchEffect)
? { ...effects.patchEffect(value), ...draftState }
? { ...effects.patchEffect(next), ...draftState }
: draftState;
store.setState(nextState);
(_a = effects === null || effects === void 0 ? void 0 : effects.sideEffect) === null || _a === void 0 ? void 0 : _a.call(effects, { prev, next: value });
(_a = effects === null || effects === void 0 ? void 0 : effects.sideEffect) === null || _a === void 0 ? void 0 : _a.call(effects, { prev, next });
};

@@ -25,0 +26,0 @@ const clear = () => {

@@ -14,2 +14,3 @@ import { StoreApi } from "zustand";

key: string;
getState: () => ILeitenLoading<Payload, Result>;
}

@@ -32,3 +33,4 @@ export interface ILeitenRequestCallback<Payload, Result> {

}
export declare const leitenRequest: <Store extends object, P extends DotNestedKeys<Store>, Payload, Result>(store: StoreApi<Store>, path: P extends string ? Result extends void ? P : DotNestedValue<Store, P> extends Result | null ? P : never : never, payloadCreator: (params: Payload, extraArgument?: IExtraArgument) => Promise<Result>, options?: ILeitenRequestOptions<Payload, Result> | undefined) => ILeitenRequest<Payload, Result>;
/** @deprecated use leitenRequest from leiten-zustand library instead */
export declare const leitenRequest: <Store extends object, P extends DotNestedKeys<Store>, Payload, Result extends void | DotNestedValue<Store, P> | null>(store: StoreApi<Store>, path: P extends string ? Result extends void ? P : DotNestedValue<Store, P> extends Result | null ? P : never : never, payloadCreator: (params: Payload, extraArgument?: IExtraArgument) => Promise<Result>, options?: ILeitenRequestOptions<Payload, Result> | undefined) => ILeitenRequest<Payload, Result>;
type IExtraArgument = {

@@ -35,0 +37,0 @@ signal: AbortSignal;

@@ -7,6 +7,7 @@ import { produce } from "immer";

import { initialLeitenLoading, } from "../interfaces/IContentLoading";
/** @deprecated use leitenRequest from leiten-zustand library instead */
export const leitenRequest = (store, path, payloadCreator, options) => {
const key = nanoid(12);
const initialState = initialLeitenLoading(options === null || options === void 0 ? void 0 : options.initialStatus);
const initialContent = get(store.getState(), path, null);
const initialState = initialLeitenLoading(options === null || options === void 0 ? void 0 : options.initialStatus);
const setState = (state) => {

@@ -43,2 +44,5 @@ useLeitenRequests.setState({ [key]: state });

}
else {
value !== undefined && value !== null && setContent(value);
}
};

@@ -115,10 +119,15 @@ let previousResult = getContent();

};
const resettable = store.getState()["_resettableLifeCycle"] !== undefined;
if (resettable) {
store.subscribe((next, prev) => {
if (next["_resettableLifeCycle"] === false &&
prev["_resettableLifeCycle"] === true)
setState(initialState);
});
}
setTimeout(() => {
const resettable = store.getState()["_resettableLifeCycle"] !== undefined;
if (resettable) {
store.subscribe((next, prev) => {
if (next["_resettableLifeCycle"] === false &&
prev["_resettableLifeCycle"] === true)
setState(initialState);
});
}
}, 0);
const _getState = () => {
return useLeitenRequests.getState()[key];
};
return Object.assign(useRequest, {

@@ -130,2 +139,3 @@ abort: _abort,

key,
getState: _getState,
});

@@ -132,0 +142,0 @@ };

import { ILeitenLoading } from "../interfaces/IContentLoading";
/** @deprecated use useLeitenRequests from leiten-zustand library instead */
export declare const useLeitenRequests: import("zustand").UseBoundStore<import("zustand").StoreApi<{

@@ -3,0 +4,0 @@ [key: string]: ILeitenLoading<any, any>;

import { create } from "zustand";
import { initialLeitenLoading, } from "../interfaces/IContentLoading";
/* eslint-disable @typescript-eslint/no-explicit-any */
/** @deprecated use useLeitenRequests from leiten-zustand library instead */
export const useLeitenRequests = create(() => ({}));

@@ -5,0 +6,0 @@ export const leitenMap = (keys, selector) => {

import { ReactNode } from "react";
import { StateCreator, StoreApi } from "zustand";
/** @deprecated use leitenContext from leiten-zustand library instead */
export declare const leitenContext: <STATE, R>(state: StateCreator<STATE, [], [], STATE>, applyStore?: ((store: StoreApi<STATE>) => R) | undefined) => readonly [<R_1>(selector: (s: STATE) => R_1, equalityFn?: ((a: R_1, b: R_1) => boolean) | undefined) => R_1, ({ children }: {
children: ReactNode;
}) => import("react/jsx-runtime").JSX.Element, <T>(selector: (withStore: R) => T) => T];
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useState } from "react";
import { create, useStore } from "zustand";
/** @deprecated use leitenContext from leiten-zustand library instead */
export const leitenContext = (state, applyStore) => {

@@ -5,0 +6,0 @@ const StoreContext = createContext({ store: null, withStore: null });

import { ReactNode } from "react";
import { StoreApi } from "zustand";
/** @deprecated use leitenResettable from leiten-zustand library instead */
export declare const leitenResettable: <Store, _>(useStore: StoreApi<Store>, getState?: (() => Store) | undefined) => ({ children }: {
children?: ReactNode;
}) => import("react/jsx-runtime").JSX.Element;
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from "react";
/** @deprecated use leitenResettable from leiten-zustand library instead */
export const leitenResettable = (useStore, getState) => {

@@ -4,0 +5,0 @@ const initialState = useStore.getState();

{
"name": "zustand-fetching",
"version": "2.4.3",
"version": "2.4.4",
"private": false,

@@ -5,0 +5,0 @@ "description": "Zustand state manager controllers",

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc