Sha256: cf31337dfb50de9af86ad72a9011870938afb2c3beef5f954798e20b382bcec7
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
var _ = require('../util') var uid = 0 /** * A dep is an observable that can have multiple * directives subscribing to it. * * @constructor */ function Dep () { this.id = uid++ this.subs = [] } // the current target watcher being evaluated. // this is globally unique because there could be only one // watcher being evaluated at any time. Dep.target = null /** * Add a directive subscriber. * * @param {Directive} sub */ Dep.prototype.addSub = function (sub) { this.subs.push(sub) } /** * Remove a directive subscriber. * * @param {Directive} sub */ Dep.prototype.removeSub = function (sub) { this.subs.$remove(sub) } /** * Add self as a dependency to the target watcher. */ Dep.prototype.depend = function () { Dep.target.addDep(this) } /** * Notify all subscribers of a new value. */ Dep.prototype.notify = function () { // stablize the subscriber list first var subs = _.toArray(this.subs) for (var i = 0, l = subs.length; i < l; i++) { subs[i].update() } } module.exports = Dep
Version data entries
3 entries across 3 versions & 1 rubygems