Knockout 2.2.0 released

1,851 views
Skip to first unread message

Steve Sanderson

unread,
Oct 29, 2012, 7:12:31 AM10/29/12
to knock...@googlegroups.com
Yay, it's released! The 2.2.0 Release Candidate build proved pretty solid (thanks to everyone who tried it), the docs are all updated, the specs are 100% passing on all supported browsers, and so this new release is final as of today.

I've posted more information on my blog at http://blog.stevensanderson.com/2012/10/29/knockout-2-2-0-released/. Michael Best also wrote the following summary of what's new and improved:

Bindings enhancements 
  • The css binding accepts multiple classes in a string and dynamic class names. 
  • The text binding can be used in virtual elements: <!--ko text: myValue--><!--/ko--> 
  • For the options binding, it will skip destroyed items (unless optionsIncludeDestroyed is passed as truthy), optionsValue can accept a function just like optionsText, and optionsCaption can be an observable. 
  • The with binding will bind to the original child DOM elements when its initial value is truthy, and keep a copy of the elements as a template. 
  • The if and ifnot bindings will bind to the original child DOM elements when the initial value is truthy for if or falsy for ifnot. Additionally, they will only re-render the content when the truthiness of the value changes. 
  • The attr binding handles the name attribute properly in older versions of IE. 

Computed observable and binding dependency enhancements
  • Observables (including computed) include a peek function for access within a computed without adding a dependency.
  • observableArray mutation functions no longer cause a dependency within a computed. 
  • Writes to writeable computeds can now be chained like observables. 
  • Computed observables now have an isActive function that indicates that the computed has dependencies (can be triggered again). 
  • change (normal manual subscription) and beforeChange callbacks no longer create dependencies. 
foreach and template enhancements
  • When a function is used for the template name, it now receives the binding context as the second argument. 
  • The foreach functionality now does its best to understand items that were moved and move their content rather than re-render them. 
  • beforeMove and afterMove callbacks can now be configured when using foreach functionality. 
  • The foreach and template bindings now accept an as option to give $data an alias. 
  • The afterRenderbeforeRemoveafterAddbeforeMove, and afterMove callbacks will no longer cause dependencies. 
Other binding enhancements
  • The ko object is now available from within bindings, even if ko is not global, such as when used with an AMD loader. 
  • Can access the current element in a binding using the $element variable. 
  • Can access the current context directly in a binding using the $context variable. 

It's well worth upgrading your apps to this new version. Let us know how you get on! Thanks again to everyone who contributed code, bug reports, feature requests, and support :)

Steve

tom.v.e...@gmail.com

unread,
Oct 30, 2012, 4:38:47 AM10/30/12
to knock...@googlegroups.com
Does the css binding with a computed observable allow you to return a null or empty string when no CSS class is required?
So for example in a scenario like this, where depending on the value a different class name gets returned, but when the value is below 50 it would not have a CSS class name:

viewModel.warningStatus = ko.computed(function() {
    if (this.status() > 100) {
        return 'red';
    }
    else if (this.status() > 50) {
        return 'yellow';
    }
    else {
        return ''; // or even return null
    } 
});

Benoit R

unread,
Oct 30, 2012, 5:24:42 AM10/30/12
to knock...@googlegroups.com
Neat ! Thank you very much for creating and continuing to improve this library ! I use it every day for work...

I love the new as argument in foreach. Very useful for complex nesting ! I would love to have the same in the with binding !

Also, more tricky but an else binding would be very natural...

Benoit

Michael Best

unread,
Oct 30, 2012, 5:55:24 AM10/30/12
to knock...@googlegroups.com, tom.v.e...@gmail.com
Yes, it will work with an empty string or null.

-- Michael

Ω Alisson

unread,
Oct 30, 2012, 10:31:29 AM10/30/12
to knock...@googlegroups.com
Congratulations!

loved...@gmail.com

unread,
Oct 30, 2012, 10:26:37 PM10/30/12
to knock...@googlegroups.com
Hi could you please demo some project about the isActive function ! Thanks !

rpn

unread,
Oct 30, 2012, 11:10:30 PM10/30/12
to knock...@googlegroups.com, loved...@gmail.com
The isActive flag would be for pretty advanced usage. It basically can tell you if your computed observable has any dependencies (that is can be triggered again).  Internally, Knockout can avoid some work when it knows that the computed observable that tracks a binding's dependencies will never be triggered, so it looks for this flag.  An example would be when you are binding against a non-observable or static value.

shoky

