import { Component , OnInit , OnDestroy } from 'angular2/core' ; import { Observable } from 'rxjs/Observable' ; import { Subject } from 'rxjs/Subject' ; import { Subscription } from 'rxjs/Subscription' ; import { RouteParams } from '@ngrx/router' ; import { Store } from '@ngrx/store' ; import { IPerson } from '../../interfaces/IPerson' ; import { one , patch } from '../../services/people-actions.service' ; import { getOne$ } from '../../services/people-selectors.service' ; import { PersonFormComponent } from '../../components/person-form.component/person-form.component' ; @ Component ( { selector : 'people-edit-route' , directives : [ PersonFormComponent ] , template : require ( './people.edit.route.html' ) } ) export class PeopleEditRoute implements OnInit , OnDestroy { public person$ : Observable < IPerson > = this . _params . pluck ( 'id' ) . mergeMap ( id => this . _store . let ( getOne$ ( id ) ) ) ; public onPatch$ = new Subject < any > ( ) ; public queryIdSetAction$ = this . _params . pluck ( 'id' ) . map ( one ( ) ) ; public patchAction$ = this . onPatch$ . mergeMap ( id => this . _params . pluck ( 'id' ) , ( data , id ) => ( { id : id , data : data } ) ) . map ( patch ( ) ) ; private _subscription : Subscription ; constructor ( private _store , private _params ) { } ngOnInit ( ) { this . _subscription = Observable . merge ( this . queryIdSetAction$ , this . patchAction$ ) . subscribe ( this . _store ) ; } ngOnDestroy ( ) { this . _subscription . unsubscribe ( ) ; } }