datavis-tech / reactive-model

A library for reactive dataflow programming.
MIT License
61 stars 6 forks source link

Move fluff out of README #30

Closed curran closed 8 years ago

curran commented 8 years ago

The following content should be moved somewhere else, maybe to a Medium post.

Fluff

This library maintains an singleton instance of graph-data-structure internally, called the "data dependency graph", in which

Whenever reactive functions are added to the model, nodes and edges are added to this data structure. Whenever a property is changed, that property is marked as changed.

The digest algorithm performs a topological sort using the changed property nodes as sources. The resulting list of nodes is in the sorted order in which the reactive functions must be executed. After computing this ordering, each reactive function is executed, and its output value is assigned to its output property. Before executing each reactive function, a check is performed that ensures all of its input properties are defined.

The done callback for asynchronous reactive functions is inspired by the asynchronous tests in Mocha.

This is a re-design of model.js that addresses the following issues:

The core ideas of this redesign are:

The configuration-related functions (addPublicProperty, configuration) were informed by work on the Chiasm project. Chiasm manages synchronization of interactive visualizations with a dynamic application state configuration. In order to achieve predictable behavior, Chiasm introduces the notion of "public properties" and the requirement that they have default values. This is essential to achieve the goal of reversability for every action resulting from configuration changes (required to support undo/redo and history navigation, one of the goals of the Chiasm project).

Moving the publicProperty and serialization/deserialization semantics into the model abstraction seemed like a logical move. This will simplify the implementation of an engine like Chiasm, and will provide consistent serialization behavior for any users of reactive-model.

The digest function is exposed on the ReactiveModel constructor function rather than the ReactiveModel instance because there is a singleton data dependency graph shared by all reactive model instances. This approach was taken to enable reactive functions that take input from one model and yield output on another (via bind).

The term "digest" was chosen because it is already in common use within the AngularJS community and refers to almost exactly the same operation - see AngularJS $digest().

The motivation behind the organization of reactive function setup arguments is:

# bind(arr)

Establish bidirectional data binding between properties from different models.

The arr argument is expected to be an array of objects with the following properties:

Invoking bind() adds a cycle of pass-through reactive functions to the data dependency graph such that all specified properties will be synchronized, handling the fact that they are from different model instances.