Giter Site home page Giter Site logo

Comments (4)

JakeWharton avatar JakeWharton commented on September 26, 2024

Can you provide a full sample that demonstrates the issue rather than just snippets?

From a quick glance, it looks like your recomposition is triggering an insert which is triggering a query update which is then triggering recomposition. If nothing was actually changing the StateFlow would not emit to Compose UI–so something is changing.

from sqldelight.

santiwanti avatar santiwanti commented on September 26, 2024

Here is the sample project https://github.com/santiwanti/SqlDelighTest.

A LaunchedEffect is used to insert a value, and then that value just blinks on screen for 15 seconds until the recompositions settle

from sqldelight.

JakeWharton avatar JakeWharton commented on September 26, 2024

On second look (but not yet trying the sample), the problem is that you're returning a new instance from both properties on every call. Remove the get() on both to create a single instance of each.

The current behavior is such because when recomposition occurs from the insert, viewModel.users is invoked again which produces a new StateFlow. That StateFlow emits an emptyList and then the real query value comes in which triggers recomposition. Then the process starts all over. Frankly, I'm not sure why it would ever stop.

This can also be fixed by wrapping viewModel.users in a remember { } to save StateFlow instance across recompositions, but there's really no reason the two properties should be creating instances on each call so I would change them instead.

from sqldelight.

santiwanti avatar santiwanti commented on September 26, 2024

You are absolutely right, changing the code to val users: StateFlow<List<User>> = ... and val users: Flow<List<User>> = ... fixed the issue. I had always used it as get() and thought it was the same because I never noticed a difference. Thanks for pointing this out. I will have to checkout the differences

from sqldelight.

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.