Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find which observable dependency change fired computed evaluation; dump the context

Tags:

knockout.js

If I set a break point inside a knockout.js computed, I see two frames in the call stack (using Chrome's F12 facility)

  • my computed (debugger stopped at the break point)
  • knockout's function evaluateImmediate() at var newValue = readFunction.call(evaluatorFunctionTarget);

I believe knockout defers/throttles computed evaluation using a timeout mechanism. They must be storing the trigger(s) that caused the computed to re-evaluate, yes? Where?

Is there also a "remembered" context that is available to the evaluating computed? Where?

like image 992
G. Stoynev Avatar asked Sep 06 '13 19:09

G. Stoynev


People also ask

How does ko computed work?

Whenever you declare a computed observable, KO immediately invokes its evaluator function to get its initial value. While the evaluator function is running, KO sets up a subscription to any observables (including other computed observables) that the evaluator reads.

What is Knockout observable?

Knockout. js defines an important role when we want to detect and respond to changes on one object, we uses the observable. An observable is useful in various scenarios where we are displaying or editing multiple values and require repeated sections of the UI to appear and disappear as items are inserted and deleted.

What computed observables?

Computed Observable is a function which is dependent on one or more Observables and automatically updates whenever its underlying Observables (dependencies) change. Computed Observables can be chained.

What is knockout js used for?

Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.


1 Answers

If you are using the throttle extender then yes the evaluation is deferred. But the reason the evaluation was triggered is not stored. It is unusual, when using Knockout, to care about which dependency triggered your evaluation.

like image 91
Brandon Avatar answered Sep 30 '22 18:09

Brandon