diff --git a/libs/shared/ngrx-callstate-store/README.md b/libs/shared/ngrx-callstate-store/README.md index a6da01f..cc2ff02 100644 --- a/libs/shared/ngrx-callstate-store/README.md +++ b/libs/shared/ngrx-callstate-store/README.md @@ -71,6 +71,16 @@ export type CallState = LoadingState | ErrorState; ## API +### initialization + +##### setInitState + +The `setInitState` method lets you initialize your custom state if you are not using the constructor. + +```typescript +setInitState = (state: T): void +``` + ### updater ##### startLoading diff --git a/libs/shared/ngrx-callstate-store/package.json b/libs/shared/ngrx-callstate-store/package.json index 1d9a2e3..bc4bbb0 100644 --- a/libs/shared/ngrx-callstate-store/package.json +++ b/libs/shared/ngrx-callstate-store/package.json @@ -1,6 +1,6 @@ { "name": "@tomalaforge/ngrx-callstate-store", - "version": "0.0.3", + "version": "0.0.4", "description": "Enhance NgRx component-store by providing a loading/error state", "publishConfig": { "access": "public" diff --git a/libs/shared/ngrx-callstate-store/src/lib/call-state-component-store.ts b/libs/shared/ngrx-callstate-store/src/lib/call-state-component-store.ts index 08c2259..8061d91 100644 --- a/libs/shared/ngrx-callstate-store/src/lib/call-state-component-store.ts +++ b/libs/shared/ngrx-callstate-store/src/lib/call-state-component-store.ts @@ -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); return err; } + + setInitState(initialState: U) { + this.setState({ callState: 'INIT', ...initialState } as T); + } }