UNPKG

ageras-temporary-redux-segment

Version:

Segment.io analytics integration for redux.

48 lines (39 loc) 995 B
import {Component, View, Inject, OnDestroy, OnInit} from 'angular2/core'; import {bindActionCreators} from 'redux'; import {Counter} from '../components/counter/counter'; import * as CounterActions from '../actions/counter'; @Component({ selector: 'root' }) @View({ directives: [Counter], template: ` <counter [counter]="counter" [increment]="increment" [decrement]="decrement" [incrementIfOdd]="incrementIfOdd" [incrementAsync]="incrementAsync"> </counter> ` }) export default class App implements OnDestroy, OnInit { protected unsubscribe: Function; constructor( @Inject('ngRedux') private ngRedux) { } ngOnInit() { this.unsubscribe = this.ngRedux.connect( this.mapStateToThis, this.mapDispatchToThis)(this); } ngOnDestroy() { this.unsubscribe(); } mapStateToThis(state) { return { counter: state.counter }; } mapDispatchToThis(dispatch) { return bindActionCreators(CounterActions, dispatch); } }