Skip to main content

Blueprint

This document outlines the core behaviors of MobX that need to be implemented for an effective reactive system.

Core Actors

Atom

Observable<T>

  • Can be observed and intercepted

Derivation

  • Depends on a set of observables to do its work.

Computed<T>

  • Is an observable which derives its value from a set of dependent observables
  • Compare values structurally or as scalars

Reaction

  • Reactions are scheduled with a sync-scheduler or debounced with a timer-based scheduler
  • They are derivations with no output value and only cause side-effects
  • Handle exceptions and report them back with global handlers
  • Can dispose
  • Checks for convergence with 100 iterations

Global Tracker

  • Used to push pending reactions
  • Determine the underlying dependencies when derivations are executed
  • Keeps track of current derivation
  • Keeps track of the nesting depth and use that to execute affected reactions
  • Works in a transactional manner for executing pending reactions

Action

  • Provides an atomic way to mutate observables
  • Fires notifications only upon the completion of the action
  • Handles any level of nesting and ensures notifications are fired only when the outermost action has completed

API

  • Convenience layer to provide programmer friendly interface to the Core Actors and behaviors

Cross cutting layers

  • Memoization of computation with DependencyState
  • Spying and Traceability
  • Exception handling and propagation

Implementation Details

  • Avoid dart:mirrors as it is not supported in Flutter