refactor(stalker): extend portal related store

This commit is contained in:
4gray committed 2023-08-14 08:49:20 +02:00
1 parent bb0e832b6b
commit adea3cf0d1
1 file changed
+12
+12
View File
@@ -3,6 +3,7 @@ import { ComponentStore } from '@ngrx/component-store';
export interface PortalState {
searchPhrase: string;
content: any[];
}
@Injectable({ providedIn: 'root' })
@@ -10,12 +11,16 @@ export class PortalStore extends ComponentStore<PortalState> {
constructor() {
super({
searchPhrase: '',
content: [],
});
}
// selectors
readonly searchPhrase = this.selectSignal((state) => state.searchPhrase);
readonly getContentById = (id: string) =>
this.selectSignal((state) => state.content.find((i) => i.id === id));
// reducers
readonly setSearchPhrase = this.updater(
(state, searchPhrase: string): PortalState => ({
@@ -23,4 +28,11 @@ export class PortalStore extends ComponentStore<PortalState> {
searchPhrase,
})
);
readonly setContent = this.updater(
(state, content: any[]): PortalState => ({
...state,
content,
})
);
}