-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Given that we recommend normalizing state, it would be nice to have at least some amount of built-in tooling to help with that. This was also on Dan's wishlist of things to include in a Redux addon layer:
- Containing built-in helpers for indexing, normalization, collections, and optimistic updates.
I previously asked on Twitter about the idea of adding something like this:
https://twitter.com/acemarke/status/1216766299688316928
The NgRX platform has a library called @ngrx/entity
( https://ngrx.io/guide/entity ), which contains some type definitions and helpers for working with normalized state. Per discussion with an NgRX dev, that library is already almost completely framework-agnostic - it just has a couple NgRX/Angular-specific imports.
I just opened up ngrx/platform#2333 to ask if they might be able to tweak it and make it truly agnostic, in which case we might be able to depend on @ngrx/entity
ourselves.
Alternately, we could copy-paste the code with attribution.
There's also a bunch of other libraries for dealing with entity management, which I have listed at https://github.com/markerikson/redux-ecosystem-links/blob/master/entity-collection-management.md .
Key considerations:
- Don't want to go down the rabbit hole of making this incredibly complex
- Needs to be tree-shakeable, and I think we still aren't doing that yet ( Tree shaking is hindered by dependencies #78 )
- How does this overlap with "model actions as events, not setters"?
- I can picture having a wrapper around
createSlice
to generate entity actions and reducers or something, but we've already seen that can get tricky in TypeScript - Probably also some overlap with Create Async Action #76 as well for defining fetch logic