All files / lib diagnostics.reducer.ts

85.71% Statements 6/7
50% Branches 1/2
83.33% Functions 5/6
85.71% Lines 6/7

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                  2x   7x   3x         1x 1x               7x    
import { Injectable, Provider } from '@angular/core';
import { createReducer, on } from '@ngrx/store';
 
import { diagnosticsAction } from './diagnostics.actions';
import { diagnosticsReducerConfig } from './diagnostics.interface';
 
@Injectable({
  providedIn: 'root',
})
export class AppDiagnosticsReducer {
  public createReducer() {
    return createReducer(
      diagnosticsReducerConfig.initialState,
      on(diagnosticsAction.connected, (state, { payload }) => ({
        ...state,
        events: [...state.events, ...(payload.events ?? [])],
      })),
      on(diagnosticsAction.staticDataSuccess, (state, { payload }) => ({ ...state, staticData: payload })),
      on(diagnosticsAction.dynamicDataSuccess, (state, { payload }) => ({ ...state, dynamicData: payload })),
      on(diagnosticsAction.userDataSuccess, (state, { payload }) => ({ ...state, users: payload })),
    );
  }
}
 
export const diagnosticsReducerProvider: Provider = {
  provide: diagnosticsReducerConfig.token,
  deps: [AppDiagnosticsReducer],
  useFactory: (reducer: AppDiagnosticsReducer) => reducer.createReducer(),
};