Last active
January 31, 2019 12:44
-
-
Save vteivans/da5adf19a94da9e32d27cb8b9d5b8884 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 'rxjs/add/operator/map'; | |
import 'rxjs/add/operator/filter'; | |
import 'rxjs/add/operator/withLatestFrom'; | |
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.length / 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