[TOC]
*****
## 4 helper.js 编译助手
>[info] import
~~~
;(导入)数组基础工具
import { isArray } from 'shared/util'
~~~
>[info] module
~~~
;基础警告接口
export function baseWarn (msg) {
console.error(`[Vue parser]: ${msg}`)
}
;el添加prop
export function addProp (el, name, value) {
(el.props || (el.props = [])).push({ name, value })
}
;el添加attrs
export function addAttr (el, name, value) {
(el.attrs || (el.attrs = [])).push({ name, value })
}
;el添加StaticAttr
export function addStaticAttr (el, name, value) {
(el.staticAttrs || (el.staticAttrs = [])).push({ name, value })
}
;el添加指令
export function addDirective (el, name, value, arg, modifiers) {
(el.directives || (el.directives = [])).push({ name, value, arg, modifiers })
}
;el添加style
export function addStyleBinding (el, name, value) {
const code = `"${name}":${value}`
el.styleBinding = el.styleBinding
? el.styleBinding.replace(/}\s?$/, `,${code}}`)
: `{${code}}`
}
;el添加hook
export function addHook (el, name, code) {
const hooks = el.hooks || (el.hooks = {})
const hook = hooks[name]
if (hook) {
hook.push(code)
} else {
hooks[name] = [code]
}
}
;el添加事件handler
export function addHandler (el, name, value, modifiers) {
const events = el.events || (el.events = {})
// check capture modifier
if (modifiers && modifiers.capture) {
delete modifiers.capture
name = '!' + name // mark the event as captured
}
const newHandler = { value, modifiers }
const handlers = events[name]
if (isArray(handlers)) {
handlers.push(newHandler)
} else if (handlers) {
events[name] = [handlers, newHandler]
} else {
events[name] = newHandler
}
}
;获取绑定属性v-bind
export function getBindingAttr (el, name, getStatic) {
const staticValue = getStatic !== false && getAndRemoveAttr(el, name)
return staticValue || staticValue === ''
? JSON.stringify(staticValue)
: (getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name))
}
;获取帮删除绑定属性v-bind
export function getAndRemoveAttr (el, name) {
let val
if ((val = el.attrsMap[name]) != null) {
el.attrsMap[name] = null
const list = el.attrsList
for (let i = 0, l = list.length; i < l; i++) {
if (list[i].name === name) {
list.splice(i, 1)
break
}
}
}
return val
}
~~~
>[info] export
~~~
;(导出)基础警告
export function baseWarn (msg) {}
export function addProp (el, name, value) {}
export function addAttr (el, name, value) {}
export function addStaticAttr (el, name, value) {}
export function addDirective (el, name, value, arg, modifiers) {}
export function addStyleBinding (el, name, value) {}
export function addHook (el, name, code) {}
export function addHandler (el, name, value, modifiers) {}
export function getBindingAttr (el, name, getStatic) {}
export function getAndRemoveAttr (el, name) {}
;(导出)添加事件处理接口
export function addHandler (el, name, value, modifiers) {}
;(导出)获取绑定属性
export function getBindingAttr (el, name, getStatic) {}
;(导出)获取并删除绑定属性
export function getAndRemoveAttr (el, name) {}
~~~
- 概述
- 框架结构
- 编译入口(\entries)
- web-compiler.js(web编译)
- web-runtime.js(web运行时)
- web-runtime-wih-compiler.js(web编译运行)
- web-server-renderer.js(web服务器渲染)
- 核心实现 (\core)
- index.js(核心入口)
- config.js(核心配置)
- core\util(核心工具)
- core\observer(双向绑定)
- core\vdom(虚拟DOM)
- core\global-api(核心api)
- core\instance(核心实例)
- 模板编译(\compiler)
- compiler\parser(模板解析)
- events.js(事件解析)
- helper.js(解析助手)
- directives\ref.js(ref指令)
- optimizer.js(解析优化)
- codegen.js(渲染生成)
- index.js(模板编译入口)
- web渲染(\platforms\web)
- compiler(web编译目录)
- runtime(web运行时目录)
- server(web服务器目录)
- util(web工具目录)
- 服务器渲染(\server)
- render-stream.js(流式渲染)
- render.js(服务器渲染函数)
- create-renderer.js(创建渲染接口)
- 框架流程
- Vue初始化
- Vue视图数据绑定
- Vue数据变化刷新
- Vue视图操作刷新
- 框架工具
- 基础工具(\shared)
- 模板编译助手
- 核心实例工具
- Web渲染工具
- 基础原理
- dom
- string
- array
- function
- object
- es6
- 模块(Module)
- 类(Class)
- 函数(箭头)
- 字符串(扩展)
- 代理接口(Proxy)
- 数据绑定基础
- 数据绑定实现
- mvvm简单实现
- mvvm简单使用
- vdom算法
- vdom实现
- vue源码分析资料