Track Number Of Evaluations In Knockout
I would like to know how to I track the number of evaluation in knockout observable array for GetArray1() and GetArray2() below. I have read a sample from this fiddle link but not
Solution 1:
well in the link you provided they are creating a function using fn
which has the computation logic for getting the re-evaluation
count
Better way would be using inbuilt functions isInitial
and getDependenciesCount
of computed under computedContext
.
Logic :
ko.computed(function () {
var subscribe = self.sampleArray(); //declared on top to subscribe initiallyif (ko.computedContext.isInitial()) returntrue;
var count = ko.computedContext.getDependenciesCount();
self.revaluationCount(self.revaluationCount() + count);
});
As per Docs :
isInitial() — A function that returns true if called during the first ever evaluation of the current computed observable, or false otherwise. For pure computed observables, isInitial() is always undefined.
getDependenciesCount() — Returns the number of dependencies of the computed observable detected so far during the current evaluation.
Check here for complete documentation .
working sample with complete code here
Post a Comment for "Track Number Of Evaluations In Knockout"