[Angular] Ngrx/effects, Action trigger another action

 

@Injectable()
export class LoadUserThreadsEffectService {

  constructor(private action$: Actions, private threadsService: ThreadsService) {
  }

  @Effect()
  userThreadsEffect$: Observable<Action> = this.action$
    .ofType(LOAD_USER_THREADS_ACTION)
    .switchMap((action) => this.threadsService.loadUserThreads(action.payload))
    .map((allUserData) => new LoadUserThreadsSuccess(allUserData));

  @Effect()
  userSelectedEffect$: Observable<Action> = this.action$
    .ofType(USER_SELECTED_ACTION)
    .map((action) => new LoadUserThreadsAction(action.payload))
}

 

For the first Effect, 

LOAD_USER_THREADS_ACTION

will trigger another action:

.map((allUserData) => new LoadUserThreadsSuccess(allUserData));

 

Second effect:

.ofType(USER_SELECTED_ACTION)

will trigger another action:

.map((action) => new LoadUserThreadsAction(action.payload))

 

posted @ 2017-01-26 15:21  Zhentiw  阅读(339)  评论(0)    收藏  举报