Skip to content

Instantly share code, notes, and snippets.

@peterbsmyth
Last active November 12, 2019 22:52
Show Gist options
  • Select an option

  • Save peterbsmyth/1349e74a91de7e36b0055319ae6b942c to your computer and use it in GitHub Desktop.

Select an option

Save peterbsmyth/1349e74a91de7e36b0055319ae6b942c to your computer and use it in GitHub Desktop.

Revisions

  1. Peter B Smith revised this gist Nov 12, 2019. 2 changed files with 31 additions and 14 deletions.
    31 changes: 31 additions & 0 deletions effects.tns.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    @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
    ) { }
    }
    14 changes: 0 additions & 14 deletions effects.ts
    Original file line number Diff line number Diff line change
    @@ -18,20 +18,6 @@ export class Effects {
    })
    ), { dispatch: false }
    );

    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,
  2. Peter B Smith created this gist Nov 11, 2019.
    41 changes: 41 additions & 0 deletions effects.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    @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 }
    );

    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,
    private modalService: BaseModalService
    ) { }
    }