store icon indicating copy to clipboard operation
store copied to clipboard

🐞[BUG]: setState returns global state instead of subState

Open davideappiano opened this issue 3 years ago • 2 comments

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.

davideappiano avatar Jan 19 '22 19:01 davideappiano

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.

markwhitfeld avatar Jan 28 '22 11:01 markwhitfeld

Stumbled upon this issue today. Is there any timeline already to when v4 will be released?

vander2675 avatar Mar 10 '22 11:03 vander2675

Closing since this is related to v4 which is already mentioned in the main issue.

arturovt avatar Nov 05 '22 21:11 arturovt