Angular deepWatcher
Add watch to every leaf in an object.
by dandoyon
HTML
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<ul id="results"></ul>
CSS
#results li.pass { color: green; }
#results li.fail { color: red; }
JavaScript
function assert(value, desc) {
var li = document.createElement("li");
li.className = value ? "pass" : "fail";
li.appendChild(document.createTextNode(desc));
document.getElementById("results").appendChild(li);
}
var target = {
deepWatcher: function(obj, handler) {
var self = this;
self.watchers = self.watchers || [];
/*
var container = {};
var prop = properties.shift();
if(properties.length > 0) {
container[prop] = arguments.callee(properties,val);
} else {
container[prop] = val;
}
return container;
*/
return self.watchers;
}
};
var obj = { a : 123 };
var actual = target.deepWatcher(obj, function() {});
assert((actual.length == 1), "there is only one obj with a handler");