-2

I'm using ractivejs,I know angularjs's two way binding based "dirty check",but I don't know the principle of ractivejs,who knows?I want a detailed answer.

user3387471
  • 113
  • 2
  • 5
  • 1
    This is a poorly asked question. I strongly recommend reading [how do I ask a good question?](http://stackoverflow.com/help/how-to-ask) before posting again. – John Conde Apr 07 '15 at 11:36

1 Answers1

2

Ractive doesn't diff or check anything, it uses the declarative template to know exactly what needs to be updated.

Ractive constructs a virtualDOM based on the template. The templated portions of the virtual dom (things with {{...}} in them) register with the viewmodel using the keypaths they contain.

When a ractive.set(...) or one of the other data manipulation methods occurs, dependents are notified of the change (computations and expressions, upstream and downstream keypaths, as well as observers are also notified).

Ractive uses a runloop that batches the actual DOM changes for any set operation to occur at the end of the cycle.

In addition to API calls, Ractive offers twoway binding by default. This maps needed DOM events from form input controls to the API calls to set the data to which it is bound (via the specified keypath).

Ractive does offer the .update(keypath) and .updateModel(keypath) methods which can be used to flush changes from model to view, or view to model when it is not possible for Ractive to know about them, for example using a third-party widget library.

martypdx
  • 3,702
  • 14
  • 22