Using entity adapters inside reducers in 1.5.0
See original GitHub issueHi, would be thankful for a little help here. From the changelog of 1.5.0 I understood that we who use our entity adapters inside reducers are covered by:
We’ve also updated createEntityAdapter’s getSelectors API to use these draft-safe selectors.
So lets define an adapter:
const tabsAdapter = createEntityAdapter<Tab>();
export const tabsSelectors = tabsAdapter.getSelectors<State>((state) => state.tabs);
export const { selectById: selectTabById } = tabsSelectors;
Then use it in some reducer:
setSomething(state, action: PayloadAction<{ tabId: string; foo: string }>) {
const { tabId, foo } = action.payload;
const tab = selectTabById(state, tabId);
if (tab) {
tab.foo = foo;
}
},
Works in 1.4.0, but fails in 1.5.0 during runtime with:
TypeError: Cannot assign to read only property 'foo' of object '#<Object>'
or this one if the property was not yet set
TypeError: Cannot add property foo, object is not extensible
Could someone please explain what is the migration path here from 1.4.0 -> 1.5.0?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
createEntityAdapter - Redux Toolkit
A function that generates a set of prebuilt reducers and selectors for performing CRUD operations on a normalized state structure containing ...
Read more >22. Use Entity Adapter - Angular and NgRx - GitBook
1. Reduces boilerplate for creating reducers that manage a collection of models. · 2. Provides performant CRUD operations for managing entity collections. ·...
Read more >More advanced access patterns for createEntityAdapter ? #799
I'm using createEntityAdapter to keep my data normalised and it's working very nicely, however, my use-case means not only do I need to...
Read more >Angular NgRx Entity - Complete Practical Guide
In order to be able to use the other features of NgRx Entity, we need to first create an entity adapter. The adapter...
Read more >reduxjs/toolkit - NPM Package Overview - Socket.dev
createEntityAdapter () : generates a set of reusable reducers and selectors to manage normalized data in the store; The createSelector() utility ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@markerikson Correct, not calling
getSelectors()
everytime, that was just an example, in reality we are using stored and correctly typed selector variants (because our entity adapter has an union type). Thanks for the reply, will get rid of the these selectors inside reducers and hopefully finally fully migrate to 1.5.0. 😄@phryneas I see, so I handled updates the unsafe way from the very beginning. 😇 Thanks a lot for the clarification and super fast response! The
update*/upsert*
methods are what I needed!