filur filur - 1 year ago 128
Javascript Question

Get computed observable dependencies

Let's say that I have a viewmodel which looks something like this: = ko.observable(); = ko.observable();

this.bah = ko.pureComputed(function(){
var bar =;
}, this);

this.baz = ko.pureComputed(function(){
var foo =,
bah = this.bah();
}, this);

Is there any way to access the dependencies of a computed observable dynamically? In the example above with
, I would like a list with
, since they are the two observables that can trigger the computed.

I need this for debugging purposes.

Answer Source

AFAIK there is no documented or public API to get this information. In addition, I think (though am not sure) that internally KnockoutJS works the other way around: an observable knows who are dependent on it ("subscribers"), as opposed to the dependency knowing about the observables it depends on.

The only thing that comes close is baz.getDependenciesCount(), but that only gives you a number. You can check out the relevant source file to see what other things computeds expose.

The only other option that might help: include the unminified / debug version of KnockoutJS, and use the debugger to dig into the underlying problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download