feat(ngrxcallstatelibray): update readme

This commit is contained in:
thomas
2022-12-14 14:37:54 +01:00
parent c6e0d55b93
commit 0979a9f3db
6 changed files with 257 additions and 13 deletions

View File

@@ -1,2 +1,2 @@
export * from './lib/custom-component-store';
export * from './lib/call-state-component-store';
export * from './lib/external.model';

View File

@@ -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'

View File

@@ -29,10 +29,6 @@ export class CallStateErrorHandler implements ErrorHandler<CallStateError> {
};
}
export interface EsuiteError {
code: string;
}
export interface ErrorState {
error: CustomError;
}

View File

@@ -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,
});