koin icon indicating copy to clipboard operation
koin copied to clipboard

Support the key with viewModel

Open allen-hsu opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. Hi, because the ViewModel provider has the function (ViewModelProvider.get(key, clazz)) that can let you pass the key to ViewModel provide in order to get a different ViewModel with a different key, I want to raise this PR, and according to this : https://github.com/InsertKoinIO/koin/issues/213.

Describe the solution you'd like Add the key variable to every get ViewModel function. like this PR https://github.com/InsertKoinIO/koin/pull/1373

allen-hsu avatar Jun 30 '22 18:06 allen-hsu

Yes can be interesting. But from the Koin perspective, you can use a qualifier that do the same. Could it answer you case?

arnaudgiuliani avatar Aug 26 '22 13:08 arnaudgiuliani

@arnaudgiuliani I believe a qualifier would not be able to do the same once you could use multiple instances of the same ViewModel class for different views simultaneously, attaching them by a key.

This answer https://github.com/InsertKoinIO/koin/issues/782#issuecomment-671790468 used to work in previous versions, but probably the library's internal logic has changed since then.

Adding the possibility of setting a key to creating multiple instances from a single definition would help a lot in cases where you have multiple stateful components that share the same type o ViewModel in a list, like in a feed, for example.

htroliveira avatar Sep 28 '22 21:09 htroliveira

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 25 '23 21:02 stale[bot]

this has been fixed for API in 3.4

arnaudgiuliani avatar Mar 06 '23 08:03 arnaudgiuliani