Code Monkey home page Code Monkey logo

Comments (3)

raamcosta avatar raamcosta commented on July 23, 2024 1

Neither. It’s how Compose works in general. Not related with navigation official or this library.

The ViewModel is created as the corresponding screen becomes visible, so I would say you do have control over when it gets instantiated and you should also have control over when it happens on tests. This has never been an issue for me.
As a bonus, the UI shouldn’t be saying things like “load the list” to the VM. The VM is the one that decides what to do.
at most the UI can say “hey the UI is now visible” and then the VM makes the decision to load the list or not.

from compose-destinations.

raamcosta avatar raamcosta commented on July 23, 2024

Hi!

yes, this is expected. When you navigate forward, the back stack entry and the ViewModels are kept but the Composable leaves composition and re enters it when you navigate back. So the LaunchedEffect runs again.

for this use case, what I do usually is I load list on the constructor of the ViewModel. This is better in my opinion for multiple reasons.

from compose-destinations.

marosseleng avatar marosseleng commented on July 23, 2024

@raamcosta Thanks for the quick reply, sorry if it's a bad question, but is this feature of navigation or Compose Destinations?

The problem with loading something in constructor is that you have no control over it, eg in testing - your side effects are started by DI creating the instance, not you.

from compose-destinations.

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.