-
-
Notifications
You must be signed in to change notification settings - Fork 207
Closed
Labels
{ } State@rx-angular/state related@rx-angular/state related
Description
Description
When I change the company object, it changes the store, also.
Which causes unexpected behavior in the state.
Why does the store not readonly? (using object freeze like ngrx)
vm$ = this.state.select(selectSlice(["company"])).pipe(
map(({ company }) => ({ company })),
tap(({ company }) => {
company.id = 2; // <-------------- I change the id here, and it change the store because it's ref object.
console.log({ company });
})
);
https://codesandbox.io/s/condescending-thompson-e51sh1?file=/src/app/app.component.ts:334-670
template: `
in app! vm = {{ vm$ | async | json }}<br />
state = {{ state$ | async | json }} <---- state changed.
`,
providers: [RxState]
})
export class AppComponent {
title = "CodeSandbox";
state$ = this.state.select();
vm$ = this.state.select(selectSlice(["company"])).pipe(
map(({ company }) => ({ company })),
tap(({ company }) => {
company.id = 2; // <-- should be readonly??
console.log({ company });
})
);
constructor(private state: RxState<{ company: { id: number } }>) {
this.state.set({ company: { id: 1 } });
}
Metadata
Metadata
Assignees
Labels
{ } State@rx-angular/state related@rx-angular/state related