Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong emit order (Loading after Success) #76

Closed
chrisbanes opened this issue Aug 31, 2018 · 5 comments
Closed

Wrong emit order (Loading after Success) #76

chrisbanes opened this issue Aug 31, 2018 · 5 comments

Comments

@chrisbanes
Copy link
Contributor

chrisbanes commented Aug 31, 2018

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
Copy link
Contributor Author

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

imageProviderObservable
        .delay(50, TimeUnit.MILLISECONDS, schedulers.io)
        .execute { copy(seasons = it) }

chrisbanes pushed a commit to chrisbanes/tivi that referenced this issue Aug 31, 2018
@hellohuanlin
Copy link
Contributor

@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
Copy link
Contributor Author

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
Copy link
Collaborator

gpeal commented Sep 1, 2018

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

@chrisbanes
Copy link
Contributor Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants