MobiusLoopViewModel

open class MobiusLoopViewModel<M, E, F, V> : ViewModel

A Mobius Loop lifecycle handler which is based on the Android ViewModel.

This view model has the concept of a View Effect (parameter V) which is a type of effect that requires the corresponding Android lifecycle owner to be in an active state i.e. between onResume and onPause. To allow the normal effect handler to send these, the view model will provide a Consumer of these View Effects to the Loop Factory Provider, which can then be passed into the normal Effect handler, so it can delegate view effects where necessary.

Since it's based on Android View model, this view model will keep the loop alive as long as the lifecycle owner it is associated with (via a factory to produce it) is not destroyed - meaning the Mobius loop will persist through rotations and brief app minimization to background.

While the loop is running but the view is paused, which is between onPause and onDestroy, the view model will keep the latest model/state sent by the loop and will keep a queue of View Effects that have been sent by the effect handler. The loop is automatically disposed when the lifecycle owner is destroyed. To avoid leaks, the maximum number of view effects that are kept when paused is capped - see create. Exceeding the limit leads to an IllegalStateException when posting further effects.

This class is public with a protected constructor in order to facilitate using it as a key in a androidx.lifecycle.ViewModelProvider. It's not intended to be subclassed in order to change its behaviour, and for that reason, all its methods are private or final.

Parameters

M

The Model with which the Mobius Loop will run

E

The Event type accepted by the loop

F

The Effect type handled by the loop

V

The View Effect which will be emitted by this view model

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val model: M
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
fun dispatchEvent(event: E)
Link copied to clipboard
Link copied to clipboard
override fun onCleared()