π Mutable Observable
Available Since 0.0.39
Introduction
Observable#mutable returns a reactive container that allows both reading and updating its internal value. It implements the Observable<T> interface and provides a set(T) method to modify the current state.
Mutable observers are the foundation for building dynamic, reactive state in your application.
Any change to the state triggers notifications to dependent observers and re-computes them as needed.
Usage
You can use it directly, or combine it with mapping, watching, or composing multiple observables.
How it works
A MutableObservable keeps an internal value and a list of dependent observers. When set() is called: 1. The internal value is updated.
2. All observers are notified and may trigger their effects via Observer#flagAsDirty
If the new value is equal to the old one (by Object#equals), dependents will not be notified, thereby improving performance.
Advantages
π Mutable state: Ideal for reactive inputs, counters, toggles, and form fields.
π Notifies observers: Automatically propagates changes through the system.
π Composable: Works with mapping, compound logics and other observables.
β‘ Efficient: No re-computation or dirty state.