feat: implement basic hooks

This commit is contained in:
Evan You
2018-10-27 22:10:25 -04:00
parent 6982f755fd
commit 832d715afe
5 changed files with 131 additions and 6 deletions

View File

@@ -172,10 +172,7 @@ export function mergeComponentOptions(to: any, from: any): ComponentOptions {
res[key] = value
} else {
// merge lifecycle hooks
res[key] = function(...args: any[]) {
existing.call(this, ...args)
value.call(this, ...args)
}
res[key] = mergeLifecycleHooks(existing, value)
}
} else if (isArray(value) && isArray(existing)) {
res[key] = existing.concat(value)
@@ -188,6 +185,13 @@ export function mergeComponentOptions(to: any, from: any): ComponentOptions {
return res
}
export function mergeLifecycleHooks(a: Function, b: Function): Function {
return function(...args: any[]) {
a.call(this, ...args)
b.call(this, ...args)
}
}
export function mergeDataFn(a: Function, b: Function): Function {
// TODO: backwards compat requires recursive merge,
// but maybe we should just warn if we detect clashing keys