Closed cubissimo closed 5 years ago
Hey there -- Yep, you have total control of what's emitted from the Stream! In this case, you're only emitting one thing from this stream: A list of actions.
Instead, you need to emit two items! You have a few ways to do that, but the easiest for this case will be using the expand
operator. It's kinda like map, but allows you to emit multiple items: https://docs.flutter.io/flutter/dart-async/Stream/expand.html
The example becomes:
return Observable(actions)
.ofType(TypeToken<SearchAction>())
.debounce(Duration(milliseconds: 300))
.switchMap((SearchAction action) {
return _getResults(store, action)
.expand((result) => [OnSearchResult(result), SearchAnalyticAction(result)])
.takeUntil(actions.where((action) => action is CancelSearchAction));
Superb! Thanks @brianegan
Is there a pattern to dispatch multiple actions from an Epic?
is there a way to do that? Or is better to have 2 separeted epics listen same action (SearchAction)?
tks