Replies: 1 comment 1 reply
-
@marbemac there isn't anything preventing you from using a Set or Map as the state of a store, though you'd have to stick to const store = injectStore(new Set())
store.setState(set => new Set(set)) // works
store.setStateDeep(set => new Set(set)) // bad Storing a set and updating it by cloning first is actually not bad since native JS Sets clone pretty fast. However, that does not apply to native JS Maps. Idk why, but they're terrible at cloning, making them awful for immutability. We use Immutable.js Maps stored in Zedux stores when we need a map. It works well, but Immutable has lots of footguns and I don't recommend it in general. TL;DR using a JS Set is fine. But if you can stick to an array, that still might be better, especially since signals are improving UX with those - the new |
Beta Was this translation helpful? Give feedback.
-
I'm rendering a virtualized grid, keeping track of the row/column indexes that are currently rendered on the screen as the user scrolls. A Set would be ideal for this for the o(1) removal and automatic de-duping - can Sets be used as a store? Guessing no since stores kind of rely on immutable updates. Not a huge deal if not, can fall back to good old arrays.
Beta Was this translation helpful? Give feedback.
All reactions