[This seems to be impossible. I will answer this question by myself later]
This question largely continues my pervious one. I use "async computed" approach to refresh some parts of my page. Thanks to Michael Best I solved issue with updates of invisible parts of UI. But one annoying thing still here. How can I set initial (default) value to computed observable? I try to avoid multiple ajax calls during page load. Instead of it I embed json into page to load everything at once. Seems trivial (common)? But I can't supress first evaluation of my async computed. So ajax call will be made in any case. I could use this approach:
var isFirstEval = ko.observable(true);
updateComputed = ko.pureComputed(function () {
updateTrigger();
if(isFirstEval()){
isFirstEval(false);
result(initialValue);
}
else
result(evaluator.call(owner));
});
But I face the same issue, as in the previous question: this computed will never subscribe on evaluator
changes, because of approach knockout uses to reevaluate computed observables.
The suggestion from similar question works because it checks for the first evaluation after var value = self.product() * self.quantity();
. So the computed is always tracking product
and quantity
. I can't use this approach, because I can't call evaluator
just to care about dependency as evaluator
can make ajax call...
Does any way exists to supress the first evaluation of computed (or pure computed)? Or maybe way to set initial value? Any suggestions? Other workarounds?