ng-turkey/ngxs-reset-plugin

If we are using StateReset for states which dont have values set, we are getting error 'split' of null from ngxs-store.js

arun-s-aot opened this issue · 3 comments

Describe the bug
I need to clear all the store datas (even datas which are stored in storagePlugins) whenever a new version of our application is deployed. So i tried to use StateResetAll for clearing all the store datas. But as some of the stores were saved using storage plugin, i was not able to clear the datas fully. So i used StateReset(,) to it. I have total of 15 states to be cleared. There are chances where some states might not be having data when trying to update the app . In that case , i am getting an error as property 'split' of null from ngxs-store . The split value got in that function is coming as null at some places where my particular state is not assigned with any value . For other states with value, there is no issue.

Expected behavior
Even if i pass a State without values, it should be null checked and then only passed to ngxs-store so that the sequence of execution of state reset wont break .

Screenshots
image
image
image

Additional context
I tried calling each State Clear seperately instead of
this.store.dispatch(new StateReset(,))
as
this.store.dispatch(new StateReset())
this.store.dispatch(new StateReset())

Still same issue persists.

Can you please work on it as we need to take a production build with these changes as its a critical part in clearing the data and providing user a fresh experience . @armanozak @denizguzel

Hi,

Could you please share a minimum representation of the issue? A StackBlitz or CodeSandbox playground maybe?

Encountered the same problem. It happens anytime you try to trigger a reset and exclude a state that has not been loaded yet:
https://stackblitz.com/edit/ngxs-repro-1tu8fj?file=src%2Fapp%2Fapp.component.ts

In my case this happens because the relevant state resides inside a lazy loaded page which is not always loaded before the user triggers a logout.

Hi @mzernetsch,

Thanks for the feedback.

Well, that is expected behavior. Nevertheless, for a better DX, we could handle these cases. So, I've worked on it. There is an open PR. We will release a new version as soon as it is in.