You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if the component mutates the value received via this property (for example via a developer mistake), we actually mutate our store !
this is because your store's data is kept in the behaviorSubject .
isnt it better to keep an additional separate private property that will hold our store data.
and in the
instead of using 'this.value' (which could have been mutated), we use that private property (and also update it during this process, to have the latest store data).
The text was updated successfully, but these errors were encountered:
Hey, yes you could do that - but we define the set/select API at the beginning and re-inforce it's mainly as a learning exercise. The only way we should update it is with .set() as shown :) With things like ngrx/store you needn't worry about things like this, but you could alternatively just not use the get value() {} should you wish to use it in a real project to conceal things a little further :)
in the store.ts
get value() {
return this.subject.value;
}
if the component mutates the value received via this property (for example via a developer mistake), we actually mutate our store !
this is because your store's data is kept in the behaviorSubject .
isnt it better to keep an additional separate private property that will hold our store data.
and in the
set(name: string, state: any) {
this.subject.next({
...this.value, [name]: state
});
}
instead of using 'this.value' (which could have been mutated), we use that private property (and also update it during this process, to have the latest store data).
The text was updated successfully, but these errors were encountered: