How to make observable property to notify always in KnockoutJS

Introduction

 
In this blog, let us see how to make an observable always notify the change to the subscribers.
 
By default, the observable will notify the subscriber-only if the value is changed otherwise it does not.
 
To enable the observable to notify always we have to use always extender.
 
For example, if you have an observable property called name, you want to display the change count for the name property.
  1. var vm = {  
  2.     name: ko.observable('Jagan').extend({ notify: 'always' }),  
  3.     count: ko.observable(0)  
  4. }; 
Here in the above code, you can see the extender notify used. if you set the notify to always, then the observable will notify the subscriber always even if the value changed is the same as the original value.
  1. vm.name.subscribe(function() { this.count(this.count() + 1) }, vm); 
We have a subscriber for the name observable above. whenever we get notification, will increase the count property to display the count of name changes.
  1. <p> Name: <input data-bind="value: name" /> </p>  
  2. <p> Name has been changed <span data-bind="text: count"></span> times </p> 
The above view bindings are used to demonstrate the example.
 
Output: