appyx icon indicating copy to clipboard operation
appyx copied to clipboard

Investigate ViewModel support + RetainedInstanceStore

Open KovalevAndrey opened this issue 1 year ago • 6 comments

Check if it makes sense to implement ViewModel support on top of RetainedInstanceStore. Similarly to this, one of the possible solutions:

  1. Node implements ViewModelStoreOwner interface
  2. RetainedInstanceStore stores and clears ViewModelStore for every Node

KovalevAndrey avatar Feb 21 '23 08:02 KovalevAndrey

This will be really nice. I'm trying out appyx again today and I'm trying to figure out how to retain my presenter across config changes but only at a per node level.

saket avatar Jun 11 '23 22:06 saket

Hi @saket you can already retain your presenter per Node level. Please check com.bumble.appyx.sandbox.client.mvicoreexample.MviCoreExampleBuilder where we retain feature. To make it work per node level you simply need to provide the id of the node like this:

val feature = buildContext.getRetainedDisposable(buildContext.identifier) {
        MviCoreExampleFeature(payload)
 }

For non-rx classes check com.bumble.appyx.core.store.getRetainedInstance

KovalevAndrey avatar Jun 12 '23 08:06 KovalevAndrey

Oh whoops I completely missed that. Apologies!

saket avatar Jun 12 '23 20:06 saket

Any updates on how do we use viewModels with this?

tausifcreates avatar Jul 29 '23 08:07 tausifcreates

Hi @LittleTasteOfHeaven, the ViewModel support is not integrated into the library yet, however, we have support for retaining objects. Similar functionality can be achieved using the RetainedInstance API. Please check docs here

KovalevAndrey avatar Jul 29 '23 10:07 KovalevAndrey

Thank you @KovalevAndrey ! Any eta when viewmodel support will land on appyx?

tausifcreates avatar Jul 29 '23 15:07 tausifcreates