toy-vue

Airbnb Style PRs Welcome

Vue toys.

vue-base.html

一个不能再简单的 Vue 核心代码,一个不能再具体的 Vue 源码分析。(此处用了夸张的修辞手法)。代码参考了vue-come-true/vue-come-true-First,在此感谢原作者的整理。

PS: vue-base.html 需要在最新的 Chrome 上运行,因为用到了很多 ES6 的特性,比如:class, arrow function 等。当然,作为一个前端,我默认你的 Chrome 版本已经是最新了。

Vue 创建流程

vue-base

Dep 和 Watcher 关系

dep-watcher

流程图下载

你可以从 Google Drive 下载流程图

注意点

Simple Vue Compiler

Simple Vue Compiler基于pure-javascript-html-parserHTML Parser(你可以在线测试这个模块)。

ASTElement 是从 HTML 转换到可 render 的代码过程中的中间对象。AST(Abstract Syntax Tree): 抽象语法树。(我们在写这个编译器的时候,AST 参考Hypertext Abstract Syntax Tree format )

基本的过程是:模板 => HTML 模板解析器 => 抽象语法树 => 生成可Render的代码

在线测试 Simple Vue Compiler ,降模板编译成可Render代码的简易实现。 qq 20170710222219

Vue 中对应的代码

生成可 render 代码后,便可以通过render函数创建 virtual dom 了。

Virtual Dom

netxTick

console.log(1);
Promise.resolve().then(() => console.log(2))
setTimeout(() => console.log(3), 0);
setTimeout(() => console.log(4), 0);
Promise.resolve().then(() => console.log(5))
console.log(6);
/*
output:
1 6 2 5 3 4
*/

更多关于 Promise, Mutation observers, Microtasks 的,请查看 Tasks, microtasks, queues and schedules.

References