Skip to content

Instantly share code, notes, and snippets.

@peterbsmyth
Last active November 12, 2019 22:52
Show Gist options
  • Save peterbsmyth/1349e74a91de7e36b0055319ae6b942c to your computer and use it in GitHub Desktop.
Save peterbsmyth/1349e74a91de7e36b0055319ae6b942c to your computer and use it in GitHub Desktop.
@Injectable()
export class Effects {
getPending$ = createEffect(() =>
this.actions$.pipe(
ofType(ApprovalActions.getAllPendingApprovals),
switchMap(res =>
this.apiService.getAllPendingApprovals()
),
map((approvals) => ApprovalActions.getAllPendingApprovalsComplete({ approvals }))
)
);
savePhoto$ = createEffect(() =>
this.actions$.pipe(
ofType(
NewExpenseActions.takePhotoComplete,
NewExpenseActions.selectPhotoLibraryComplete
),
tap(() => {
this.routerExtensions.navigateByUrl('/create-expense', { clearHistory: true }); // MOBILE ONLY
}),
switchMap(({ uri }) => this.apiService.saveOneExpenseReceipt(uri)), // MOBILE ONLY
map((token) => NewExpenseActions.savePhotoComplete({ token }))
)
);
constructor(
private actions$: Actions,
private apiService: ApiService
) { }
}
@Injectable()
export class Effects {
getPending$ = createEffect(() =>
this.actions$.pipe(
ofType(ApprovalActions.getAllPendingApprovals),
switchMap(res =>
this.apiService.getAllPendingApprovals()
),
map((approvals) => ApprovalActions.getAllPendingApprovalsComplete({ approvals }))
)
);
openModal$ = createEffect(() =>
this.actions$.pipe(
ofType(ModalActions.openModal),
tap(({ name }) => {
this.modalService.open(name); // WEB ONLY
})
), { dispatch: false }
);
constructor(
private actions$: Actions,
private apiService: ApiService,
private modalService: BaseModalService
) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment