mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-12 05:43:03 -05:00
feat(ngrxcallstatelibray): update readme
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
export * from './lib/custom-component-store';
|
||||
export * from './lib/call-state-component-store';
|
||||
export * from './lib/external.model';
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
CallStateError,
|
||||
getErrorCallState,
|
||||
} from './call-state.model';
|
||||
import { ERROR_TOKEN } from './external.model';
|
||||
import { ERROR_TOKEN, FLICKER_TIME } from './external.model';
|
||||
import { nonFlickerLoader } from './non-flicker-loader';
|
||||
|
||||
export const INITIAL_TOKEN = new InjectionToken('initial data');
|
||||
@@ -26,6 +26,7 @@ export class CallStateComponentStore<
|
||||
: U & CallStateComponentState
|
||||
> extends ComponentStore<T> {
|
||||
private error = inject(ERROR_TOKEN);
|
||||
private flickerTime = inject(FLICKER_TIME);
|
||||
|
||||
constructor(@Inject(INITIAL_TOKEN) initialState: U) {
|
||||
super({ callState: 'INIT', ...initialState } as T);
|
||||
@@ -37,7 +38,9 @@ export class CallStateComponentStore<
|
||||
|
||||
readonly isLoadingWithFlicker$: Observable<boolean> = this.select(
|
||||
(state) => state.callState === 'LOADING'
|
||||
).pipe(switchMap((loading) => nonFlickerLoader(of(loading))));
|
||||
).pipe(
|
||||
switchMap((loading) => nonFlickerLoader(of(loading), this.flickerTime))
|
||||
);
|
||||
|
||||
readonly isLoaded$: Observable<boolean> = this.select(
|
||||
(state) => state.callState === 'LOADED'
|
||||
@@ -29,10 +29,6 @@ export class CallStateErrorHandler implements ErrorHandler<CallStateError> {
|
||||
};
|
||||
}
|
||||
|
||||
export interface EsuiteError {
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface ErrorState {
|
||||
error: CustomError;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
import { ClassProvider, InjectionToken, Type } from '@angular/core';
|
||||
import {
|
||||
ClassProvider,
|
||||
InjectionToken,
|
||||
Type,
|
||||
ValueProvider,
|
||||
} from '@angular/core';
|
||||
import { CallStateErrorHandler } from './call-state.model';
|
||||
|
||||
export interface ErrorHandler<T extends CustomError> {
|
||||
@@ -16,3 +21,12 @@ export const ERROR_TOKEN = new InjectionToken<ErrorHandler<any>>('error', {
|
||||
export const provideErrorHandler = <T extends ErrorHandler<any>>(
|
||||
errorHandlerClass: Type<T>
|
||||
): ClassProvider => ({ provide: ERROR_TOKEN, useClass: errorHandlerClass });
|
||||
|
||||
export const FLICKER_TIME = new InjectionToken<number>('flicker', {
|
||||
factory: () => 300,
|
||||
});
|
||||
|
||||
export const provideFlickerDelay = (delay: number): ValueProvider => ({
|
||||
provide: FLICKER_TIME,
|
||||
useValue: delay,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user