import { createReducer, on } from '@ngrx/store';
import { increment, decrement, reset } from '../actions/vorgang';
-export const initialState = 0;
+export interface State {
+ counter: number;
+}
+
+export const initialState: State = { counter: 0 };
const REDUCER = createReducer(initialState,
- on(increment, state => state + 1),
- on(decrement, state => state - 1),
- on(reset, state => 0),
+ on(increment, state => {
+ return { counter: state.counter + 1 };
+ }),
+ on(decrement, state => {
+ return { counter: state.counter - 1 };
+ }),
+ on(reset, state => {
+ return { counter: 0 };
+ }),
);
export function reducer(state, action) {
let fixture: ComponentFixture<VorgangComponent>;
let mockStore: MockStore;
- const initialState = { vorgang: 0 };
+ const initialState = { vorgang: { counter: 0 } };
beforeEach(async(() => {
TestBed.configureTestingModule({
import { Component, OnInit } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs';
+import { State } from '../reducers/vorgang';
import { increment, decrement, reset } from '../actions/vorgang';
+import { map } from 'rxjs/operators';
@Component({
selector: 'app-vorgang',
vorgang$: Observable<number>;
- constructor(private store: Store<{ vorgang: number }>) {
- this.vorgang$ = store.pipe(select('vorgang'));
+ constructor(private store: Store<{ vorgang: State }>) {
+ this.vorgang$ = store.pipe(select('vorgang'), map(vorgang => vorgang.counter));
}
ngOnInit(): void {