Skip to content

Instantly share code, notes, and snippets.

@peterbsmyth
Created June 1, 2019 23:32
Show Gist options
  • Save peterbsmyth/5582a5670b5be498a15dddaec4af8c98 to your computer and use it in GitHub Desktop.
Save peterbsmyth/5582a5670b5be498a15dddaec4af8c98 to your computer and use it in GitHub Desktop.
ngrx 8 createEffect
import { createAction, props } from '@ngrx/store';
export const get = createAction(
'[Job] get'
);
export const getComplete = createAction(
'[Job] getComplete',
props<{ job: any }>()
);
export const getError = createAction(
'[Job] getError',
props<{ error: any }>()
);
export const saveOneFavorite = createAction(
'[Job] saveOneFavorite',
props<{ job: any }>()
);
export const saveOneFavoriteComplete = createAction(
'[Job] saveOneFavoriteComplete',
props<{ job: any }>()
);
export const saveOneFavoriteError = createAction(
'[Job] saveOneFavoriteError',
props<{ error: any }>()
);
export const select = createAction(
'[Job] select',
props<{ id: any }>()
);
export const filter = createAction(
'[Job] filter',
props<{ filter: any }>()
);
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { mapTo } from 'rxjs/operators';
import { JobCodeActions } from '../actions';
@Injectable()
export class JobCodeEffects {
get$ = createEffect(() =>
this.actions$.pipe(
ofType(JobCodeActions.get),
mapTo(JobCodeActions.getComplete({
jobCode: {}
}))
)
);
saveOneFavorite$ = createEffect(() =>
this.actions$.pipe(
ofType(JobCodeActions.saveOneFavorite),
mapTo(JobCodeActions.saveOneFavoriteComplete({
jobCode: {}
}))
)
);
constructor(
private actions$: Actions
) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment