mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-11 21:33:02 -05:00
feat(ngrx lib): add init function
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user