filur filur - 8 months ago 70
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.


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.