airbnb / mavericks

Mavericks: Android on Autopilot
https://airbnb.io/mavericks/
Apache License 2.0
5.83k stars 500 forks source link

Wrong emit order (Loading after Success) #76

Closed chrisbanes closed 6 years ago

chrisbanes commented 6 years ago

I've noticed a bit of weirdness since moving to MvRx. After debugging it today, it turns out that the emitting order using execute() is wrong for Observables which emit immediately:

D  imageProviderObservable reducer: Success(value=app.tivi.tmdb.TmdbImageUrlProvider@696bcd)
D  imageProviderObservable reducer: com.airbnb.mvrx.Loading@7749791c

imageProviderObservable in this instance is a BehaviorSubject with a default value, so will always emit immediately on subscribe. If the Observable does not emit again, the final state is Loading which is obviously wrong.

chrisbanes commented 6 years ago

My current workaround is to add a small delay to the observable:

imageProviderObservable
        .delay(50, TimeUnit.MILLISECONDS, schedulers.io)
        .execute { copy(seasons = it) }
hellohuanlin commented 6 years ago

@chrisbanes Loading should be emitted before subscription to the observable happens.

https://github.com/airbnb/MvRx/blob/master/mvrx/src/main/kotlin/com/airbnb/mvrx/BaseMvRxViewModel.kt#L141-L152

Can you try to debug there?

chrisbanes commented 6 years ago

Yep I saw the code but haven't had a chance to step back into MvRx yet (I won't be able to until Monday now).

gpeal commented 6 years ago

This test also passes. If this could be reproduced with a failing test, that would be great.

chrisbanes commented 6 years ago

Closing this. I can't recreate in tests, and I think I've worked out a bug in my app which is causing this. Thanks!