ng-turkey / ngxs-reset-plugin

Reset plugin for NGXS: Effortlessly clears, resets, or overwrites NGXS states respecting the state tree.
https://stackblitz.com/edit/ngxs-pizza
MIT License
108 stars 8 forks source link

A possibility to reset to default all states except some states #11

Closed beaussan closed 5 years ago

beaussan commented 5 years ago

Is your feature request related to a problem? Please describe.

When an user logout, I want to keep some state (for example preference of UI) and reset back to default all other states. And unless I dispatch a StateReset with all my states, I am not able to do that.

Describe the solution you'd like

I would like an action to dispatch in order to reset all state excepts some states.

Describe alternatives you've considered

Dispatch a StateReset with all active states, but I don't think it's the best solution.

armanozak commented 5 years ago

Hi @beaussart

First of all, thanks for all your support to this project. This was a very useful and challenging feature request for us.

It was a tricky action to create, because no public APIs were provided by NGXS store from which a list of all state classes or a tree of complete meta data could be taken. We had to add a handler and a basic service to get the initial state on app initialization and use it when the action is dispatched later on.

A PR has just been merged addressing the issue. All our tests have passed, so we are planning to release a minor version soon.

Enjoy, and thanks again for the idea!

Note: Lazy loaded states are not handled in this version. If you have any, you may need to use the action cautiously. This caveat is documented in the manual.

armanozak commented 5 years ago

v1.1.0 is released and published to npm.