The Classic @Effect Model
@Effect() updates$ = this.actions$ .ofType('START_TIMER') .switchMap( () => Observable.timer(2000) .switchMap(() => Observable.of({ type: "TIMER_DONE" })) );
A Use Case For Not Returning An Action
firebase.auth().onAuthStateChanged( (user) => { if (user) { this.store.dispatch(type: "ANONYMOUS_AUTH_SUCCESS", payload: {uid: user.uid, isAnonymous:user.isAnonymous})); } else { this.store.dispatch({type:"BEGIN_ANONYMOUS_AUTH"}); } })
@Effect() anonymousAuthr$ = this.actions$ .ofType('BEGIN_ANONYMOUS_AUTH') .switchMap(() => { return Observable.fromPromise(<Promise<any>>firebase.auth().signInAnonymously()) .switchMap((result) => { return Observable.of({ type: "ANONYMOUS_AUTH_SUCCESS", payload: {uid: result.uid, isAnonymous: result.isAnonymous} }) }) });
Returning an Unused Action
@Effect() anonymousAuth$ = this.actions$ .ofType('BEGIN_ANONYMOUS_AUTH') .switchMap( () => { return Observable.fromPromise(<Promise<any>>firebase.auth().signInAnonymously()) .switchMap( (user) => { return Observable.of({type:"NO_ACTION"}); }) })
Using "{dispatch: false}"
@Effect({dispatch: false}) anonymousAuth$ = this.actions$ .ofType('BEGIN_ANONYMOUS_AUTH') .switchMap( () => { console.log('yep, doing the anonymous auth') return Observable.fromPromise(<Promise<any>>firebase.auth().signInAnonymously()) .switchMap( (result) => { // Any of these will work return Observable.of({}) return (<ObservableInput<any>>{}); return null; }); })