Closed ubaidazad closed 10 months ago
NGXS recommends avoiding class instances in your state because your state should be immutable and serializable/deserializable. Nevertheless, if you don't worry about serialization and still want to use a Map
, you must make sure your state changes are immutable. In other words, you should create a new Map
instance any time you want to update your state. I forked our pizza example to show you how it works.
If you check line 55 in the pizza.state.ts file, you'll see a new Map
instance is created with the current state and the state is updated with it. The order.handler.ts file proves this works with StateResetAll
.
Please let us know if your question is answered.
Condisering the issue is open for 5 months and no follow up, maybe we can close the issue?
I guess we can. Thanks for reminding @gokhanipek. 👍
StateResetAll
reset state to default values but Map objects are not reset Whenever you dispatchStateResetAll
it perfectly resets the state but what happens if default state field is Map it is not getting reset to new Map() and old value is returned to listeners leading to unintentional results.here settings in defaults is not reset to
new Map()
but settingsDict is set to{}