Skip to content

Commit

Permalink
rename vnode.child -> vnode.componentInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 12, 2017
1 parent 9b384bd commit 30258a9
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions flow/vnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare type VNodeComponentOptions = {

declare type MountedComponentVNode = {
componentOptions: VNodeComponentOptions;
child: Component;
componentInstance: Component;
parent: VNode;
data: VNodeData;
}
Expand All @@ -26,7 +26,7 @@ declare type VNodeWithData = {
context: Component;
key: string | number | void;
parent?: VNodeWithData;
child?: Component;
componentInstance?: Component;
isRootInsert: boolean;
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/components/keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default {
? opts.Ctor.cid + (opts.tag ? `::${opts.tag}` : '')
: vnode.key
if (this.cache[key]) {
vnode.child = this.cache[key].child
vnode.componentInstance = this.cache[key].componentInstance
} else {
this.cache[key] = vnode
}
Expand All @@ -52,8 +52,8 @@ export default {
destroyed () {
for (const key in this.cache) {
const vnode = this.cache[key]
callHook(vnode.child, 'deactivated')
vnode.child.$destroy()
callHook(vnode.componentInstance, 'deactivated')
vnode.componentInstance.$destroy()
}
}
}
24 changes: 12 additions & 12 deletions src/core/vdom/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ function init (
parentElm: ?Node,
refElm: ?Node
): ?boolean {
if (!vnode.child || vnode.child._isDestroyed) {
const child = vnode.child = createComponentInstanceForVnode(
if (!vnode.componentInstance || vnode.componentInstance._isDestroyed) {
const child = vnode.componentInstance = createComponentInstanceForVnode(
vnode,
activeInstance,
parentElm,
Expand All @@ -177,7 +177,7 @@ function prepatch (
vnode: MountedComponentVNode
) {
const options = vnode.componentOptions
const child = vnode.child = oldVnode.child
const child = vnode.componentInstance = oldVnode.componentInstance
child._updateFromParent(
options.propsData, // updated props
options.listeners, // updated listeners
Expand All @@ -187,23 +187,23 @@ function prepatch (
}

function insert (vnode: MountedComponentVNode) {
if (!vnode.child._isMounted) {
vnode.child._isMounted = true
callHook(vnode.child, 'mounted')
if (!vnode.componentInstance._isMounted) {
vnode.componentInstance._isMounted = true
callHook(vnode.componentInstance, 'mounted')
}
if (vnode.data.keepAlive) {
vnode.child._inactive = false
callHook(vnode.child, 'activated')
vnode.componentInstance._inactive = false
callHook(vnode.componentInstance, 'activated')
}
}

function destroy (vnode: MountedComponentVNode) {
if (!vnode.child._isDestroyed) {
if (!vnode.componentInstance._isDestroyed) {
if (!vnode.data.keepAlive) {
vnode.child.$destroy()
vnode.componentInstance.$destroy()
} else {
vnode.child._inactive = true
callHook(vnode.child, 'deactivated')
vnode.componentInstance._inactive = true
callHook(vnode.componentInstance, 'deactivated')
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/vdom/modules/ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function registerRef (vnode: VNodeWithData, isRemoval: ?boolean) {
if (!key) return

const vm = vnode.context
const ref = vnode.child || vnode.elm
const ref = vnode.componentInstance || vnode.elm
const refs = vm.$refs
if (isRemoval) {
if (Array.isArray(refs[key])) {
Expand Down
20 changes: 10 additions & 10 deletions src/core/vdom/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ export function createPatchFunction (backend) {
function createComponent (vnode, insertedVnodeQueue, parentElm, refElm) {
let i = vnode.data
if (isDef(i)) {
const isReactivated = isDef(vnode.child) && i.keepAlive
const isReactivated = isDef(vnode.componentInstance) && i.keepAlive
if (isDef(i = i.hook) && isDef(i = i.init)) {
i(vnode, false /* hydrating */, parentElm, refElm)
}
// after calling the init hook, if the vnode is a child component
// it should've created a child instance and mounted it. the child
// component also has set the placeholder vnode's elm.
// in that case we can just return the element and be done.
if (isDef(vnode.child)) {
if (isDef(vnode.componentInstance)) {
initComponent(vnode, insertedVnodeQueue)
if (isReactivated) {
reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm)
Expand All @@ -185,8 +185,8 @@ export function createPatchFunction (backend) {
// again. It's not ideal to involve module-specific logic in here but
// there doesn't seem to be a better way to do it.
let innerNode = vnode
while (innerNode.child) {
innerNode = innerNode.child._vnode
while (innerNode.componentInstance) {
innerNode = innerNode.componentInstance._vnode
if (isDef(i = innerNode.data) && isDef(i = i.transition)) {
for (i = 0; i < cbs.activate.length; ++i) {
cbs.activate[i](emptyNode, innerNode)
Expand Down Expand Up @@ -221,8 +221,8 @@ export function createPatchFunction (backend) {
}

function isPatchable (vnode) {
while (vnode.child) {
vnode = vnode.child._vnode
while (vnode.componentInstance) {
vnode = vnode.componentInstance._vnode
}
return isDef(vnode.tag)
}
Expand All @@ -242,7 +242,7 @@ export function createPatchFunction (backend) {
if (vnode.data.pendingInsert) {
insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert)
}
vnode.elm = vnode.child.$el
vnode.elm = vnode.componentInstance.$el
if (isPatchable(vnode)) {
invokeCreateHooks(vnode, insertedVnodeQueue)
setScope(vnode)
Expand Down Expand Up @@ -316,7 +316,7 @@ export function createPatchFunction (backend) {
rm.listeners += listeners
}
// recursively invoke hooks on child component root node
if (isDef(i = vnode.child) && isDef(i = i._vnode) && isDef(i.data)) {
if (isDef(i = vnode.componentInstance) && isDef(i = i._vnode) && isDef(i.data)) {
removeAndInvokeRemoveHook(i, rm)
}
for (i = 0; i < cbs.remove.length; ++i) {
Expand Down Expand Up @@ -420,7 +420,7 @@ export function createPatchFunction (backend) {
vnode.key === oldVnode.key &&
(vnode.isCloned || vnode.isOnce)) {
vnode.elm = oldVnode.elm
vnode.child = oldVnode.child
vnode.componentInstance = oldVnode.componentInstance
return
}
let i
Expand Down Expand Up @@ -483,7 +483,7 @@ export function createPatchFunction (backend) {
const { tag, data, children } = vnode
if (isDef(data)) {
if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode, true /* hydrating */)
if (isDef(i = vnode.child)) {
if (isDef(i = vnode.componentInstance)) {
// child component. it should have hydrated its own tree.
initComponent(vnode, insertedVnodeQueue)
return true
Expand Down
4 changes: 2 additions & 2 deletions src/core/vdom/vnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class VNode {
functionalContext: Component | void; // only for functional component root nodes
key: string | number | void;
componentOptions: VNodeComponentOptions | void;
child: Component | void; // component instance
componentInstance: Component | void; // component instance
parent: VNode | void; // component placeholder node
raw: boolean; // contains raw HTML? (server only)
isStatic: boolean; // hoisted static node
Expand Down Expand Up @@ -39,7 +39,7 @@ export default class VNode {
this.functionalContext = undefined
this.key = data && data.key
this.componentOptions = componentOptions
this.child = undefined
this.componentInstance = undefined
this.parent = undefined
this.raw = false
this.isStatic = false
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/web/runtime/directives/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { enter, leave } from '../modules/transition'

// recursively search for possible transition defined inside the component root
function locateNode (vnode: VNode): VNodeWithData {
return vnode.child && (!vnode.data || !vnode.data.transition)
? locateNode(vnode.child._vnode)
return vnode.componentInstance && (!vnode.data || !vnode.data.transition)
? locateNode(vnode.componentInstance._vnode)
: vnode
}

Expand Down
4 changes: 2 additions & 2 deletions src/platforms/web/util/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export function genClassForVnode (vnode: VNode): string {
let data = vnode.data
let parentNode = vnode
let childNode = vnode
while (childNode.child) {
childNode = childNode.child._vnode
while (childNode.componentInstance) {
childNode = childNode.componentInstance._vnode
if (childNode.data) {
data = mergeClassData(childNode.data, data)
}
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/web/util/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export function getStyle (vnode: VNode, checkChild: boolean): Object {

if (checkChild) {
let childNode = vnode
while (childNode.child) {
childNode = childNode.child._vnode
while (childNode.componentInstance) {
childNode = childNode.componentInstance._vnode
if (childNode.data && (styleData = normalizeStyleData(childNode.data))) {
extend(res, styleData)
}
Expand Down

0 comments on commit 30258a9

Please sign in to comment.