Giter VIP home page Giter VIP logo

Comments (2)

inorichi avatar inorichi commented on August 21, 2024

In your subscription you should call a method of your view that updates the data. When you rotate the screen, the last result will be given again to the view, without repeating the query or network call or whatever. You don't have to do anything else.

You can use restartable*, a pseudocode example here: #42 (comment)

And a real example (with lambdas):

MyPresenter:

private static final int GET_MY_DATA = 1;

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    restartableLatestCache(GET_MY_DATA,
            () -> Observable.just(1)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread()),
            (view, data) -> {
                view.doSomething(data);
            }, (view, error) -> {
                view.doSomethingOnError(error);
            });

    start(GET_MY_DATA);
}

Or you can use the deilver* methods, for example:

MyPresenter:

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    Observable.just(1)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(deliverLatestCache())
            .subscribe(
                    split((view, data) -> {
                        view.doSomething(data);
                    }),
                    split((view, error) -> {
                        view.doSomethingOnError(error);
                    }));
}

I would use the restartable approach. It allows you to start the observable whenever you want, with the start(x) method, so that you can provide some parameters to the query first. Just make sure you are not restarting the observable when a configuration change occurs in order to take advantage of these deliver* methods.

If you use the second approach, don't forget to wrap the observable with the add() method, so that it unsubscribes when the presenter is destroyed.

from nucleus.

konmik avatar konmik commented on August 21, 2024

@devilmac , did @inorichi anwer your question? You can close the issue if so.

from nucleus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.