Book Image

KnockoutJS Web Development

Book Image

KnockoutJS Web Development

Overview of this book

Table of Contents (13 chapters)
KnockoutJS Web Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Purifying our computations


Now we are going to redo the script section of code using pureComputed versus computed. The term pureComputed was inspired by the concept of pure functions as a style of programming. It is nothing you need to understand to use so don't get caught up with the semantics of the name as there is no practical win as far as learning how these pure computations benefit us here.

When Knockout has something watching, a computed item is called a subscriber. Thus, it is considered to be a subscriber dependency. If we use the pureComputed method versus the computed method, Knockout will not calculate the value when there are no subscribers. This, of course, adds more speed to our processes by reducing calculations that aren't needed and unnecessary code from running. It is also another way to avoid any chance of memory issues.

When there are no subscribers, a pure computed observable is considered to be sleeping. When there are subscribers it is considered to be listening. The...