Knockout.JS 2.1 is now available! Minified and debug versions available here. This release focused mainly on performance improvements and bug fixes after the 2.0 release.
Here are some highlights:
- CommonJS and AMD support
- Great performance improvements to templating - use cloned DOM nodes when possible rather than parsing strings into elements.
- Support for custom container-less bindings
- Ability to extend the binding context in a custom binding
- Computed observables no longer can recursively evaluate themselves (I think that has happened to all of us a few times!)
$index
is available inforeach
scenarios from the binding context. There is no longer a need for workarounds like storing an index as a property of your data items. Note that$index
is an observable, so it needs to be reference using$index()
in expressions.$parentContext
is available from the binding context as well. While,$parent
contains the actual data from one scope level up,$parentContext
contains the actual binding context ($data
,$parent
,$parents
,$root
, etc.) of the parent.ko.isComputed
is a helper function that was added to determine if a value is a computed observable or not.ko.toJSON
now passes its arguments on toJSON.stringify
after callingko.toJS
. This makes creating a handy “debug” section even easier<pre data-bind="text: ko.toJSON($root, null, 2)"></pre>
and this can be used to include only certain properties in the converted JSON likeko.toJSON(person, ['firstName', 'lastName'])
. This seems even more flexible in many cases than the approach that I mentioned here.- Better support for using a single instance of KO between documents - you can now pass an instance of KO between documents and have bindings work properly across the documents. Previously the computed observables associated with bindings would dispose themselves when outside of the original document as they believed they were no longer part of the DOM.
- Numerous other bug and performance fixes
For this release Michael Best joined the core team and drove the majority of the changes with Steve. Michael has numerous other exciting performance enhancements in his fork that will be evaluated for possible inclusion (in a non-breaking fashion) in the core. He has really helped tremendously in moving the project forward.
Please report any issues found here.