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

Case for onPopped/onDestroy #61

Open
bangarharshit opened this issue Dec 7, 2017 · 1 comment
Open

Case for onPopped/onDestroy #61

bangarharshit opened this issue Dec 7, 2017 · 1 comment
Assignees

Comments

@bangarharshit
Copy link

bangarharshit commented Dec 7, 2017

onShow and onHide are the only screen events. onHide is also called when a view comes in front. onPopped will be called when the screen is popped from the queue and can't be used in future.
This also means that if the developer store the fields in an instance variable and add it back to the queue it should throw an error.

Cases for it:

  1. Leak analysis.
  2. Allow for network requests which have the lifecycle of a screen.

onCreate/onPushed is not that important since we already have a constructor and with correct Rx multicasting, we can work around the limitations.

public class SomeScreen {
    private PublishSubject<NetworkResponse> responseSubject; // It can be non-reactive and just a state.
    private Observable<NetworkRequest> request;
    private Disposable hideDispoable;
    private Disposable poppedDisposable;

   void onPushed() {
      request.subscribe(responseSubject); //dispose it onPopped() - only 1 network call for a screen;
   }
   
   void onShow() {
      hideDisposable = responseSubject.subscribe(_ -> { // Do your stuff }) // dispose it in onHide().
   } 

   void onHide() {
      hideDisposable.clear();
    }

    void onPopped() {
        poppedDisposable.dispose();
        // Leak analysis unless a developer wants to cache or magellan should throw an error.
    }   
}
@fabiendevos
Copy link
Contributor

I think there is a case for onPushed() as well actually. Will definitely consider it. Any other idea for the names? Not completely sold on onPushed/onPopped, and onCreate/onDestroy would be confusing with the activity one.

@ryanmoelter ryanmoelter added this to the v2.0.0 milestone Oct 2, 2018
@ryanmoelter ryanmoelter modified the milestones: v2.0.0, v1.x, v1.2 Oct 25, 2018
@ryanmoelter ryanmoelter self-assigned this May 20, 2019
@ryanmoelter ryanmoelter removed this from the v1.2: Child support milestone Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants