How to Trigger Knockout-Computables manually ...

2014-06-16 | #knockout, #solution

There really does not seem to be a native method for this in the current version being 3.1.0.

Alternatively just expand knockout with this extended computable:

/**

* add a computed to knockout,

* that can manually trigger an value update with forceUpdateNotification()

*/

ko.forcibleComputed = function(readFunc, context, options) {

var trigger = ko.observable().extend({notify:'always'});

var target = ko.computed(function() {

trigger();

return readFunc.call(context);

},

null,

options

);

target.forceUpdateNotification = function() {

trigger.valueHasMutated();

};

return target;

};