Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //MyActions file:
  2. export const fooAction = createAction(
  3.   '[Foo] Foo Action',
  4.   props<{ foo: string }>()
  5. );
  6.  
  7. export const barAction = createAction(
  8.   '[Bar] Bar Action',
  9.   props<{ bar: string }>()
  10. );
  11. //end
  12.  
  13. //actions index file:
  14. import * as MyActions from '(path)/ngrx/my-actions';
  15. export {MyActions};
  16. // end  
  17.  
  18. //effects file:
  19. import { MyActions} from '(path to actions index file)
  20. ...
  21. export class MyEffects {
  22.  
  23.  constructor(public actions$: Actions) {}
  24.  
  25.  
  26.  test1$ = createEffect(() =>
  27.    this.actions$.pipe(
  28.      ofType(MyActions.fooAction),
  29.      switchMap(({ foo }) => EditActions.barAction)
  30.    )
  31.  );
  32.  
  33.  test2$ = createEffect(() =>
  34.    this.actions$.pipe(
  35.      ofType(MyActions.fooAction),
  36.      withLatestFrom(this.store.select(selectCompanyId)),
  37.      switchMap(
  38.        ([{ foo }, id]: [{ foo: string }, number]) => EditActions.barAction
  39.      )
  40.    )
  41.  );
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement