vue.js 源代码学习笔记 ----- instance render
/* @flow */ import {
warn,
nextTick,
toNumber,
_toString,
looseEqual,
emptyObject,
handleError,
looseIndexOf
} from '../util/index' import VNode, {
cloneVNodes,
createTextVNode,
createEmptyVNode
} from '../vdom/vnode' import { createElement } from '../vdom/create-element'
import { renderList } from './render-helpers/render-list'
import { renderSlot } from './render-helpers/render-slot'
import { resolveFilter } from './render-helpers/resolve-filter'
import { checkKeyCodes } from './render-helpers/check-keycodes'
import { bindObjectProps } from './render-helpers/bind-object-props'
import { renderStatic, markOnce } from './render-helpers/render-static'
import { resolveSlots, resolveScopedSlots } from './render-helpers/resolve-slots' export function initRender (vm: Component) {
vm.$vnode = null // the placeholder node in parent tree 站位节点
vm._vnode = null // the root of the child tree 根节点
vm._staticTrees = null
const parentVnode = vm.$options._parentVnode
const renderContext = parentVnode && parentVnode.context
vm.$slots = resolveSlots(vm.$options._renderChildren, renderContext)
vm.$scopedSlots = emptyObject
// bind the createElement fn to this instance
// so that we get proper render context inside it.
// args order: tag, data, children, normalizationType, alwaysNormalize
// internal version is used by render functions compiled from templates
// 把创建元素 的函数绑定到这个实例上, 这样就能得到合适的渲染上下文;
// 参数的顺序是: 标签 数据 子节点 规范化的类型 是否总是规范化
vm._c = (a, b, c, d) => createElement(vm, a, b, c, d, false)
// normalization is always applied for the public version, used in
// user-written render functions.
// 规范化总是应用在公共的版本, 应用在用户编写的 渲染函数
vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)
} export function renderMixin (Vue: Class<Component>) {
//定义 $nextTick函数, 实际调用了 nextTick方法
Vue.prototype.$nextTick = function (fn: Function) {
return nextTick(fn, this)
} Vue.prototype._render = function (): VNode {
const vm: Component = this
const {
render,
staticRenderFns,
_parentVnode
} = vm.$options if (vm._isMounted) {
// clone slot nodes on re-renders
for (const key in vm.$slots) {
//克隆虚拟节点给自己
vm.$slots[key] = cloneVNodes(vm.$slots[key])
}
}
//scopedSlots ...
vm.$scopedSlots = (_parentVnode && _parentVnode.data.scopedSlots) || emptyObject if (staticRenderFns && !vm._staticTrees) {
vm._staticTrees = []
}
// set parent vnode. this allows render functions to have access
// to the data on the placeholder node.
// 设置父虚拟节点, 这使得渲染函数可以访问站位节点上的数据 vm.$vnode = _parentVnode
// render self
let vnode
try {
vnode = render.call(vm._renderProxy, vm.$createElement)
} catch (e) {
handleError(e, vm, `render function`)
// return error render result,
// or previous vnode to prevent render error causing blank component
/* istanbul ignore else */
// 返回一个错误渲染的结果, 或者前一个虚拟节点放在呈现错误的时候引起空白组件
if (process.env.NODE_ENV !== 'production') {
vnode = vm.$options.renderError
? vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e)
: vm._vnode
} else {
vnode = vm._vnode
}
}
// return empty vnode in case the render function errored out
// 返回空的虚拟节点 假如渲染函数出错了
if (!(vnode instanceof VNode)) {
if (process.env.NODE_ENV !== 'production' && Array.isArray(vnode)) {
warn(
'Multiple root nodes returned from render function. Render function ' +
'should return a single root node.',
vm
)
}
vnode = createEmptyVNode()
}
// set parent
vnode.parent = _parentVnode
return vnode
} // internal render helpers.
// these are exposed on the instance prototype to reduce generated render
// code size.
// 用简写, 生成实例的时候减少代码
Vue.prototype._o = markOnce
Vue.prototype._n = toNumber
Vue.prototype._s = _toString
Vue.prototype._l = renderList
Vue.prototype._t = renderSlot
Vue.prototype._q = looseEqual
Vue.prototype._i = looseIndexOf
Vue.prototype._m = renderStatic
Vue.prototype._f = resolveFilter
Vue.prototype._k = checkKeyCodes
Vue.prototype._b = bindObjectProps
Vue.prototype._v = createTextVNode
Vue.prototype._e = createEmptyVNode
Vue.prototype._u = resolveScopedSlots
}
vue.js 源代码学习笔记 ----- instance render的更多相关文章
- vue.js 源代码学习笔记 ----- instance proxy
/* not type checking this file because flow doesn't play well with Proxy */ import config from 'core ...
- vue.js 源代码学习笔记 ----- instance init
/* @flow */ import config from '../config' import { initProxy } from './proxy' import { initState } ...
- vue.js 源代码学习笔记 ----- instance index
import { initMixin } from './init' import { stateMixin } from './state' import { renderMixin } from ...
- vue.js 源代码学习笔记 ----- instance state
/* @flow */ import Dep from '../observer/dep' import Watcher from '../observer/watcher' import { set ...
- vue.js 源代码学习笔记 ----- instance event
/* @flow */ import { updateListeners } from '../vdom/helpers/index' import { toArray, tip, hyphenate ...
- vue.js 源代码学习笔记 ----- instance inject
/* @flow */ import { hasSymbol } from 'core/util/env' import { warn } from '../util/index' import { ...
- vue.js 源代码学习笔记 ----- core lifecycle
/* @flow */ import config from '../config' import Watcher from '../observer/watcher' import { mark, ...
- vue.js 源代码学习笔记 ----- html-parse.js
/** * Not type-checking this file because it's mostly vendor code. */ /*! * HTML Parser By John Resi ...
- vue.js 源代码学习笔记 ----- keep-alives
/* @flow */ import { callHook } from 'core/instance/lifecycle' import { getFirstComponentChild } fro ...
随机推荐
- 【Thinking in Java, 4e】访问权限控制
[包:库单元] 编译单元的概念. 一个.java文件就是一个编译单元,一个编译单元只能有一个public类,编译单元中的非public类一般是用于为public类提供支持的,这些类在包外不可见. im ...
- 分享基于Sails.js和React.js的全栈聊天室
在线地址: http://fiora.suisuijiang.com/ 项目源码[ 路过求star(^_^) ]: 后端: https://github.com/yinxin630/fiora-bac ...
- lamp编译详解
首先确认系统环境:centos6.4 min版本 1.安装需要的开发环境 yum groupinstall "Development Tools" "Server Pla ...
- 异常: error MSB8008: 指定的平台工具集(V120)未安装或无效
打开项目属性->配置属性->常规,平台工作集,选为v100
- Linux升级内核总结
Linux内核升级总结. 一.编译内核步骤 1.#uname –r 确定系统的原内核版本,然后下载较新版本的Linux内核源码包 http://www.kernel.org/pub/linux/ker ...
- JDK 中的监控与故障处理工具-03 (jstat)
jstat : JVM statistics monitoring tool jstat 命令可以监控 JVM 虚拟机各种运行时状态信息, 包括 内存状态 ,垃圾回收 ,类的装载等信息. jstat ...
- 使用淘宝的npm代理下载模块
npm install node-sass --registry=http://registry.npm.taobao.org
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B题
2017-09-24 19:16:38 writer:pprp 题目链接:https://www.jisuanke.com/contest/877 题目如下: You are given a list ...
- 基于Redis的限流系统的设计
本文讲述基于Redis的限流系统的设计,主要会谈及限流系统中限流策略这个功能的设计:在实现方面,算法使用的是令牌桶算法来,访问Redis使用lua脚本. 1.概念 In computer netw ...
- tp5搭建1
1.首先在wamp环境根目录下创建文件夹resource. 2.利用composer下载tp5框架 怎么利用composer下载tp5框架 根据tp5完全开发手册,composer下载你的tp5框架 ...