Observable<T> constructor

Observable<T>(
  1. T initialValue, {
  2. String? name,
  3. ReactiveContext? context,
  4. EqualityComparer<T>? equals,
})

Create an observable value with an initialValue and an optional name

Observable values are tracked inside MobX. When a reaction uses them they are implicitly added as a dependency of the reaction. When its value changes the linked reaction is re-triggered.

An Observable's value is read with the value property.

It is possible to override equality comparison of new values with equals.

var x = Observable(10);
var message = Observable('hello');

print('x = ${x.value}'); // read an Observable's value

Implementation

factory Observable(
  T initialValue, {
  String? name,
  ReactiveContext? context,
  EqualityComparer<T>? equals,
}) => Observable._(
  context ?? mainContext,
  initialValue,
  name: name,
  equals: equals,
);