What is New in Knockout.js 3.0 Lightning Round
I have been writing so much about Knockout.js lately that I thought it would be a disservice not to write about the release of its latest version, Knockout.js 3.0. I will write a lightning version, a fast and brief summary if you will, as better in-depth blog posts have already been written (see links below :) ). Without further ado, this is what is new in Knockout.js 3.0:
- Multiple bindings that affect the same element are evaluated independently, that is, changes in an observable no longer trigger updates in bindings that do not directly depend on it.
- Ordered bindings. The execution of some bindings is now done in a particular order to avoid WTF bugs. For instance, the binding
value: selectedValue, options: choices
would not work in Knockout 2.3, and debugging it would be a pain. This feature works for all built-in bindings and can be defined for custom bindings. - You can now add an arbitrary pre-processing function to built-in and custom bindings. This function will be given the unadultered binding value before it is evaluated.
- Likewise, you can now add a node pre-processing function to the binding provider that will be executed for each node within the document before it is processed for bindings. (This is used in knockout punches to add support for handlerbars syntax).
- Knockout now supports dynamic binding handlers. You can override the new
ko.getBindingHandler
function that determines which binding handler to use and add bindings on the fly. - New
checkedValue
binding that extends the functionality in thechecked
binding to support objects (the latter did only support the input’s value property, that is a primitive) - An experimental version of observable view models, that is, switch the entire view model and update each individual binding separatel.
- The
options
binding now generates achange
event, if changed (as when we remove the selected item), it will trigger updates in other bindings such as value or selectedOption. - New
arrayChange
event that makes it super easy to figure out has an observable array has changed. - Support for binding to detached nodes
- Support for arrays of observables in addition to observable arrays.
- The
optionsCaption
binding is now HTML encoded. - Is fully (very) backward compatible
In summary, new and awesome extensibility points, performance improvements and minor yet nice bug fixes and usability improvements.
Note that much better blog posts by most experienced people have been written about this new version, so, if you have some more time to spare, please check Steven Sanderson’s Knockout.js 3.0 RC and Knockout.js 3.0 Beta blog posts and Ryan P. Niemeyer’s blog for more in-depth information and a very good screencast.
Written by Jaime González García , dad, husband, software engineer, ux designer, amateur pixel artist, tinkerer and master of the arcane arts. You can also find him on Twitter jabbering about random stuff.