Hi all. Currently trying to setup and type a zustand store. My store has actions contained within a different Map to differentiate them on their main responsibility, I'll just show one of the Map instances:
export type ActionsObject = {
projectActions: Map<string, (...args: unknown[]) => void>
linesActions: Map<string, (...args: unknown[]) => void>
holesActions: Map<string, (...args: unknown[]) => void>
itemsActions: Map<string, (...args: unknown[]) => void>
areaActions: Map<string, (...args: unknown[]) => void>
viewer2DActions: Map<string, (...args: unknown[]) => void>
viewer3DActions: Map<string, (...args: unknown[]) => void>
verticesActions: Map<string, (...args: unknown[]) => void>
}
... just showing one key
verticesActions: new Map([
['beginDraggingVertex', (vertexID) => beginDraggingVertex(set, get, vertexID as string)],
['updateDraggingVertex', (x, y) => updateDraggingVertex(set, get, x as number, y as number)],
['endDraggingVertex', (x, y) => endDraggingVertex(set, get, x as number, y as number)],
]),
...
These Maps will grow and can have any type of variables passed within. So far, I typed the arguments as unknown to later cast them, but I'm sure there is a better way to do this with generics.