-
Notifications
You must be signed in to change notification settings - Fork 36
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
Dealing with one-time effects #12
Comments
I ran into a similar issue before with regards to I think the actual fix is using something like https://github.com/googlesamples/android-architecture/blob/dev-todo-mvvm-live/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/SingleLiveEvent.java#L38 - since the state won't be emitted automatically, if this is what you meant by |
So there would be a |
Jmmm, I was originally thinking of just using Thinking about it some more this probably wouldn't work, since we may have some loaded state that we always want rendered without an explicit action to load it.
The super simple solution would just have our Rx chains that we want to act as useCase.loadStuff()
.toObservable()
.map<Change> { Change.Load(it) }
.onErrorReturn { error -> Change.Error(error) }
// Intermediate state here
.flatMap { Observable.just<Change>(Change.Idle) }
.subscribeOn(Schedulers.io())
.startWith(Change.Loading) When |
I've just run into the same problem when trying to use the Navigation Component. I was thinking along the same lines as you by introducing another emitter using SingleLiveEvent. That way you have States which change the state of the UI and you have Events/Effects that trigger something like navigation, snackbars, dialogs, permission requests etc The question is how to split Changes into either States or Events, an example would be the user pressing a "locate me" button, the Action triggers a Change that updates the State to show a progress spinner, whilst the Event needs to trigger a permission request. It gets trickier when we need to do something based on the results of the Event, did they accept it or did they reject it etc |
@glurt Just FYI. Trying to relay navigation update as event/effect (SingleLiveEvent) fails in an edge case with lifecycle and fragment transactions. |
This seems like a good way to handle single events https://ryanharter.com/blog/handling-transient-events/ events can be dispatched from within bindActions() |
Checked it, the subscription until onDestroy still has the same problem while the app is backgrounded and the event notification (from PublishRelay) tries to perform a fragment transaction on a paused app. |
Here is a scenario:
Your screen supports rotation. A particular
Action
can generate an error which should display aSnackbar
.How do we deal with it? Emit the error
State
initially but not after rotation to avoid displaying theSnackbar
twice? What should theState
be after rotation then?Should we introduce a concept of
Effect
s (single event typeState
s)?In the spirit of Roxie's lightweight way of doing things, it would be ideal to solve this with minimal code needed by the consumer apps.
The text was updated successfully, but these errors were encountered: