LithoViewModelStore

Owns AndroidX ViewModel instances used by Litho components.

AndroidX normally exposes ViewModels through lifecycle owners whose stores are accessed from the main thread. Litho components can resolve concurrently on background threads, including multiple resolves that request the same ViewModel before either resolve completes. This store coordinates those requests so that a key creates exactly one instance and every caller observes that same instance.

The store also coordinates creation with scope teardown, supports retry after a failed factory, and delegates each retained instance to AndroidX ViewModelStore so closing this scope preserves the standard ViewModel.onCleared contract. The owner of this object defines its lifetime and is responsible for closing it when that scope ends.

This type is thread-safe. The request that installs a new entry runs the factory on its resolve thread; other resolve threads requesting that key wait for the result. Factories must be fast and non-blocking. A factory must receive its dependencies directly rather than request another ViewModel from a LithoViewModelStore.

Constructors

Link copied to clipboard

Functions

Link copied to clipboard

Requests closure of this scope once. New calculations cannot acquire a usage, while models used by existing calculations are cleared after the final usage ends. ViewModel access without an existing usage is rejected immediately.