Skip to content

Commit

Permalink
refactor: simplify internal component creation
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 28, 2017
1 parent f5ce6b5 commit 7e46683
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
4 changes: 0 additions & 4 deletions flow/options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
declare type InternalComponentOptions = {
_isComponent: true;
parent: Component;
propsData: ?Object;
_parentVnode: VNode;
_parentListeners: ?Object;
_renderChildren: ?Array<VNode>;
_componentTag: ?string;
_parentElm: ?Node;
_refElm: ?Node;
render?: Function;
Expand Down
14 changes: 9 additions & 5 deletions src/core/instance/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ export function initMixin (Vue: Class<Component>) {
function initInternalComponent (vm: Component, options: InternalComponentOptions) {
const opts = vm.$options = Object.create(vm.constructor.options)
// doing this because it's faster than dynamic enumeration.
const parentVnode = options._parentVnode
opts.parent = options.parent
opts.propsData = options.propsData
opts._parentVnode = options._parentVnode
opts._parentListeners = options._parentListeners
opts._renderChildren = options._renderChildren
opts._componentTag = options._componentTag
opts._parentVnode = parentVnode
opts._parentElm = options._parentElm
opts._refElm = options._refElm

const vnodeComponentOptions = parentVnode.componentOptions
opts.propsData = vnodeComponentOptions.propsData
opts._parentListeners = vnodeComponentOptions.listeners
opts._renderChildren = vnodeComponentOptions.children
opts._componentTag = vnodeComponentOptions.tag

if (options.render) {
opts.render = options.render
opts.staticRenderFns = options.staticRenderFns
Expand Down
7 changes: 1 addition & 6 deletions src/core/vdom/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,10 @@ export function createComponentInstanceForVnode (
parentElm?: ?Node,
refElm?: ?Node
): Component {
const vnodeComponentOptions = vnode.componentOptions
const options: InternalComponentOptions = {
_isComponent: true,
parent,
propsData: vnodeComponentOptions.propsData,
_componentTag: vnodeComponentOptions.tag,
_parentVnode: vnode,
_parentListeners: vnodeComponentOptions.listeners,
_renderChildren: vnodeComponentOptions.children,
_parentElm: parentElm || null,
_refElm: refElm || null
}
Expand All @@ -218,7 +213,7 @@ export function createComponentInstanceForVnode (
options.render = inlineTemplate.render
options.staticRenderFns = inlineTemplate.staticRenderFns
}
return new vnodeComponentOptions.Ctor(options)
return new vnode.componentOptions.Ctor(options)
}

function mergeHooks (data: VNodeData) {
Expand Down

0 comments on commit 7e46683

Please sign in to comment.