订阅功能的部分实现代码如下:

/*  */

var uid = 0;

/**
* A dep is an observable that can have multiple
* directives subscribing to it.
*/
var Dep = function Dep () {
this.id = uid++;
this.subs = [];
}; Dep.prototype.addSub = function addSub (sub) {
this.subs.push(sub);
}; Dep.prototype.removeSub = function removeSub (sub) {
remove(this.subs, sub);
}; Dep.prototype.depend = function depend () {
if (Dep.target) {
Dep.target.addDep(this);
}
}; Dep.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 be only one
// watcher being 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();
} /* */

最新文章

  1. 混合 Data Warehouse 和 Big Data 倉庫的新架構
  2. python的正则表达式
  3. 2013-09-25-【随笔】-Roy
  4. babel 无法解析jsx (webpack react )
  5. Lost connection to MySQL server at 'reading initial communication packet' 错误解决
  6. 在Entity Framework中重用现有的数据库连接字符串
  7. HDU Train Problem I 1022 栈模拟
  8. Thinkphp 连接数据库、查询、添加
  9. NOIP2011-普及组复赛模拟试题-第二题-买票
  10. 【Spark2.0源码学习】-2.一切从脚本说起
  11. Dynamics CRM2015 Custom Code Validation Tool工具的使用
  12. 为Arch Linux更换Archlinuxcn源(清华源)
  13. Spring的@Transactional事务注意事项
  14. vue-resource: jsonp请求百度搜索的接口
  15. LeetCode--No.009 Palindrome Number
  16. get post 小结
  17. opencv的DMatch
  18. 10个CSS+HOVER 的创意按钮
  19. 解决sdk manager下载非常慢或者下载失败
  20. 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth 题解

热门文章

  1. hdp 2.06 安装备忘
  2. Js屏蔽键盘输入的某些字符,用以部分代替正则表达式
  3. [HAOI2011]Problem b BZOJ2301 数学
  4. ajax beforeSend中无效果
  5. Qt 学习之路 2(37):文本文件读写
  6. angularjs中向html页面添加内容节点元素代码段的两种方法
  7. Largest Submatrix of All 1’s(思维+单调栈)
  8. POJ - 3735 循环操作
  9. C#.net 设置Access-Control-Allow-Origin来实现跨域
  10. cmd命令行编译c/c++程序