Sam
12/11/2020, 10:45 PMclass TodoViewModel : ViewModel() {
var todoItems = mutableStateOf(listOf())
override fun onCleared { /* clean stuff up */ }
}
and then i remember it in my composable:
var todoItems by remember { TodoViewModel().todoItems }
why isn’t onCleared
called on the VM when navigation pops the composable back off the stack?Sam
12/11/2020, 11:11 PMvar model = remember { TodoViewModel() }
and then accessed the values via model.todoItems.value
but still didn’t see onCleared
fire on the VM. Is there any way to tap into remember { }
lifecycle when popping off nav? Otherwise I’m forced to create Id’s for every view model and manually cleanup via Composable { onDispose { /* cleanup */ } }
and it’s quite arduous.Ian Lake
12/12/2020, 1:38 AMval model: TodoViewModel = viewModel()
Sam
12/12/2020, 2:17 AMIan Lake
12/12/2020, 4:13 AMviewModel()
is the factory used to create the ViewModelSam
12/13/2020, 3:23 AMvar x by remember { mutableStateOf() }
without using View Model interop? My original example was simplified, but I’m actually trying to subscribe to state changes from our Redux-based store, and then unsubscribe when the composable is popped off navigation. Is the View Model approach bringing in unecessary overhead for legacy techniques when there might be something more direct?Ian Lake
12/13/2020, 3:53 PMonDispose
, not only when permanently destroyedIan Lake
12/13/2020, 6:24 PMcollectAsState()
, LaunchedEffect
)