// how to use const dialogStore = useDialogStore(); dialogStore.pushDialogStack(dialogName);
// xxx store export const useDialogStore = () => { const state = useAppSelector((state) => state.dialog); return { state, getState: () => { return store.getState().dialog; }, pushDialogStack: (dialogName: string) => { store.dispatch(pushDialogStack(dialogName)); }, popDialogStack: () => { store.dispatch(popDialogStack()); }, removeDialog: (dialogName: string) => { store.dispatch(removeDialog(dialogName)); }, topDialogStack: () => { return last(store.getState().dialog.dialogStack); }, }; };
// xxx reducer const dialogSlice = createSlice({ name: "dialog", initialState: { dialogStack: [], } as State, reducers: { removeDialog: (state, action: PayloadAction<string>) => { const filterDialogStack = state.dialogStack.filter((dialogName) => dialogName !== action.payload); return { ...state, dialogStack: filterDialogStack, }; },// end action },// end reducers }); export const { pushDialogStack, popDialogStack, removeDialog } = dialogSlice.actions; export default dialogSlice.reducer;
|