feat(ngrx lib): add init function

This commit is contained in:
thomas laforge
2022-12-17 20:10:34 +01:00
parent df832c6850
commit d16ea1dcd0
3 changed files with 23 additions and 3 deletions

View File

@@ -1,5 +1,11 @@
/* eslint-disable @typescript-eslint/ban-types */
import { inject, Inject, Injectable, InjectionToken } from '@angular/core';
import {
inject,
Inject,
Injectable,
InjectionToken,
Optional,
} from '@angular/core';
import { ComponentStore } from '@ngrx/component-store';
import { Observable, of, switchMap } from 'rxjs';
import {
@@ -28,7 +34,7 @@ export class CallStateComponentStore<
private error = inject(ERROR_TOKEN);
private flickerTime = inject(FLICKER_TIME);
constructor(@Inject(INITIAL_TOKEN) initialState: U) {
constructor(@Inject(INITIAL_TOKEN) @Optional() initialState: U) {
super({ callState: 'INIT', ...initialState } as T);
}
@@ -92,4 +98,8 @@ export class CallStateComponentStore<
} as Partial<T>);
return err;
}
setInitState(initialState: U) {
this.setState({ callState: 'INIT', ...initialState } as T);
}
}