@codeperate/app-asset
Version:
Codeperate App Asset
41 lines (40 loc) • 1.17 kB
JavaScript
import { createStore } from '@stencil/store';
let cdpModalStore;
export default cdpModalStore;
export let state;
export function init() {
cdpModalStore = createStore({
modals: [],
});
state = cdpModalStore.state;
}
export function clear(payload) {
for (const num of payload)
state.modals.splice(num, 1);
state.modals = [...state.modals];
}
export function pushModal(payload) {
state.modals = [...state.modals, payload];
}
export function popModal() {
state.modals = state.modals.filter((_, i) => i != state.modals.length - 1);
}
export function popAllModal() {
state.modals = [];
}
export function closeModal() {
if (state.modals[state.modals.length - 1])
state.modals[state.modals.length - 1].close = true;
state.modals = [...state.modals];
}
export function closeAllModal() {
for (const modal of state.modals)
modal.close = true;
state.modals = [...state.modals];
}
export function popModalByTag(payload) {
for (let i = 0; i < state.modals.length; i++)
if (Object.values(state.modals[i].content).includes(payload))
state.modals.splice(i, 1);
state.modals = [...state.modals];
}