Giter VIP home page Giter VIP logo

Comments (4)

konmik avatar konmik commented on August 21, 2024

Hi,

No, there are some lifecycle considerations that prevent us from having presenters as singletons. Dagger reuses singletons for each view instance, so there are cases when the same view is instantiated twice, but only one presenter exists. This is causing bugs and lifecycle problems.

The solution that works in Nucleus is that each presenter should have its own unical id that is saved into view's bundle. This is (almost) impossible to do with Dagger.

But! You're still able to inject stuff into Presenter, take a look at: #32

from nucleus.

mheras avatar mheras commented on August 21, 2024

Yes, I saw the example with tests. But I would like to avoid using
PowerMock if possible. Do you have any idea? Thanks you!

On Tue, Aug 25, 2015 at 10:14 AM, Konstantin Mikheev <
[email protected]> wrote:

Hi,

No, there are some lifecycle considerations that prevent us from having
presenters as singletones. Dagger reuses singletons for each view instance,
so there are cases when the same view is instantiated twice, but only one
presenter exists. This is causing bugs and lifecycle problems.

The solution is that works in Nucleus is that each presenter should have
its own unical id that is saved into view's bundle. This is (almost)
impossible to do with Dagger.

But! You're still able to inject stuff into Presenter, take a look at: #32
#32


Reply to this email directly or view it on GitHub
#36 (comment).

Martín A. Heras
[email protected]

from nucleus.

konmik avatar konmik commented on August 21, 2024

You can just put a package-visible static PresenterFactory into a View class to instantiate presenters.

from nucleus.

vanceanderson41 avatar vanceanderson41 commented on August 21, 2024

@konmik I have a similar issue wherein:

I am converting an application to use this library and it currently has an instrumented (Espresso) test setup that relies on the espresso test having a reference to the same instance of a mocked presenter injected into views (accomplished with singleton constructor-injected presenters) I am looking to achieve the same capability with Nucleus but am a little hung up how I might accomplish this, as the Activity lifecycle seems abstracted away from the test execution (ActivityTestRule.getActivity() is null until a point after which its onCreate has already been called) and curious if you have any thoughts on how one might test Nucleus views isolated from presenter logic (in instrumentation)?

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.