mobx library

MobX is a library for reactively managing the state of your applications.

Describe the state of your application as a graph of observable-values. Setup reactions that observe these observable values. When a dependent observable changes, the reactions are automatically triggered. The observables are treated as the implicit dependencies of the reaction. No explicit wiring is needed, besides just using it inside a reaction.

With these simple primitives, you can tackle a wide variety of state management use-cases in your Dart apps.

Consider the following example:

var x = Observable(10);
var y = Observable(20);

autorun((){
  print(x.value + y.value); // just referencing the observable values is enough to start tracking
}); // prints 30

// When x or y changes
x.value = 20; // prints 40
y.value = 30; // prints 50

Notice there is no explicit subscription to any observable values. By simply referencing the observables, the reaction picks up the dependencies. When they change, the reaction is automatically triggered.

Classes

Action
ActionController
ActionController is used to define the start/end boundaries of code which should be wrapped inside an action. This ensures all observable mutations are neatly encapsulated. [...]
ActionRunInfo
AsyncAction
Atom
ChangeNotification<T>
Computed<T>
Derivation
Interceptable<T>
Interceptors<T>
ListChange<T>
Listenable<TNotification>
Listeners<TNotification>
MapChange<K, V>
Observable<T>
ObservableFuture<T>
ObservableList<T>
Create a list of T. [...]
ObservableMap<K, V>
ObservableSet<T>
ObservableStream<T>
Reaction
ReactionDisposer
A callable class that is used to dispose a reaction, autorun or when [...]
ReactiveConfig
Configuration used by ReactiveContext
ReactiveContext
SetChange<T>
WillChangeNotification<T>

Mixins

Store

Constants

action → const MakeAction
Declares a method as an action. See the Action class for full documentation.
const MakeAction._()
computed → const ComputedMethod
Declares a method as a computed value. See the Computed class for full documentation.
const ComputedMethod._()
observable → const MakeObservable
Declares a class field as an observable. See the Observable class for full documentation
const MakeObservable._()

Properties

mainContext ReactiveContext
The main context of Mobx. All reactive operations and observations are happening inside this context. [...]
final

Functions

asyncWhen(bool predicate(Reaction), { String name, int timeout, ReactiveContext context }) → Future<void>
A variant of when() which returns a Future. The Future completes when the predicate() turns true. Note that there is no effect function here. Typically you would await on the Future and execute the effect after that. [...]
autorun(dynamic fn(Reaction), { String name, int delay, ReactiveContext context, void onError(Object, Reaction) }) ReactionDisposer
Executes the specified fn, whenever the dependent observables change. It returns a disposer that can be used to dispose the autorun. [...]
createContext({ReactiveConfig config }) ReactiveContext
Create a new context for running actions and reactions. [...]
reaction<T>(T predicate(Reaction), void effect(T), { String name, int delay, bool fireImmediately, ReactiveContext context, void onError(Object, Reaction) }) ReactionDisposer
Executes the predicate function and tracks the observables used in it. Returns a function to dispose the reaction. [...]
runInAction<T>(T fn(), { String name, ReactiveContext context }) → T
transaction<T>(T fn(), { ReactiveContext context }) → T
During a transaction, no derivations (Reaction or Computed) will be run and will be deferred until the end of the transaction (batch). Transactions can be nested, in which case, no derivation will be run until the top-most batch completes
untracked<T>(T fn(), { ReactiveContext context }) → T
Untracked ensures there is no tracking derivation while the given action runs. This is useful in cases where no observers should be linked to a running (tracking) derivation.
when(bool predicate(Reaction), void effect(), { String name, ReactiveContext context, int timeout, void onError(Object, Reaction) }) ReactionDisposer
A one-time reaction that auto-disposes when the predicate becomes true. It also executes the effect when the predicate turns true. [...]

Enums

EnforceActions
Defines the behavior for observables mutated outside actions [...]
FutureStatus
OperationType
StreamStatus

Typedefs

Dispose() → void
Interceptor<T>(WillChangeNotification<T>) WillChangeNotification<T>
ListChangeListener<TNotification>(ListChange<TNotification>) → void
Listener<TNotification>(TNotification) → void
MapChangeListener<K, V>(MapChange<K, V>) → void
ReactionErrorHandler(Object error, Reaction reaction) → void
SetChangeListener<T>(SetChange<T>) → void

Exceptions / Errors

MobXCaughtException
MobXException