I am working with a program that contains 1000s of user objects, and HashMaps are a must to keep performance in check. For example, the user needs to be able to click on an on-screen object and enter editing mode for that object in O(1) time.
Here is an example partial implementation I found created with Zustand:
If a function was made for the store that can manipulate a hashmap within it, how can I signal to Zustand that the hashmap has changed and needs a re-render with all components that depend on it?
Re-creating the Hashmap completely, or putting it within an array, is not an option.
Is this possible with redux without creating a new Hashmap? I also want to subscribe some UI components exclusively to that hashmap.
(Record is a TypeScript utility type that is comparable to {[key: string]: Object} in this case)
With this you can follow along with the docs on updating managing your hash-map, while keeping the performance gains. The one area where you lose out in Map vs {} is you aren’t guaranteed the order of the keys in the map, but that shouldn’t be an issue if you save the order in another piece of state (usually an array of ids)