From 673c7c039990a33e39d9d5f4503d2236bbd61315 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 5 Jul 2020 13:51:04 +0200 Subject: [PATCH] WIP: Extract interaction with store into service --- src/app/vorgang.service.ts | 13 +++++++++++++ src/app/vorgang/vorgang.component.ts | 13 ++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/app/vorgang.service.ts b/src/app/vorgang.service.ts index b68958b..6d5cca4 100644 --- a/src/app/vorgang.service.ts +++ b/src/app/vorgang.service.ts @@ -4,6 +4,7 @@ import { Observable, of, EMPTY } from 'rxjs'; import { catchError, map, tap } from 'rxjs/operators'; import { select, Store } from '@ngrx/store'; import { Vorgang } from './vorgang'; +import { increment, decrement, reset } from './actions/vorgang'; import { State } from './reducers/vorgang'; @@ -41,6 +42,18 @@ export class VorgangService { return this.gpsUrl + vbId + '/save'; } + increment() { + this.store.dispatch(increment()); + } + + decrement() { + this.store.dispatch(decrement()); + } + + reset() { + this.store.dispatch(reset()); + } + Observable observe() { return this.store.pipe(select('vorgang'), map(vorgang => vorgang.counter)); } diff --git a/src/app/vorgang/vorgang.component.ts b/src/app/vorgang/vorgang.component.ts index 587ebd4..e69251d 100644 --- a/src/app/vorgang/vorgang.component.ts +++ b/src/app/vorgang/vorgang.component.ts @@ -1,9 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; -import { Store } from '@ngrx/store'; -import { increment, decrement, reset } from '../actions/vorgang'; import { VorgangService } from '../vorgang.service'; -import { State } from '../reducers'; @Component({ selector: 'app-vorgang', @@ -14,9 +11,7 @@ export class VorgangComponent implements OnInit { vorgang$: Observable; - constructor( - private store: Store<{ vorgang: State }>, - private service: VorgangService) { + constructor(private service: VorgangService) { this.vorgang$ = service.observe(); } @@ -24,14 +19,14 @@ export class VorgangComponent implements OnInit { } increment() { - this.store.dispatch(increment()); + this.service.increment(); } decrement() { - this.store.dispatch(decrement()); + this.service.decrement(); } reset() { - this.store.dispatch(reset()); + this.service.reset(); } } -- 2.20.1