Book Image

Mastering KnockoutJS

By : Timothy Moran
Book Image

Mastering KnockoutJS

By: Timothy Moran

Overview of this book

Table of Contents (16 chapters)
Mastering KnockoutJS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Applying bindings


The binding application process takes place primarily in the bindingAttributeSyntax module, which defines the ko.bindingContext class as well as the ko.applyBindings method. The high-level overview looks like this:

  1. The ko.applyBindings method is called with the viewmodel.

  2. A binding context is constructed using the viewmodel.

  3. The binding provider is retrieved from ko.bindingProvider.instance.

  4. Knockout works with the DOM tree:

    • It is passed through the binding provider's node preprocessor (except the root node)

    • The binding handlers for the node are constructed using the binding provider

    • The binding handlers are sorted by ensuring that any bindings in their after property are loaded first

    • The binding handlers are iterated through, calling each handler's init and update function.

The first three steps are pretty straightforward; even the walking algorithm is just a simple recursion that applies bindings to a node and then iterates over its children to preprocess and bind them. The real...