Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,48 @@ var internalHooks = [
'activate'
]

function decorator (options) {
return function (Component) {
options.name = options.name || Component.name
// prototype props.
var proto = Component.prototype
Object.getOwnPropertyNames(proto).forEach(function (key) {
if (key === 'constructor') {
return
}
// hooks
if (internalHooks.indexOf(key) > -1) {
options[key] = proto[key]
return
}
var descriptor = Object.getOwnPropertyDescriptor(proto, key)
if (typeof descriptor.value === 'function') {
// methods
(options.methods || (options.methods = {}))[key] = descriptor.value
} else if (descriptor.get || descriptor.set) {
// computed properties
(options.computed || (options.computed = {}))[key] = {
get: descriptor.get,
set: descriptor.set
}
function componentFactory (Component, options) {
if (!options) {
options = {}
}
options.name = options.name || Component.name
// prototype props.
var proto = Component.prototype
Object.getOwnPropertyNames(proto).forEach(function (key) {
if (key === 'constructor') {
return
}
// hooks
if (internalHooks.indexOf(key) > -1) {
options[key] = proto[key]
return
}
var descriptor = Object.getOwnPropertyDescriptor(proto, key)
if (typeof descriptor.value === 'function') {
// methods
(options.methods || (options.methods = {}))[key] = descriptor.value
} else if (descriptor.get || descriptor.set) {
// computed properties
(options.computed || (options.computed = {}))[key] = {
get: descriptor.get,
set: descriptor.set
}
})
// find super
var Super = proto.__proto__.constructor
if (!(Super instanceof Vue)) {
Super = Vue
}
return Super.extend(options)
})
// find super
var Super = proto.__proto__.constructor
if (!(Super instanceof Vue)) {
Super = Vue
}
return Super.extend(options)
}

function decorator (options) {
if (typeof options === 'function') {
return componentFactory(options)
}
return function (Component) {
return componentFactory(Component, options)
}
}

Expand Down