Skip to content

store solution - exposing the subject value #1

@TheILPlace

Description

@TheILPlace

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions