diff --git a/index.js b/index.js index 08462bb..1d43308 100644 --- a/index.js +++ b/index.js @@ -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) } }