Git Product home page Git Product logo

Comments (5)

bentrengrove avatar bentrengrove commented on April 27, 2024

Hey @KevinnZou, cool project! That does look like a backwards write. Instead of keying your launched effect with state.loadingState try use snapshotFlow instead, this will avoid the backwards write as you won't be observing the state in composition. This will also be more performant if it can avoid recomposing the whole WebView composable.

Something like:

LaunchedEffect(state) {
   snapshotFlow { state.loadingState }.collect {
      // do something
   }
}

from accompanist.

KevinnZou avatar KevinnZou commented on April 27, 2024

@bentrengrove Thank you for your response. It is greatly appreciated and very helpful.

from accompanist.

KevinnZou avatar KevinnZou commented on April 27, 2024

@bentrengrove I have a followup question regarding backwards write issue.

At here, we read the state.webview: val webView = state.webView
Then, we update it at here: state.webView = it

Is that also a case for backwards write?

from accompanist.

bentrengrove avatar bentrengrove commented on April 27, 2024

That one is ok because it happens in the factory method which only occurs once, so at most causes one more recomposition. Still not ideal if it can be avoided, you want your composables to settle in one recomposition if possible, not take multiple compositions to arrive at their final state. But one more isn't the biggest deal if it can't be avoided.

The backwards writes you have to watch out for are the infinite loops like the one in the example here. https://developer.android.com/jetpack/compose/performance/bestpractices#avoid-backwards

from accompanist.

KevinnZou avatar KevinnZou commented on April 27, 2024

@bentrengrove Got you! Thanks for your explanation!

from accompanist.

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.