|
|
@@ -2,7 +2,7 @@ import Vue from '../instance/index'
|
|
|
import { callHook } from '../instance/lifecycle'
|
|
|
import { warn } from '../util/index'
|
|
|
|
|
|
-export default function Component (Ctor, data, parent, children, context) {
|
|
|
+export default function Component (Ctor, data, parent, children) {
|
|
|
if (typeof Ctor === 'object') {
|
|
|
Ctor = Vue.extend(Ctor)
|
|
|
}
|
|
|
@@ -14,14 +14,29 @@ export default function Component (Ctor, data, parent, children, context) {
|
|
|
'dependencies and optimizes re-rendering.'
|
|
|
)
|
|
|
}
|
|
|
+ // merge hooks on the placeholder node itself
|
|
|
+ const hook = { init, insert, prepatch, destroy }
|
|
|
+ if (data.hook) {
|
|
|
+ for (let key in data.hook) {
|
|
|
+ let existing = hook[key]
|
|
|
+ let fromParent = data.hook[key]
|
|
|
+ hook[key] = existing ? mergeHook(existing, fromParent) : fromParent
|
|
|
+ }
|
|
|
+ }
|
|
|
// return a placeholder vnode
|
|
|
return {
|
|
|
tag: 'component',
|
|
|
key: data && data.key,
|
|
|
- data: {
|
|
|
- hook: { init, insert, prepatch, destroy },
|
|
|
- Ctor, data, parent, children, context
|
|
|
- }
|
|
|
+ data: { hook, Ctor, data, parent, children }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function mergeHook (a, b) {
|
|
|
+ // since all hooks have at most two args, use fixed args
|
|
|
+ // to avoid having to use fn.apply().
|
|
|
+ return (_, __) => {
|
|
|
+ a(_, __)
|
|
|
+ b(_, __)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -29,7 +44,6 @@ function init (vnode) {
|
|
|
const data = vnode.data
|
|
|
const child = new data.Ctor({
|
|
|
parent: data.parent,
|
|
|
- _context: data.context,
|
|
|
_renderData: data.data,
|
|
|
_renderChildren: data.children
|
|
|
})
|