Skip to content

Instantly share code, notes, and snippets.

@talamaska
Forked from vteivans/line.effect.ts
Created February 20, 2018 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talamaska/ead0c6fc345b6e4da1baf6f14cbe2969 to your computer and use it in GitHub Desktop.
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
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