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:
The
ko.applyBindings
method is called with the viewmodel.A binding context is constructed using the viewmodel.
The binding provider is retrieved from
ko.bindingProvider.instance
.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 firstThe binding handlers are iterated through, calling each handler's
init
andupdate
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...