Hi All,
I'm facing a problem at the moment where I need to be able to force an observable to fire its update handler regardless of whether the new value is different from _latestValue or not. This is because my observable is being called as a callback rather than being triggered directly by a change event on the bound element (it's a custom autocomplete control).
The ideal solution would be a "force" flag on the observable:
myObservable("new value", /* force = */ true)
Is there any other way to do this?
Cheers, Andrew.
observables have a valueHasMutated
function that you can call for this purpose.
You just need to do:
myObservable.valueHasMutated()
You can also make the observable always notify when it's updated:
myObservable = ko.observable().extend({notify: 'always'});
myObservable("new value"); // will notify even if the value is already "new value"
It's probably a good idea to have both of these methods in the documentation.
valueHasMutated works like a charm! Thanks, guys :-)
Most helpful comment
observables have a
valueHasMutated
function that you can call for this purpose.You just need to do:
myObservable.valueHasMutated()