Skip to content

Instantly share code, notes, and snippets.

@evgenyfedorenko
Last active November 11, 2019 21:32
Show Gist options
  • Save evgenyfedorenko/c6b0e3105bccd6dea7c5d0c5dea50170 to your computer and use it in GitHub Desktop.
Save evgenyfedorenko/c6b0e3105bccd6dea7c5d0c5dea50170 to your computer and use it in GitHub Desktop.
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import * as fromRoot from './reducers/';
import { Increment, Decrement, Reset } from './actions/counter.actions';
import { StoreService, select } from './store.service';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {
counter: Observable<number>;
constructor(
private storeService: StoreService
) { }
ngOnInit() {
this.counter = this.storeService.getState().pipe(select(fromRoot.getCount));
}
increment() {
this.storeService.dispatch(new Increment());
}
decrement() {
this.storeService.dispatch(new Decrement());
}
reset() {
this.storeService.dispatch(new Reset());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment