0

I am using flutter with redux and for handling stream data I'm using redux-epics.

Like this:

Stream<dynamic> getDataEpic(Stream<dynamic> actions, EpicStore<AppState> store) {
  return Observable(actions)
      .ofType(TypeToken<RequestDataAction>())
      .flatMap((RequestDataAction action) {
        return getDataStream()
          .map(
              (data) => UpdateStateWithData(data)
          );
      })
      .takeUntil(actions.where((action) => action is CancelGetDataAction));
}

// getDataStream() - is a stream that returns some stuff... 

In my screen in onInit I call store.dispatch(RequestDataAction()) and onDispose I call store.dispatch(CancelGetDataAction()) which destroys the Observable altogether, so the next time I go to this screen if I call store.dispatch(RequestDataAction()) my stream is not sending data, actually the entire Observable is dead!

How can I solve this problem? As far as I can see the problem is takeUntil because I completely closes the observable..

exilonX
  • 1,712
  • 3
  • 26
  • 50

1 Answers1

0

Try moving the takeUntil into the flatMap just after the getStreamData().map(). This will cancel the inner observable rather than the outer observable when the action is received.

exilonX
  • 1,712
  • 3
  • 26
  • 50