Giter Site home page Giter Site logo

vuedemo's Introduction

vuedemo's People

Contributors

answershuto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vuedemo's Issues

一点小建议

感觉这里可以优化一下
22行:set: function reactiveSetter (newVal) {
if (newVal === val) return;
val = newVal;
cb(newVal);
}

关于 《响应式系统的依赖收集追踪原理》.js 中一些疑惑

该 JS 文件中有 defineReactive 函数定义如下:

function defineReactive (obj, key, val) {
  const dep = new Dep();
  
  Object.defineProperty(obj, key, {
      enumerable: true,
      configurable: true,
      get: function reactiveGetter () {
          dep.addSub(Dep.target);
          return val;         
      },
      set: function reactiveSetter (newVal) {
          if (newVal === val) return;
          val = newVal;
          dep.notify();
      }
  });
}

不太明白为什么要把 dep.addSub(Dep.target); 放到 get 方法里面呢?这样就会一定要读取过属性才会添加到订阅队列中,感觉 不太好。改成以下会不会好一些呢?

function defineReactive (obj, key, val) {
  const dep = new Dep();
  dep.addSub(Dep.target);
  
  Object.defineProperty(obj, key, {
      enumerable: true,
      configurable: true,
      get: function reactiveGetter () {
          return val;         
      },
      set: function reactiveSetter (newVal) {
          if (newVal === val) return;
          val = newVal;
          dep.notify();
      }
  });
}

《批量异步更新策略及 nextTick 原理》.js 中的一些问题

flushSchedulerQueue() 函数在遍历执行所有的 watcher 之后,应该要清空当前的 watcher 队列才对的,即 queue.length = 0,完整代码如下:

function flushSchedulerQueue () {
    let watcher, id;

    for (index = 0; index < queue.length; index++) {
        watcher = queue[index]
        id = watcher.id;
        has[id] = null;
        watcher.run();
    }

    waiting  = false;
    queue.length = 0;
}

如果不清空队列的话,在以后的 nextTick() 中就会重复执行之前的旧的 watcher ,比如,测试代码中在一秒后再执行 watch1.update() :

(function () {
    let watch1 = new Watcher();
    let watch2 = new Watcher();

    watch1.update();
    watch1.update();
    watch2.update();

    setTimeout(() => {
      watch1.update();
    }, 1000)
})();

会发现,在一秒之后,只更新了 watcher1, 但是, watcher2 也会执行。

parseEndTag方法中currentParent指向错误

parseEndTag 方法中

    if (pos >= 0) {
        stack.length = pos;
        currentParent = stack[pos]; 
    }   

currentParent指向错误,如果将测试html语句

<div :class="c" class="demo" v-if="isShow">
    <span v-for="item in sz">{{item}}</span>
</div> 

变为

 <div :class="c" class="demo" v-if="isShow">
     <span>2333</span>
     <span>23333</span>
</div>  

则生成的ast的diiv的children只有一个span,建议修改一下currentParent的指向

    if (pos >= 0) {
        if(pos>0){
            currentParent = stack[pos - 1]
        }
        else{
            currentParent = null
        }
        stack.length = pos
    } 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.