vuejs源码摘抄
2024-08-25 22:20:53
订阅功能的部分实现代码如下:
/* */ 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();
} /* */
最新文章
- 混合 Data Warehouse 和 Big Data 倉庫的新架構
- python的正则表达式
- 2013-09-25-【随笔】-Roy
- babel 无法解析jsx (webpack react )
- Lost connection to MySQL server at 'reading initial communication packet' 错误解决
- 在Entity Framework中重用现有的数据库连接字符串
- HDU Train Problem I 1022 栈模拟
- Thinkphp 连接数据库、查询、添加
- NOIP2011-普及组复赛模拟试题-第二题-买票
- 【Spark2.0源码学习】-2.一切从脚本说起
- Dynamics CRM2015 Custom Code Validation Tool工具的使用
- 为Arch Linux更换Archlinuxcn源(清华源)
- Spring的@Transactional事务注意事项
- vue-resource: jsonp请求百度搜索的接口
- LeetCode--No.009 Palindrome Number
- get post 小结
- opencv的DMatch
- 10个CSS+HOVER 的创意按钮
- 解决sdk manager下载非常慢或者下载失败
- 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth 题解
热门文章
- hdp 2.06 安装备忘
- Js屏蔽键盘输入的某些字符,用以部分代替正则表达式
- [HAOI2011]Problem b BZOJ2301 数学
- ajax beforeSend中无效果
- Qt 学习之路 2(37):文本文件读写
- angularjs中向html页面添加内容节点元素代码段的两种方法
- Largest Submatrix of All 1’s(思维+单调栈)
- POJ - 3735 循环操作
- C#.net 设置Access-Control-Allow-Origin来实现跨域
- cmd命令行编译c/c++程序