When using effects, should the action be dispatch in the component or store?

Viewed 130

I was pocking around the echoes-player code, There use of effects is very clean, They have an effect in player-dearch.effects that listens to PlayerSearchActions.SEARCH_MORE_FOR_QUERY, this effects in turns calls the searchMore in youtube.search service. The interesting part is that the action searchMoreForQuery is dispatched from the youtube-videos.component.

The question: Someone said that it would be better to move the dispatching function to the 'youtube.search' service then to call that from the youtube-videos.component. would that really be better design ? is there any suggestions to improve this ?

@Effect()
  searchMoreForQuery$ = this.actions$
    .ofType(PlayerSearchActions.SEARCH_MORE_FOR_QUERY)
    .map(toPayload)
    .withLatestFrom(this.store)
    .map((latest: any[]) => latest[1])
    .filter((store: EchoesState) => !store.search.isSearching)
    .mergeMap((store: EchoesState) =>
      this.youtubeSearch.searchMore(store.search.pageToken.next)
      .search(store.search.query, store.search.queryParams)
      .map(youtubeResponse => this.playerSearchActions.searchResultsReturned(youtubeResponse)));
0 Answers
Related