响应式数据原理

模板编译原理

tempalte模版

  1. <div id="abc">hello</div>

ast语法抽象树

  1. {
  2. tag: 'div',
  3. type: 1
  4. attrs: [
  5. {name: "id", value: "abc"}
  6. ],
  7. children: [
  8. {type: 3, text: "hello"}
  9. ],
  10. parent: null,
  11. }

render

  1. with(this) {
  2. return _c('div',{id:'abc'},_v('hello'))
  3. }

从render生成vnode,_c、_v、_s方法都有对应的vnode结构

vnode类

  1. class Vnode {
  2. constructor(tag, data, key, children, text) {
  3. self.tag = tag
  4. self.data = data
  5. self.key = key
  6. self.children = children
  7. self.text = text
  8. }
  9. }

拿到vnode结构,进入到_update
在_update中有patch