The partial implementation code for the subscription feature is as follows:
/* */var uid = 0;/** * A DEP is A observable that can has multiple * directives subscribing to it. */var dep = function dep () {this.id = uid++; This.subs = [];};D Ep.prototype.addSub = function AddSub (sub) {This.subs.push (sub);};D Ep.prototype.removeSub = function Removesub (sub) {Remove (this.subs, sub);};D Ep.prototype.depend = function depend () {if (dep.target) {DEP.TARGET.ADDDEP (this); }};D ep.prototype.notify = function Notify () {//Stabilize the Subscriber list first var subs = This.subs.slice (); for (var i = 0, L = subs.length; i < L; i++) {subs[i].update (); }};//the current target watcher being evaluated.//this is globally unique because there could being only one//watcher Bein G evaluated at any time. Dep.target = Null;var Targetstack = [];function pushtarget (_target) {if (dep.target) {Targetstack.push (Dep.target);} Dep.target = _target;} function Poptarget () {dep.target = Targetstack.pop ();} /* */
Vuejs Source code excerpt