Skip to main content
Version: 1.2.x

View Model Binder

The viewModelBinder module is used any time the framework needs to bind a view to an object. Usually this happens through using the composition module.

This module exports the following functions:

  • function bind(obj, view) - Databinds obj, which can be an arbitrary object, to view which is a dom sub-tree. If obj has a function called beforeBind, then it is called prior to binding. If obj has a function called afterBind, then it is called following binding. Both functions are passed the view.

  • function bindContext(bindingContext, view [, obj]) - Applies bindings to a view using a pre-existing bindingContext. This is used by the composition module when a view is supplied without a model. It allows the parent binding context to be preserved. If the optional obj parameter is supplied, a new binding context will be created that is a child of bindingContext with its model set to obj. This is used by the widget framework to provide the widget binding while allowing templated parts to access their surrounding scope.

Note: Both the above APIs add helpful logging and debugging support while the framework is in debug mode. If you wish the errors to be reported as such, rather than logged, set viewModelBinder.throwOnErrors = true;.

  • overridable function beforeBind(obj, view) - Called before every binding operation. Does nothing by default.

  • overridable function afterBind(obj, view) - Called after every binding operation. Does nothing by default.