2024-09-11 10:55:44 +08:00

19 lines
408 B
JavaScript

// 发布者
export default class Dep {
constructor() {
this.subs = []; // 搜集所有的watcher
}
// 添加watcher
addSub(sub) {
this.subs.push(sub);
}
// 通知watcher更新
notify() {
this.subs.forEach((sub) => {
// 具体如何更新,发布者是不管的,它只负责通知
sub.update();
});
}
}
Dep.target = null; // 一会儿用于记录当前 watcher