Comments (5)
Glad it's resolved. However, immer should be able to handle shallow copies as mentioned on this page:
case "adduser-3":
// OK: returning a new state. But, unnecessary complex and expensive
return {
userCount: draft.userCount + 1,
users: [...draft.users, action.payload]
}
Mixing both approaches is apparently the problem which can be hard to track down as mentioned for your case.
from ngrx-wieder.
Hi @julianpoemp, can you show more of your reducer code please and optimally create a reproduction?
Could this be a bug in ngrx-wieder?
Did you try removing ngrx-wieder and still receive the error?
Does it have something to do with the definition of anonymous functions by any chance?
Hm, at a glance, maybe. But I'd be wondering why this problem would only show up now. However, if that's the problem it should be pretty easy to reproduce :)
from ngrx-wieder.
Hi @nilsmehlhorn, thank you for your fast response! I was able to create a minimal working example that reproduces this issue. You can find it here: https://github.com/julianpoemp/ngrx-wieder-immer-bug The README contains further information. Thank you very much for looking into this!
from ngrx-wieder.
I've looked at your app and interestingly enough this line seems to be causing the error (not sure if it's the root cause though): https://github.com/julianpoemp/ngrx-wieder-immer-bug/blob/0556f4fa1e3cc93b462c55681e2a3c69fdfa966e/apps/immer-draft-bug/src/app/store/table.reducer.ts#L177
Changing the value of the type
property to a static string makes the error disappear for me. That's really odd as it is only some nested string value.
Overall your reducer isn't really in line with how you'd ideally use immer. You're performing immutable updates via shallow copy instead of mutating the draft - which is fine in theory but you need to be careful not to accidentally do both mutable and immutable updates (i.e. return a new object). However, I don't really see how that particular line would be doing that. Please see here for additional info: https://immerjs.github.io/immer/return
Would you mind trying to refactor at least the action reducer for TableActions.init.success
to use the mutable update patterns described here to see if that helps?
Eventually, you're also welcome to provide a pull request with a test case for the issue and a corresponding fix. I don't have loads of capacity for that right now.
from ngrx-wieder.
@nilsmehlhorn thank you very much for your response, that helps me a lot! I was able to fix this as you recommended. At the moment I don't really understand why immer can't handle simple shallow copies:
state.tools = tools;
state.projectRoles = projectRoles;
works. But this fails:
state = {
...state,
tools, projectRoles
}
So as far as I can understand it's not possible to use shallow copies as soon as I want to use immer. I'll have to read more about immer to understand it.
from ngrx-wieder.
Related Issues (20)
- Implementing with lazy-loaded feature modules HOT 2
- unable to import produceOn HOT 4
- AOT error from Angular 'ngrx-wieder' contains deep imports into
- installation of 4.0.2 failed HOT 1
- Feature request: actions for enable/disable undo & redo HOT 2
- Error with ngrx 11 HOT 1
- Error when trying to use canUndo canRedo buttons HOT 6
- Using createUndoRedoReducer with StoreModule.forFeature doesn't work HOT 9
- 6.0.2 version dependency on Angular 11 HOT 3
- Can't install version 3.1.x with angular 9.1.x and npm 7.x HOT 5
- History to contain only the changes made to the state HOT 2
- angular 13 support HOT 2
- History not filling HOT 4
- is there a version of this lib for Angular 14 HOT 9
- Angular 15 Support HOT 7
- Import default "produce" breaks jest tests HOT 6
- support for angular v16, @ngrx/store v16 HOT 5
- Ngrx V17 Support HOT 6
- CRUD operations support HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngrx-wieder.