Skip to content

Instantly share code, notes, and snippets.

@fxck
Created April 21, 2016 19:22
Show Gist options
  • Save fxck/a8f759287b3627e50ca6e6d89052ac89 to your computer and use it in GitHub Desktop.
Save fxck/a8f759287b3627e50ca6e6d89052ac89 to your computer and use it in GitHub Desktop.
import {
Component,
OnInit,
OnDestroy
} from 'angular2/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { Subscription } from 'rxjs/Subscription';
import { Store } from '@ngrx/store';
// action creators
import { login } from '../../services/auth-actions.service';
// components
import {
LoginFormComponent
} from '../../components/login-form.component/login-form.component';
@Component({
selector: 'auth-route',
directives: [ LoginFormComponent ],
template: require('./auth.route.html')
})
export class AuthRoute implements OnInit, OnDestroy {
// dom event streams
public onLogin$ = new Subject<any>();
// actions
public loginAction$ = this.onLogin$.map(login());
// subscription helpers
private _subscription: Subscription;
constructor(private _store: Store<any>) {}
ngOnInit() {
this._subscription = Observable
.merge(this.loginAction$)
.subscribe(this._store);
}
ngOnDestroy() {
this._subscription.unsubscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment