zoukankan      html  css  js  c++  java
  • vue.js源码学习分享(八)

    /*  */
    
    
    var uid$1 = 0;
    
    /**
     * A dep is an observable that can have multiple
     * directives subscribing() to it.//一个dep 是一个可观察到的,dep能有多样的订阅指示
     */
    var Dep = function Dep () {
      this.id = uid$1++;
      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 () {
      // stablize 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();
    }
    
    /*
     * not type checking this file because flow doesn't play well with//非类型检查这个文件,因为流不会很好的考虑动态的使用在数组原型上的方法
     * dynamically(动态) accessing(使用) methods on Array prototype
     */
    
    var arrayProto = Array.prototype;
    var arrayMethods = Object.create(arrayProto);
    [
    'push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse' ] .forEach(function (method) { // cache original method var original = arrayProto[method]; def(arrayMethods, method, function mutator () { var arguments$1 = arguments; // avoid leaking arguments://避开arguments的漏洞 // http://jsperf.com/closure-with-arguments var i = arguments.length; var args = new Array(i); while (i--) { args[i] = arguments$1[i]; } var result = original.apply(this, args); var ob = this.__ob__; var inserted; switch (method) { case 'push': inserted = args; break case 'unshift': inserted = args; break case 'splice': inserted = args.slice(2); break } if (inserted) { ob.observeArray(inserted); } // notify change ob.dep.notify(); return result }); });
  • 相关阅读:
    Linux常用操作命令
    Linux下查看CPU型号,内存大小,硬盘空间命令
    PhpExcel中文帮助手册|PhpExcel使用方法
    PHP操作cookie函数:setcookie()与setrawcookie()
    利用phantomjs模拟QQ自动登录
    无法在同一张表上查询和更新的问题解决方法
    App开放接口api安全性—Token签名sign的设计与实现
    开放api接口签名验证
    bootstrap字体图标
    booatrap中的表格样式
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/6672419.html
Copyright © 2011-2022 走看看