Yarikx / reductor

Redux for Android. Predictable state container library for Java/Android
Apache License 2.0
463 stars 27 forks source link

Making Epic.run return an Observable<Action> #22

Closed amiakotin closed 7 years ago

amiakotin commented 7 years ago

This change makes the interface consistent with the intent of accepting a stream of Actions and returning another stream of Actions. The type of Observable<Object> was preventing me from performing other operations on the returned observable, such as .subscribeOn(Schedulers.io) and .observeOn(AndroidSchedulers.mainThread().

codecov-io commented 7 years ago

Codecov Report

Merging #22 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master     #22   +/-   ##
========================================
  Coverage      92.3%   92.3%           
  Complexity      199     199           
========================================
  Files            25      25           
  Lines           754     754           
  Branches         89      89           
========================================
  Hits            696     696           
  Misses           42      42           
  Partials         16      16

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 56ed0ad...076dbbb. Read the comment docs.

Yarikx commented 7 years ago

Hi @amiakotin,

Thanks for your effort for this contribution. But this interface was intentionally left as Observable<Object> to be consistent with Store and Dispatcher dispatch(Object action). That was done in Store to be able to pass arbitrary objects to be handled by Middlewares. The same applies for epics: epic can return the stream of "actions" which can be processed by a Middleware.

You can return Observable in epic without casting or unchecked assignment. Are there any cases where that creates any inconveniences for you in Epics API?

amiakotin commented 7 years ago

@Yarikx thanks for explanation. The reason I thought a change was needed was because I was struggling with chaining .observeOn(AndroidSchedulers.mainThread() to the observable that Epic.run returned. This wasn't compiling:

        Epic<AppState> epic = (actions, store) -> actions
                .filter(Epics.ofType(NotesActions.ADD_ASYNC))
                .delay(1, TimeUnit.SECONDS)
                .map(action -> Action.create(NotesActions.ADD_ACTION, action.values))
                .observeOn(AndroidSchedulers.mainThread());

However, using an intermediate var helped:

        Epic<AppState> epic = (actions, store) -> {
            Observable<Object> obs = actions
                    .filter(Epics.ofType(NotesActions.ADD_ASYNC))
                    .delay(1, TimeUnit.SECONDS)
                    .map(action -> Action.create(NotesActions.ADD_ACTION, action.values));

            return obs.observeOn(AndroidSchedulers.mainThread());
        };

I'm closing since no changes are needed.