-
Here is my single store const useAppStore = create<FilterSlice&DesignerSlice&EventOperateSlice&LayerSlice&CombineSlice>()((...a) => ({
...createFilterSlice(...a),
...createDesignerSlice(...a),
...createEventOperateSlice(...a),
...createLayerSlice(...a),
})) To avoid duplicate names, I have to add many prefixes ,I hope I can construct the following code const useAppStore = create<FilterSlice&DesignerSlice&EventOperateSlice&LayerSlice&ContextMenuSlice>()((...a) => ({
...createFilterSlice(...a),
...createDesignerSlice(...a),
...createEventOperateSlice(...a),
...createLayerSlice(...a),
contextMenuSliceStore:createContextMenuSlice(...a)
})) slice.ts export interface ContextMenuSlice {
visible: boolean;
position: number[];
mouseDownTime: number;
mouseUpTime: number;
updateVisible: (visible: boolean) => void;
setPosition: (position: number[]) => void;
setMouseDownTime: (time: number) => void;
setMouseUpTime: (time: number) => void;
}
const createContextMenuSlice : StateCreator<
ContextMenuSlice,
[],
[],
ContextMenuSlice
> = (set, get) => ({
visible: false,
position: [0, 0],
mouseDownTime: 0,
mouseUpTime: 0,
updateVisible: (visible) =>{ set({ visible })},
setPosition: (position) => set({ position }),
setMouseDownTime: (time) => set({ mouseDownTime: time }),
setMouseUpTime: (time) => set({ mouseUpTime: time }),
});
export default createContextMenuSlice in function component const {} =useAppStore((state)=>state.contextMenuSliceStore) But I found out that I didn't seem to get the results I expected |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Jul 4, 2024
Replies: 1 comment
-
Check out zustand-lens. We are also working on zustand-slices, but it's probably different from your requirement. Or, maybe it's the same. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
zhangle1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out zustand-lens.
We are also working on zustand-slices, but it's probably different from your requirement. Or, maybe it's the same.