ustbhuangyi / vue-analysis

:thumbsup: Vue.js 源码分析
https://ustbhuangyi.github.io/vue-analysis/
MIT License
7.68k stars 1.65k forks source link

关于nextTick的实现 #71

Closed zhatongning closed 4 years ago

zhatongning commented 5 years ago

在nextTick实现里,有一段关于macrotask和microtask的执行顺序的模拟:

for (macroTask of macroTaskQueue) {
    // 1. Handle current MACRO-TASK
    handleMacroTask();

    // 2. Handle all MICRO-TASK
    for (microTask of microTaskQueue) {
        handleMicroTask(microTask);
    }
}

是不是将第二点提到第一点之上更合适:

for (macroTask of macroTaskQueue) {

    // 1. Handle all MICRO-TASK
    for (microTask of microTaskQueue) {
        handleMicroTask(microTask);
    }

   // 2. Handle current MACRO-TASK
    handleMacroTask();
}