store
store copied to clipboard
🐞[BUG]: setState returns global state instead of subState
I have 2 states:
@State<Config>({ name: "config", defaults: { browser: SupportedBrowsers.Chrome, defaultPassword: '' } })
and
@State<OrgsStateModel>({ name: 'orgs', defaults: { version: 2, orgs: [] } })
When I trigger an action on the second state: ` @Action(OrgDelete) public org_delete(ctx: StateContext<OrgsStateModel>, { name }: OrgDelete): void {
const state = ctx.setState(patch<OrgsStateModel>({
orgs: removeItem<org_model>((org) => org.name === name)
}));
this.db.save(state);
} `
I would expect the value of state
to be of type OrgStateModel
. Instead it englobes both states.
See this related issue: https://github.com/ngxs/store/issues/491
This is a bug, but would be a breaking change for existing apps. So, in v4 we will be removing this return value. See this comment for the reasoning: https://github.com/ngxs/store/issues/491#issuecomment-404291415
I don't recommend using this return value, but to rely on getState() instead.
Stumbled upon this issue today. Is there any timeline already to when v4 will be released?
Closing since this is related to v4 which is already mentioned in the main issue.