Wrapcode

Revisiting KnockoutJS - v3.2 cherry-picks

| 5 min read

In case you missed it

It's been awhile since KnockoutJS released it's latest stable iteration 3.2. It was a real slow paced development however it introduce some of the most wanted features KnockoutJS was missing since the beginning. KnockoutJS community didn't make any fuss over it's release. Hence, ICYMI article.

> Feature-centric release

3.2 is purely feature-centric along with some minor bug fixes and patches. Find detailed change log on github.

What's new?

KnockoutJS 3.2 comes with several new features worth taking a look. If you are serious about making your HTML code more readable and avoiding memory leaks, you should definitely refactor your code and use these features.

Pure computed observables

Although ko.computed is one of the powerful key features of KnockoutJS. In the same way, ko.computed, if used without care, is prone to memory leaks which can heavily impact your application's performance. Fortunately, there's a fix for that.

memory-leaks ]

Pure computed variables, defined as ko.pureComputed, do not maintain subscriptions to its dependencies when it has no subscriptions at all. Resulting improved performance and prevention of memory leaks. Pure computed variable is in sleeping state when there are no subscribers, which means it pauses the evaluator. It enters in to the listening state as soon as there is a subscriber resulting immediate invocation of an evaluator.

I have customized the default example from pureComputed documentation in order to demonstrate the exact difference between ko.computed and ko.pureComputed.