Knockout makes it easier to create rich, responsive UIs with JavaScript
This release fixes a few regression bugs in 3.5.0:
if
option throws an error #2446value
binding on <select>
when the options are generated via a foreach
binding #2452arrayChange
notifications when using deferred updates #2454<script>
template contents #24843.5.1 also fixes some issues with and expands 3.5.0's TypeScript definitions.
Knockout 3.5.0 includes a few new bindings and new ways to interact with observables and bindings. The full list is detailed under 3.5.0 Beta, 3.5.0 RC, and 3.5.0 RC2.
The final 3.5.0 release includes fixes for a few regressions in the pre-production releases:
if
bindings (#2414)foreach
and beforeRemove
(#2419)foreach
and Punches plugin (#2433)foreach
and if
(#2439)This release includes a number of fixes for regressions in the previous 3.5.0 release candidate. Given the time since the RC, we also decided to include a few small improvements.
foreach
binding.style
binding to correctly append px
.ko.contextFor
when used after ko.applyBindingsToNode
.ko.utils
to use native array methods.createChildContextWithAs
option and add noChildContext
binding option. The default behavior for as
matches previous releases.descendantsComplete
and if
/ifnot
/with
bindings.if
/ifnot
/with
bindings: completeOn: "render"
will have the binding wait to trigger descendantsComplete
until it is rendered.ko.applyBindings
throws an error if a non-Node is given as the second parameter.options
objects as a parameter to createChildContext
.method
parameter to the rateLimit
extender.style
binding.foreach
.We decided to keep the more standard return value for ko.utils.arrayFirst
, which now returns undefined
instead of null
when no item matches.
Changes since 3.5.0 Beta:
descendantsComplete
to include bindings other than component
, such as if
, with
, etc.ko.when
will return a Promise if called without a callback function.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 the foreach
binding, Knockout will set the named value for each item in the array but won't create a child context. In other words, when using as
, you will have to use the named value in bindings: text: item.property
rather than text: property
. This can be controlled by setting ko.options.createChildContextWithAs = true
. (See #907)
To improve performance when array changes are from a known, single operation, such as push
, the foreach
binding no longer filters out destroyed items by default. To turn this off and filter out destroyed items, you can set includeDestroyed: false
in the foreach
binding or set ko.options.foreachHidesDestroyed = true
to use the previous behavior by default. (See #2324)
if
and with
using the new childrenComplete
binding or subscribing to the childrenComplete
binding event.
(See #2310)koDescendantsComplete
method in the component viewmodel or subscribing to the descendantsComplete
binding event. (See #2319)sorted
and reversed
methods that return a modified copy of the array. This is in contrast to sort
and reverse
that modify the array itself.class
binding supports dynamic class strings. This allows you to use the css
and class
bindings together to support both methods of setting CSS classes.using
binding, similarly to with
, binds its descendant elements in the context of the child viewmodel. Unlike with
, which re-renders its contents when the viewmodel changes, using
will just trigger each descendant binding to update.hidden
binding works oppositely to visible
.let
binding allows you to set values that can be used in all descendant element bindings, regardless of context.let
, you can set such values at the root context by providing a function as the third parameter to ko.applyBindings
. (See #2024)spectate
event whenever their value changes. Unlike the standard change
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.getDependencies
method that returns an array of the observables that the computed is currently watching.attr
binding supports namespaced attributes such as xlink:href
in svg
elements.ko.when
function allows you to run code once when an observable or condition becomes true.ko.isObservableArray
function can be used to check if something is a ko.observableArray
.style
binding will use jQuery
if present. Even without jQuery, the binding now supports standard style names, such as background-color
, and automatically appends px
if needed to styles that expect it.<!--/ko-->
).30 or so separate fixes are included in this release,
css
binding accepts multiple classes in a string and dynamic class names.text
binding can be used in virtual elements: <!--ko text: myValue--><!--/ko-->
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.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.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.attr
binding handles the name attribute properly in older versions of IE.peek
function for access within a computed without adding a dependency.observableArray
mutation functions no longer cause a dependency within a computed.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
enhancementsforeach
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.foreach
and template
bindings now accept an as
option to give $data
an alias.afterRender
, beforeRemove
, afterAdd
, beforeMove
, and afterMove
callbacks will no longer cause dependencies.ko
object is now available from within bindings, even if ko
is not global, such as when used with an AMD loader.$element
variable.$context
variable.This release fixes a number of bugs related to deferred updates and computed observables.
Fixed:
pureComputed
sometimes doesn't pick up a change in a dependency (#1975 and #1992)arrayChange
events (#1973 and #1974)$rawData
within with
bindings and rendered templates (#1415)computed._latestValue
in debug mode (b3f24b1e247c1b)ko.tasks
).ko.onError
handler, if defined, for errors from asynchronous code.ko.options.useOnlyNativeEvents
can be set to tell Knockout to use only native (not jQuery) events.ko.isPureComputed()
.The 3.4.0 RC release notes has the full list of issues and pull requests included in this release. The final release fixes two regression bugs found in the RC:
beforeRemove
behavior can break retained items.ko.computed
.setTimeout
. Since microtasks are run before the browser repaints the page, all loaded components will be initialized and displayed in a single repaint. Although this reduces the overall time needed to display components, it could result in a longer delay before anything is displayed.ko.observable
and ko.computed
no longer use a closure when defining their methods, such as dispose
and valueHasMutated
. These functions expect this
to be set correctly and so can't be used directly as a callback. Instead you'll need to use bind
, such as obs.dispose.bind(obs)
.