-
-
Save talamaska/ead0c6fc345b6e4da1baf6f14cbe2969 to your computer and use it in GitHub Desktop.
Simple ngrx effect example with `withLatestFrom` operator for blog post: https://medium.com/@viestursv/how-to-get-store-state-in-ngrx-effect-fab9e9c8f087#.oekqp1ucb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Store, Action } from '@ngrx/store'; | |
import { Actions, Effect } from '@ngrx/effects'; | |
import { ADD_LINE } from './lines.reducer'; | |
import { INC_PAGE_COUNT } from './pages.reducer'; | |
import { AppState } from './app.store'; | |
@Injectable() | |
export class LineEffects { | |
@Effect() increasePageCount$ = this.actions$ | |
.ofType(ADD_LINE) | |
.withLatestFrom(this.store$) | |
.filter(([action: Action, storeState: AppState]) => { | |
return storeState.lines / 100 > storeState.pages.count; | |
}) | |
.map((actionAndStoreState) => { | |
return { | |
type: INC_PAGE_COUNT | |
} | |
}); | |
constructor ( | |
private actions$: Actions, | |
private store$: Store<AppState>) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment