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
AsyncAction uses a Zone to keep track of async operations like Future, timers and other kinds of micro-tasks. [...]
Atom
ChangeNotification<T>
Computed<T>
Derivation
Interceptable<T>
Interceptors<T>
Stores the intercept-handlers that have been attached to a specific Observable. [...]
ListChange<T>
Stores the change related information when a list-item is modified, added or removed
Listenable<TNotification>
Listeners<TNotification>
Stores the handler functions that have been attached via Observable.observe method This is an internal class and should not be used directly.
MapChange<K, V>
Stores the information related to changes happening in an ObservableMap. This is used when firing the change notifications to all the listeners
Observable<T>
ObservableFuture<T>
ObservableList<T>
The ObservableList tracks the various read-methods (eg: List.first, List.last) and write-methods (eg: List.add, List.insert) making it easier to use it inside reactions. [...]
ObservableMap<K, V>
The ObservableMap tracks the various read-methods (eg: Map.length, Map.isEmpty) and write-methods (eg: Map.[]=, Map.clear) making it easier to use it inside reactions. [...]
ObservableSet<T>
ObservbableSet provides a reactive set that notifies changes when a member is added or removed. [...]
ObservableStream<T>
ObservableValue<T>
Reaction
ReactionDisposer
A callable class that is used to dispose a reaction, autorun or when [...]
ReactiveConfig
Configuration used by ReactiveContext
ReactiveContext
SetChange<T>
Capture the change related information for an ObservableSet. This is used as the notification instance.
StoreConfig
Declares configuration of a Store class. Currently the only configuration used is boolean to indicate generation of toString method (true), or not (false)
WillChangeNotification<T>

Mixins

Store
The Store mixin is primarily meant for code-generation and used as part of the mobx_codegen package. [...]

Extensions

ObservableFutureExtension
Turn the Future into an ObservableFuture.
ObservableListExtension
Turn the List into an ObservableList.
ObservableMapExtension
Turn the Map into an ObservableMap.
ObservableSetExtension
Turn the Set into an ObservableSet.
ObservableStreamExtension
Turn the Stream into an ObservableStream.

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._()
version → const String
The current version as per pubspec.yaml
'1.0.1'

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 fn(Reaction), void effect(T), {String name, int delay, bool fireImmediately, EqualityComparator<T> equals, ReactiveContext context, void onError(Object, Reaction)}) ReactionDisposer
Executes the fn function and tracks the observables used in it. Returns a function to dispose the reaction. [...]
runInAction<T>(T fn(), {String name, ReactiveContext context}) → T
Executes the mutation function fn within an Action. This ensures that all change notifications are fired only at the end of the Action block. Note that actions can be nested, in which case the notifications go out when the outermost Action completes. [...]
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

FutureStatus
OperationType
ReactiveReadPolicy
Defines the behavior for observables read outside actions and reactions [...]
ReactiveWritePolicy
Defines the behavior for observables mutated outside actions [...]
StreamStatus

Typedefs

Dispose() → void
EqualityComparator<T>(T, T) → bool
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
This captures the stack trace when user-land code throws an exception
MobXCyclicReactionException
This exception would be fired when an reaction has a cycle and does not stabilize in ReactiveConfig.maxIterations iterations
MobXException
An Exception class to capture MobX specific exceptions