knockout v3.5.0-beta Release Notes
Release Date: 2017-12-29 // about 6 years ago-
๐ Knockout 3.5.0 beta release notes
Full list of issues: https://github.com/knockout/knockout/milestone/9?closed=1
Important: This release includes some minor breaking changes to the
foreach
binding to improve performance and clarify features. These changes can be turned off using global options.๐ When using the
as
option with theforeach
binding, Knockout will set the named value for each item in the array but won't create a child context. In other words, when usingas
, you will have to use the named value in bindings:text: item.property
rather thantext: property
. This can be controlled by settingko.options.createChildContextWithAs = true
. (See #907)To improve performance when array changes are from a known, single operation, such as
push
, theforeach
binding no longer filters out destroyed items by default. To turn this off and filter out destroyed items, you can setincludeDestroyed: false
in theforeach
binding or setko.options.foreachHidesDestroyed = true
to use the previous behavior by default. (See #2324)Other enhancements
- You can react to the completion of bindings such as
if
andwith
using the newchildrenComplete
binding or subscribing to thechildrenComplete
binding event.
๐ (See #2310) - ๐ You can react to the completion of components, including nested components, by including a
koDescendantsComplete
method in the component viewmodel or subscribing to thedescendantsComplete
binding event. (See #2319) - ๐ Binding strings can include template literals (backticks) and C++ and C-style comments.
- Observable arrays include
sorted
andreversed
methods that return a modified copy of the array. This is in contrast tosort
andreverse
that modify the array itself. - ๐ The new
class
binding supports dynamic class strings. This allows you to use thecss
andclass
bindings together to support both methods of setting CSS classes. - โก๏ธ The new
using
binding, similarly towith
, binds its descendant elements in the context of the child viewmodel. Unlikewith
, which re-renders its contents when the viewmodel changes,using
will just trigger each descendant binding to update. - The new
hidden
binding works oppositely tovisible
. - The new
let
binding allows you to set values that can be used in all descendant element bindings, regardless of context. - ๐ Similarly to
let
, you can set such values at the root context by providing a function as the third parameter toko.applyBindings
. (See #2024) - ๐ Performance improvement: String templates are no longer parsed each time they are referenced. Instead the parsed nodes are cached and cloned.
- โก๏ธ Observables notify a new
spectate
event whenever their value changes. Unlike the standardchange
event, this new event isn't necessarily delayed by rate-limiting or deferred updates. You can subscribe to the event without waking a sleeping pure computed; the computed will notify the event if it is accessed with a new value. - Computed observables include a
getDependencies
method that returns an array of the observables that the computed is currently watching. - ๐ The
attr
binding supports namespaced attributes such asxlink:href
insvg
elements. - The
ko.when
function allows you to run code once when an observable or condition becomes true. - The
ko.isObservableArray
function can be used to check if something is ako.observableArray
. - ๐
The
style
binding will usejQuery
if present. Even without jQuery, the binding now supports standard style names, such asbackground-color
, and automatically appendspx
if needed to styles that expect it. - Knockout will throw an error if it finds an unmatched closing virtual element (
<!--/ko-->
).
๐ Fixes
๐ 30 or so separate fixes are included in this release,
- You can react to the completion of bindings such as