mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(ngrx lib): add init function
This commit is contained in:
@@ -71,6 +71,16 @@ export type CallState = LoadingState | ErrorState;
|
|||||||
|
|
||||||
## API
|
## 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
|
### updater
|
||||||
|
|
||||||
##### startLoading
|
##### startLoading
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tomalaforge/ngrx-callstate-store",
|
"name": "@tomalaforge/ngrx-callstate-store",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"description": "Enhance NgRx component-store by providing a loading/error state",
|
"description": "Enhance NgRx component-store by providing a loading/error state",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
/* eslint-disable @typescript-eslint/ban-types */
|
/* 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 { ComponentStore } from '@ngrx/component-store';
|
||||||
import { Observable, of, switchMap } from 'rxjs';
|
import { Observable, of, switchMap } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
@@ -28,7 +34,7 @@ export class CallStateComponentStore<
|
|||||||
private error = inject(ERROR_TOKEN);
|
private error = inject(ERROR_TOKEN);
|
||||||
private flickerTime = inject(FLICKER_TIME);
|
private flickerTime = inject(FLICKER_TIME);
|
||||||
|
|
||||||
constructor(@Inject(INITIAL_TOKEN) initialState: U) {
|
constructor(@Inject(INITIAL_TOKEN) @Optional() initialState: U) {
|
||||||
super({ callState: 'INIT', ...initialState } as T);
|
super({ callState: 'INIT', ...initialState } as T);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,4 +98,8 @@ export class CallStateComponentStore<
|
|||||||
} as Partial<T>);
|
} as Partial<T>);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInitState(initialState: U) {
|
||||||
|
this.setState({ callState: 'INIT', ...initialState } as T);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user