unread,
Oct 30, 2012, 11:37:50 PM10/30/12
to knock...@googlegroups.com
Thank you so much, been waiting for these changes for a long time.
It's great to see big chunks of rpn and mbest's branches being incorporated into KO proper, your work is invaluable

Victor Antofica

unread,
Nov 1, 2012, 4:33:09 PM11/1/12
to knock...@googlegroups.com
I want to pass a parameter to my template, is it now possible?


On Monday, 29 October 2012 11:12:31 UTC, Steve Sanderson wrote:

Denys Khanzhiyev

unread,
Nov 1, 2012, 6:14:49 PM11/1/12
to knockoutjs
What do you mean? As for me it was always possible. You may construct  your binding context with data property of template binding.

For example:

<!-- ko template: { name:'labeledEdit', data: { id:'in1', caption:'Some Input 1', value: value1 }} -->

<script id='labeledEdit' type='text/html'>
<label data-bind='attr:{ for: id}'>
     <span data-bind='text: caption'></span>
    :
 </label>
<input data-bind='value:value, attr: {id:id}'>
</script

<script>
 var viewModel {
      value1:ko.observable(),
};
    
ko.applyBindings(viewModel);
<script>


2012/11/1 Victor Antofica <victo...@gmail.com>

Denys Khanzhiyev

unread,
Nov 1, 2012, 6:16:35 PM11/1/12
to knockoutjs
Ohh ..
<!-- ko template: { name:'labeledEdit', data: { id:'in1', caption:'Some Input 1', value: value1 }} -->
<!-- /ko -->
<script id='labeledEdit' type='text/html'>
<label data-bind='attr:{ for: id}'>
     <span data-bind='text: caption'></span>
    :
 </label>
<input data-bind='value:value, attr: {id:id}'>
</script

<script>
 var viewModel {
      value1:ko.observable(),
};
    
ko.applyBindings(viewModel);
</script>


2012/11/2 Denys Khanzhiyev <xde...@gmail.com>

Victor Antofica

unread,
Nov 1, 2012, 7:06:18 PM11/1/12
to knock...@googlegroups.com
the problem is I am not using data, I am using foreach
so if I add a foreach statement, your example  will stop working http://jsfiddle.net/mfhdS/

Denys Khanzhiyev

unread,
Nov 1, 2012, 7:34:25 PM11/1/12
to knockoutjs
Wrap template in foreach http://jsfiddle.net/xdenser/mfhdS/1/


2012/11/2 Victor Antofica <victo...@gmail.com>

Josh Beall

unread,
Nov 5, 2012, 8:51:06 AM11/5/12
to knock...@googlegroups.com
On Monday, October 29, 2012 7:12:31 AM UTC-4, Steve Sanderson wrote:
Yay, it's released! The 2.2.0 Release Candidate build proved pretty solid (thanks to everyone who tried it), the docs are all updated, the specs are 100% passing on all supported browsers, and so this new release is final as of today.

Great news!  And I'm looking forward to the ASP.NET CDN hosted version being available. As of right now (8:50 AM US Eastern, Nov 5th 2012), the latest Knockout version hosted on the ASP.NET CDN is 2.1.0.  Link to check the current status:

  -Josh

Michael Best

unread,
Nov 5, 2012, 6:11:02 PM11/5/12
to knock...@googlegroups.com

Michael Best

unread,
Nov 6, 2012, 4:32:08 AM11/6/12
to knock...@googlegroups.com
Knockout 2.2.0 is now available in the jsFiddle framework list.

Josh Beall

unread,
Nov 8, 2012, 4:22:44 PM11/8/12
to knock...@googlegroups.com
On Monday, October 29, 2012 7:12:31 AM UTC-4, Steve Sanderson wrote:
Yay, it's released! The 2.2.0 Release Candidate build proved pretty solid (thanks to everyone who tried it), the docs are all updated, the specs are 100% passing on all supported browsers, and so this new release is final as of today.

So, next up: API documentation, as mentioned some time ago, so folks like me can learn their way around? Pretty please? :-D

   -Josh

Павел Климашкин

unread,
Nov 14, 2012, 12:12:12 PM11/14/12
to knock...@googlegroups.com
Is it possible to use an as option in virtual foreach?

понедельник, 29 октября 2012 г., 15:12:31 UTC+4 пользователь Steve Sanderson написал:

Michael Best

unread,
Nov 14, 2012, 3:40:33 PM11/14/12
to knock...@googlegroups.com
Yes. 

<!-- ko foreach: { data: myItems, as: 'item' } -->
...
Reply all
Reply to author
Forward
0 new messages