JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.33k stars 1.18k forks source link

[cfw] "No ViewModelStoreOwner was provided via LocalViewModelStoreOwner" #4694

Closed jershell closed 7 months ago

jershell commented 7 months ago

Unable to use the lifecycle-viewmodel-compose with web target

Describe the bug "No ViewModelStoreOwner was provided via LocalViewModelStoreOwner"

Affected platforms

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

  1. Go to web
  2. Open console
  3. See error

Expected behavior Label with current time on screen

Source code

kropp commented 7 months ago

Hi @jershell please update to the just released 1.6.0-beta02 and change the line viewModelFactory { FooBarViewModel() } to viewModelFactory { initializer { FooBarViewModel() } } That should fix the issue.

pablichjenkov commented 7 months ago

Is this initializer {} block, the API moving forward for all platforms? It really doesn't look appealing having these 2 inner blocks with an almost equal semantic name, ViewModelFactory and initializer.

jershell commented 7 months ago

Hi @jershell please update to the just released 1.6.0-beta02 and change the line viewModelFactory { FooBarViewModel() } to viewModelFactory { initializer { FooBarViewModel() } } That should fix the issue.

Hi. I up version. Viewmodel is working. Thanks you!

MatkovIvan commented 7 months ago

Is this initializer {} block, the API moving forward for all platforms?

It's the API from Android/Google, not new one. There is another overload with trailing lambda, so the usual syntax will be like:

viewModel { FooBarViewModel() }

As for "2 inner blocks": One factory might contain multiple initializers for different types. It's useful if you want to create a single factory for all your ViewModel types instead of separate ones for each viewModel call

pablichjenkov commented 7 months ago

Wow 😲 I never used it TBH. Thanks

okushnikov commented 4 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.