var uid = 0 /** * A dep is an observable that can have multiple * directives subscribing to it. * * @constructor */ function Dep () { this.id = ++uid this.subs = [] } var p = Dep.prototype /** * Add a directive subscriber. * * @param {Directive} sub */ p.addSub = function (sub) { this.subs.push(sub) } /** * Remove a directive subscriber. * * @param {Directive} sub */ p.removeSub = function (sub) { if (this.subs.length) { var i = this.subs.indexOf(sub) if (i > -1) this.subs.splice(i, 1) } } /** * Notify all subscribers of a new value. */ p.notify = function () { for (var i = 0, l = this.subs.length; i < l; i++) { this.subs[i].update() } } module.exports = Dep