zustand-fetching
Advanced tools
Comparing version 2.0.12 to 2.1.0
@@ -8,4 +8,4 @@ export type LeitenModalState = { | ||
queue: string[]; | ||
readonly action: (key: string, value: boolean, queue?: boolean) => void; | ||
} | ||
export declare const useLeitenModalManager: import("zustand").UseBoundStore<import("zustand").StoreApi<LeitenModalManagerState>>; | ||
export declare const leitenModalManagerAction: (key: string, value: boolean, replace?: boolean) => void; |
import { produce } from "immer"; | ||
import { create } from "zustand"; | ||
export const useLeitenModalManager = create((set, get) => ({ | ||
export const useLeitenModalManager = create(() => ({ | ||
modals: {}, | ||
queue: [], | ||
action: (key, value, replace) => { | ||
const nextState = produce(get(), (draft) => { | ||
draft.modals[key] = { open: value, hidden: false }; | ||
let queue = draft.queue.filter((modal) => modal !== key); | ||
if (!replace) { | ||
queue.forEach((item) => { | ||
draft.modals[item].hidden = true; | ||
}); | ||
} | ||
else { | ||
queue.forEach((item) => { | ||
draft.modals[item].hidden = false; | ||
draft.modals[item].open = false; | ||
}); | ||
queue = []; | ||
} | ||
if (value) { | ||
queue.push(key); | ||
} | ||
const last = queue[queue.length - 1]; | ||
if (last) { | ||
draft.modals[last].open = true; | ||
draft.modals[last].hidden = false; | ||
} | ||
draft.queue = queue; | ||
}); | ||
set(nextState); | ||
}, | ||
})); | ||
export const leitenModalManagerAction = (key, value, replace) => { | ||
const nextState = produce(useLeitenModalManager.getState(), (draft) => { | ||
draft.modals[key] = { open: value, hidden: false }; | ||
let queue = draft.queue.filter((modal) => modal !== key); | ||
if (!replace) { | ||
queue.forEach((item) => { | ||
draft.modals[item].hidden = true; | ||
}); | ||
} | ||
else { | ||
queue.forEach((item) => { | ||
draft.modals[item].hidden = false; | ||
draft.modals[item].open = false; | ||
}); | ||
queue = []; | ||
} | ||
if (value) { | ||
queue.push(key); | ||
} | ||
const last = queue[queue.length - 1]; | ||
if (last) { | ||
draft.modals[last].open = true; | ||
draft.modals[last].hidden = false; | ||
} | ||
draft.queue = queue; | ||
}); | ||
useLeitenModalManager.setState(nextState); | ||
}; |
@@ -5,3 +5,3 @@ import { produce } from "immer"; | ||
import { shallow } from "zustand/shallow"; | ||
import { useLeitenModalManager } from "./hooks/useLeitenModals"; | ||
import { leitenModalManagerAction, useLeitenModalManager, } from "./hooks/useLeitenModals"; | ||
export const leitenModal = (store, path, extra) => { | ||
@@ -13,3 +13,2 @@ const initialData = get(store.getState(), path, "_empty"); | ||
const key = nanoid(10); | ||
useLeitenModalManager.getState().action(key, false); | ||
const setContent = (value) => { | ||
@@ -22,3 +21,3 @@ const nextState = produce(store.getState(), (draft) => { | ||
const setState = (value, replace) => { | ||
useLeitenModalManager.getState().action(key, value, replace); | ||
leitenModalManagerAction(key, value, replace); | ||
}; | ||
@@ -25,0 +24,0 @@ const getState = () => useLeitenModalManager.getState().modals[key]; |
{ | ||
"name": "zustand-fetching", | ||
"version": "2.0.12", | ||
"version": "2.1.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Zustand fetching helpers", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88922
1808