GithubHelp home page GithubHelp logo

Comments (9)

Burtan avatar Burtan commented on September 28, 2024 1

I did some more tests, it only happens after also changing from @Parcable to @Serializable, I will make a reproducer.
Using 3.0.0-alpha05, it works again, although I had to add @Serializable to WebHistoryController, in case that matters.
3.0.0-alpha01 also works.
Thanks for the fast response!

from decompose.

arkivanov avatar arkivanov commented on September 28, 2024

There should be no behaviour change, though there could a bug that was fixed. Could you please provide more information? In particular, what you mean by "the main instance keeper seems to be inherited to child components"?

Also a reproducer (a project, a test, etc) would be very helpful.

from decompose.

arkivanov avatar arkivanov commented on September 28, 2024

Looking at the changes between 2.1.4 and 2.2.2, I don't see anything that could affect the behaviour.

from decompose.

arkivanov avatar arkivanov commented on September 28, 2024

Glad it works on the latest versions. Though, it would be still nice to double check what's the issue.

from decompose.

Burtan avatar Burtan commented on September 28, 2024

I found the reason for the problem.
Have a look at this sample project, branch decompose-2.2.2.
It has a root component with 3 child components. One child component's config has a value "token". When this config is not a data class, this config is always treated as new on recreation regardless of its value and therefore a new InstanceKeeper is created. If it is a data class, the config is compared correctly with the old config, e.g. the same value means the config is not new and therefore the old InstanceKeeper is kept alive. I think the comparison of configs with non data classes in decompose 2.2.2 does not work correctly, but works again with 3.0.0+.

The associated test is here:

I hope this helps :-)

from decompose.

arkivanov avatar arkivanov commented on September 28, 2024

Thank you very much for the detailed explanation! Now it's al clear. This behaviour is by design, and it was like this from the very beginning. I'm surprised that it worked in some versions. This is documented - configurations must "Correctly implement equals() and hashCode() methods".

from decompose.

Burtan avatar Burtan commented on September 28, 2024

I just checked my stable branch and this is actually working. It makes sense that equals() and hashCode() should be implemented, but I wonder if comparing the serialized data is an option.

    sealed interface Config : Parcelable {
        @Parcelize class Case(val token: String) : Config
        @Parcelize data object Scanner : Config
        @Parcelize data object History : Config
        @Parcelize data object About : Config
    }

from decompose.

arkivanov avatar arkivanov commented on September 28, 2024

Yes, both kotlin-parcelize and kotlinx-serialization handle object classes just fine - there is always just one instance, and so it's always equal. The new data object also generates equals and hashCode functions, just like data class. So it also works with JVM Serialization, though not used by Decompose. Anyway, data object is the safest and preferable way.

from decompose.

arkivanov avatar arkivanov commented on September 28, 2024

Closing this for now. Feel free to reopen if there are any issues or questions.

from decompose.

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.