knockout v3.5.0-beta Release Notes

Release Date: 2017-12-29 // over 4 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 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)

    Other enhancements

    • You can react to the completion of bindings such as if and with using the new childrenComplete binding or subscribing to the childrenComplete 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 the descendantsComplete binding event. (See #2319)
    • ๐Ÿ’… Binding strings can include template literals (backticks) and C++ and C-style comments.
    • Observable arrays include 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.
    • ๐Ÿ‘ The new 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.
    • โšก๏ธ The new 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.
    • The new hidden binding works oppositely to visible.
    • 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 to ko.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 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.
    • 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 as xlink:href in svg 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 a ko.observableArray.
    • ๐Ÿ’… The 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.
    • 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,