Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 3x 33x 14x 14x 14x 14x 14x 14x 14x 14x 14x 9x 9x 9x 9x 9x 9x 9x 9x 9x 2x 33x | import { Injectable, Provider } from '@angular/core';
import { createReducer, on } from '@ngrx/store';
import { httpProgressAction } from './http-progress.actions';
import { httpProgressReducerConfig, IHttpProgressStateModel } from './http-progress.interface';
@Injectable({
providedIn: 'root',
})
export class AppHttpProgressReducer {
public createReducer() {
return createReducer(
httpProgressReducerConfig.initialState,
on(httpProgressAction.start, (state, { payload }) => {
const nextState = { mainView: { ...state.mainView }, sidebar: { ...state.sidebar }, toaster: { ...state.toaster } };
const keys = Object.keys(payload).length === 0 ? ['mainView'] : Object.keys(payload);
for (const key of keys) {
Eif (key in nextState) {
const k = key as keyof IHttpProgressStateModel;
Eif (k === 'mainView' || k === 'sidebar') {
nextState[k].counter = nextState[k].counter + 1;
nextState[k].loading = nextState[k].counter > 0;
}
}
}
return nextState;
}),
on(httpProgressAction.stop, (state, { payload }) => {
const nextState = { mainView: { ...state.mainView }, sidebar: { ...state.sidebar }, toaster: { ...state.toaster } };
const keys = Object.keys(payload).length === 0 ? ['mainView'] : Object.keys(payload);
for (const key of keys) {
Eif (key in nextState) {
const k = key as keyof IHttpProgressStateModel;
Eif (k === 'mainView' || k === 'sidebar') {
nextState[k].counter = nextState[k].counter - 1 >= 0 ? nextState[k].counter - 1 : 0;
nextState[k].loading = nextState[k].counter > 0;
}
}
}
return nextState;
}),
on(httpProgressAction.displayToast, (state, { payload }) => ({ ...state, toaster: { ...payload } })),
);
}
}
export const httpProgressReducerProvider: Provider = {
provide: httpProgressReducerConfig.token,
deps: [AppHttpProgressReducer],
useFactory: (reducer: AppHttpProgressReducer) => reducer.createReducer(),
};
|