vue-class-component
Advanced tools
Comparing version 6.2.0 to 6.3.0
/** | ||
* vue-class-component v6.2.0 | ||
* vue-class-component v6.3.0 | ||
* (c) 2015-present Evan You | ||
@@ -14,3 +14,33 @@ * @license MIT | ||
var hasProto = { __proto__: [] } instanceof Array; | ||
function reflectionIsSupported() { | ||
return (Reflect && Reflect.defineMetadata) !== undefined; | ||
} | ||
function copyReflectionMetadata(to, from) { | ||
forwardMetadata(to, from); | ||
Object.getOwnPropertyNames(from.prototype).forEach(function (key) { | ||
forwardMetadata(to.prototype, from.prototype, key); | ||
}); | ||
Object.getOwnPropertyNames(from).forEach(function (key) { | ||
forwardMetadata(to, from, key); | ||
}); | ||
} | ||
function forwardMetadata(to, from, propertyKey) { | ||
var metaKeys = propertyKey | ||
? Reflect.getOwnMetadataKeys(from, propertyKey) | ||
: Reflect.getOwnMetadataKeys(from); | ||
metaKeys.forEach(function (metaKey) { | ||
var metadata = propertyKey | ||
? Reflect.getOwnMetadata(metaKey, from, propertyKey) | ||
: Reflect.getOwnMetadata(metaKey, from); | ||
if (propertyKey) { | ||
Reflect.defineMetadata(metaKey, metadata, to, propertyKey); | ||
} | ||
else { | ||
Reflect.defineMetadata(metaKey, metadata, to); | ||
} | ||
}); | ||
} | ||
var fakeArray = { __proto__: [] }; | ||
var hasProto = fakeArray instanceof Array; | ||
function createDecorator(factory) { | ||
@@ -39,3 +69,3 @@ return function (target, key, index) { | ||
var type = typeof value; | ||
return value == null || (type !== "object" && type !== "function"); | ||
return value == null || (type !== 'object' && type !== 'function'); | ||
} | ||
@@ -67,3 +97,3 @@ function warn(message) { | ||
get: function () { return vm[key]; }, | ||
set: function (value) { return vm[key] = value; }, | ||
set: function (value) { vm[key] = value; }, | ||
configurable: true | ||
@@ -124,5 +154,16 @@ }); | ||
var descriptor = Object.getOwnPropertyDescriptor(proto, key); | ||
if (typeof descriptor.value === 'function') { | ||
if (descriptor.value !== void 0) { | ||
// methods | ||
(options.methods || (options.methods = {}))[key] = descriptor.value; | ||
if (typeof descriptor.value === 'function') { | ||
(options.methods || (options.methods = {}))[key] = descriptor.value; | ||
} | ||
else { | ||
// typescript decorated data | ||
(options.mixins || (options.mixins = [])).push({ | ||
data: function () { | ||
var _a; | ||
return _a = {}, _a[key] = descriptor.value, _a; | ||
} | ||
}); | ||
} | ||
} | ||
@@ -155,2 +196,5 @@ else if (descriptor.get || descriptor.set) { | ||
forwardStaticMembers(Extended, Component, Super); | ||
if (reflectionIsSupported()) { | ||
copyReflectionMetadata(Extended, Component); | ||
} | ||
return Extended; | ||
@@ -201,5 +245,5 @@ } | ||
var superDescriptor = Object.getOwnPropertyDescriptor(Super, key); | ||
if (!isPrimitive(descriptor.value) | ||
&& superDescriptor | ||
&& superDescriptor.value === descriptor.value) { | ||
if (!isPrimitive(descriptor.value) && | ||
superDescriptor && | ||
superDescriptor.value === descriptor.value) { | ||
return; | ||
@@ -209,4 +253,4 @@ } | ||
// Warn if the users manually declare reserved properties | ||
if (process.env.NODE_ENV !== 'production' | ||
&& reservedPropertyNames.indexOf(key) >= 0) { | ||
if (process.env.NODE_ENV !== 'production' && | ||
reservedPropertyNames.indexOf(key) >= 0) { | ||
warn("Static property name '" + key + "' declared on class '" + Original.name + "' " + | ||
@@ -228,12 +272,8 @@ 'conflicts with reserved property name of Vue internal. ' + | ||
} | ||
(function (Component) { | ||
function registerHooks(keys) { | ||
$internalHooks.push.apply($internalHooks, keys); | ||
} | ||
Component.registerHooks = registerHooks; | ||
})(Component || (Component = {})); | ||
var Component$1 = Component; | ||
Component.registerHooks = function registerHooks(keys) { | ||
$internalHooks.push.apply($internalHooks, keys); | ||
}; | ||
exports.default = Component$1; | ||
exports.default = Component; | ||
exports.createDecorator = createDecorator; | ||
exports.mixins = mixins; |
/** | ||
* vue-class-component v6.2.0 | ||
* vue-class-component v6.3.0 | ||
* (c) 2015-present Evan You | ||
@@ -7,230 +7,269 @@ * @license MIT | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) : | ||
(factory((global.VueClassComponent = {}),global.Vue)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) : | ||
(factory((global.VueClassComponent = {}),global.Vue)); | ||
}(this, (function (exports,Vue) { 'use strict'; | ||
Vue = Vue && Vue.hasOwnProperty('default') ? Vue['default'] : Vue; | ||
Vue = Vue && Vue.hasOwnProperty('default') ? Vue['default'] : Vue; | ||
var hasProto = { __proto__: [] } instanceof Array; | ||
function createDecorator(factory) { | ||
return function (target, key, index) { | ||
var Ctor = typeof target === 'function' | ||
? target | ||
: target.constructor; | ||
if (!Ctor.__decorators__) { | ||
Ctor.__decorators__ = []; | ||
function reflectionIsSupported() { | ||
return (Reflect && Reflect.defineMetadata) !== undefined; | ||
} | ||
function copyReflectionMetadata(to, from) { | ||
forwardMetadata(to, from); | ||
Object.getOwnPropertyNames(from.prototype).forEach(function (key) { | ||
forwardMetadata(to.prototype, from.prototype, key); | ||
}); | ||
Object.getOwnPropertyNames(from).forEach(function (key) { | ||
forwardMetadata(to, from, key); | ||
}); | ||
} | ||
function forwardMetadata(to, from, propertyKey) { | ||
var metaKeys = propertyKey | ||
? Reflect.getOwnMetadataKeys(from, propertyKey) | ||
: Reflect.getOwnMetadataKeys(from); | ||
metaKeys.forEach(function (metaKey) { | ||
var metadata = propertyKey | ||
? Reflect.getOwnMetadata(metaKey, from, propertyKey) | ||
: Reflect.getOwnMetadata(metaKey, from); | ||
if (propertyKey) { | ||
Reflect.defineMetadata(metaKey, metadata, to, propertyKey); | ||
} | ||
else { | ||
Reflect.defineMetadata(metaKey, metadata, to); | ||
} | ||
}); | ||
} | ||
var fakeArray = { __proto__: [] }; | ||
var hasProto = fakeArray instanceof Array; | ||
function createDecorator(factory) { | ||
return function (target, key, index) { | ||
var Ctor = typeof target === 'function' | ||
? target | ||
: target.constructor; | ||
if (!Ctor.__decorators__) { | ||
Ctor.__decorators__ = []; | ||
} | ||
if (typeof index !== 'number') { | ||
index = undefined; | ||
} | ||
Ctor.__decorators__.push(function (options) { return factory(options, key, index); }); | ||
}; | ||
} | ||
function mixins() { | ||
var Ctors = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
Ctors[_i] = arguments[_i]; | ||
} | ||
if (typeof index !== 'number') { | ||
index = undefined; | ||
return Vue.extend({ mixins: Ctors }); | ||
} | ||
function isPrimitive(value) { | ||
var type = typeof value; | ||
return value == null || (type !== 'object' && type !== 'function'); | ||
} | ||
function warn(message) { | ||
if (typeof console !== 'undefined') { | ||
console.warn('[vue-class-component] ' + message); | ||
} | ||
Ctor.__decorators__.push(function (options) { return factory(options, key, index); }); | ||
}; | ||
} | ||
function mixins() { | ||
var Ctors = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
Ctors[_i] = arguments[_i]; | ||
} | ||
return Vue.extend({ mixins: Ctors }); | ||
} | ||
function isPrimitive(value) { | ||
var type = typeof value; | ||
return value == null || (type !== "object" && type !== "function"); | ||
} | ||
function warn(message) { | ||
if (typeof console !== 'undefined') { | ||
console.warn('[vue-class-component] ' + message); | ||
} | ||
} | ||
function collectDataFromConstructor(vm, Component) { | ||
// override _init to prevent to init as Vue instance | ||
var originalInit = Component.prototype._init; | ||
Component.prototype._init = function () { | ||
var _this = this; | ||
// proxy to actual vm | ||
var keys = Object.getOwnPropertyNames(vm); | ||
// 2.2.0 compat (props are no longer exposed as self properties) | ||
if (vm.$options.props) { | ||
for (var key in vm.$options.props) { | ||
if (!vm.hasOwnProperty(key)) { | ||
keys.push(key); | ||
function collectDataFromConstructor(vm, Component) { | ||
// override _init to prevent to init as Vue instance | ||
var originalInit = Component.prototype._init; | ||
Component.prototype._init = function () { | ||
var _this = this; | ||
// proxy to actual vm | ||
var keys = Object.getOwnPropertyNames(vm); | ||
// 2.2.0 compat (props are no longer exposed as self properties) | ||
if (vm.$options.props) { | ||
for (var key in vm.$options.props) { | ||
if (!vm.hasOwnProperty(key)) { | ||
keys.push(key); | ||
} | ||
} | ||
} | ||
} | ||
keys.forEach(function (key) { | ||
if (key.charAt(0) !== '_') { | ||
Object.defineProperty(_this, key, { | ||
get: function () { return vm[key]; }, | ||
set: function (value) { return vm[key] = value; }, | ||
configurable: true | ||
}); | ||
keys.forEach(function (key) { | ||
if (key.charAt(0) !== '_') { | ||
Object.defineProperty(_this, key, { | ||
get: function () { return vm[key]; }, | ||
set: function (value) { vm[key] = value; }, | ||
configurable: true | ||
}); | ||
} | ||
}); | ||
}; | ||
// should be acquired class property values | ||
var data = new Component(); | ||
// restore original _init to avoid memory leak (#209) | ||
Component.prototype._init = originalInit; | ||
// create plain data object | ||
var plainData = {}; | ||
Object.keys(data).forEach(function (key) { | ||
if (data[key] !== undefined) { | ||
plainData[key] = data[key]; | ||
} | ||
}); | ||
}; | ||
// should be acquired class property values | ||
var data = new Component(); | ||
// restore original _init to avoid memory leak (#209) | ||
Component.prototype._init = originalInit; | ||
// create plain data object | ||
var plainData = {}; | ||
Object.keys(data).forEach(function (key) { | ||
if (data[key] !== undefined) { | ||
plainData[key] = data[key]; | ||
{ | ||
if (!(Component.prototype instanceof Vue) && Object.keys(plainData).length > 0) { | ||
warn('Component class must inherit Vue or its descendant class ' + | ||
'when class property is used.'); | ||
} | ||
} | ||
}); | ||
{ | ||
if (!(Component.prototype instanceof Vue) && Object.keys(plainData).length > 0) { | ||
warn('Component class must inherit Vue or its descendant class ' + | ||
'when class property is used.'); | ||
} | ||
return plainData; | ||
} | ||
return plainData; | ||
} | ||
var $internalHooks = [ | ||
'data', | ||
'beforeCreate', | ||
'created', | ||
'beforeMount', | ||
'mounted', | ||
'beforeDestroy', | ||
'destroyed', | ||
'beforeUpdate', | ||
'updated', | ||
'activated', | ||
'deactivated', | ||
'render', | ||
'errorCaptured' // 2.5 | ||
]; | ||
function componentFactory(Component, options) { | ||
if (options === void 0) { options = {}; } | ||
options.name = options.name || Component._componentTag || Component.name; | ||
// prototype props. | ||
var proto = Component.prototype; | ||
Object.getOwnPropertyNames(proto).forEach(function (key) { | ||
if (key === 'constructor') { | ||
return; | ||
var $internalHooks = [ | ||
'data', | ||
'beforeCreate', | ||
'created', | ||
'beforeMount', | ||
'mounted', | ||
'beforeDestroy', | ||
'destroyed', | ||
'beforeUpdate', | ||
'updated', | ||
'activated', | ||
'deactivated', | ||
'render', | ||
'errorCaptured' // 2.5 | ||
]; | ||
function componentFactory(Component, options) { | ||
if (options === void 0) { options = {}; } | ||
options.name = options.name || Component._componentTag || 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 (descriptor.value !== void 0) { | ||
// methods | ||
if (typeof descriptor.value === 'function') { | ||
(options.methods || (options.methods = {}))[key] = descriptor.value; | ||
} | ||
else { | ||
// typescript decorated data | ||
(options.mixins || (options.mixins = [])).push({ | ||
data: function () { | ||
var _a; | ||
return _a = {}, _a[key] = descriptor.value, _a; | ||
} | ||
}); | ||
} | ||
} | ||
else if (descriptor.get || descriptor.set) { | ||
// computed properties | ||
(options.computed || (options.computed = {}))[key] = { | ||
get: descriptor.get, | ||
set: descriptor.set | ||
}; | ||
} | ||
}); | ||
(options.mixins || (options.mixins = [])).push({ | ||
data: function () { | ||
return collectDataFromConstructor(this, Component); | ||
} | ||
}); | ||
// decorate options | ||
var decorators = Component.__decorators__; | ||
if (decorators) { | ||
decorators.forEach(function (fn) { return fn(options); }); | ||
delete Component.__decorators__; | ||
} | ||
// hooks | ||
if ($internalHooks.indexOf(key) > -1) { | ||
options[key] = proto[key]; | ||
return; | ||
// find super | ||
var superProto = Object.getPrototypeOf(Component.prototype); | ||
var Super = superProto instanceof Vue | ||
? superProto.constructor | ||
: Vue; | ||
var Extended = Super.extend(options); | ||
forwardStaticMembers(Extended, Component, Super); | ||
if (reflectionIsSupported()) { | ||
copyReflectionMetadata(Extended, Component); | ||
} | ||
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 | ||
}; | ||
} | ||
}); | ||
(options.mixins || (options.mixins = [])).push({ | ||
data: function () { | ||
return collectDataFromConstructor(this, Component); | ||
} | ||
}); | ||
// decorate options | ||
var decorators = Component.__decorators__; | ||
if (decorators) { | ||
decorators.forEach(function (fn) { return fn(options); }); | ||
delete Component.__decorators__; | ||
return Extended; | ||
} | ||
// find super | ||
var superProto = Object.getPrototypeOf(Component.prototype); | ||
var Super = superProto instanceof Vue | ||
? superProto.constructor | ||
: Vue; | ||
var Extended = Super.extend(options); | ||
forwardStaticMembers(Extended, Component, Super); | ||
return Extended; | ||
} | ||
var reservedPropertyNames = [ | ||
// Unique id | ||
'cid', | ||
// Super Vue constructor | ||
'super', | ||
// Component options that will be used by the component | ||
'options', | ||
'superOptions', | ||
'extendOptions', | ||
'sealedOptions', | ||
// Private assets | ||
'component', | ||
'directive', | ||
'filter' | ||
]; | ||
function forwardStaticMembers(Extended, Original, Super) { | ||
// We have to use getOwnPropertyNames since Babel registers methods as non-enumerable | ||
Object.getOwnPropertyNames(Original).forEach(function (key) { | ||
// `prototype` should not be overwritten | ||
if (key === 'prototype') { | ||
return; | ||
} | ||
// Some browsers does not allow reconfigure built-in properties | ||
var extendedDescriptor = Object.getOwnPropertyDescriptor(Extended, key); | ||
if (extendedDescriptor && !extendedDescriptor.configurable) { | ||
return; | ||
} | ||
var descriptor = Object.getOwnPropertyDescriptor(Original, key); | ||
// If the user agent does not support `__proto__` or its family (IE <= 10), | ||
// the sub class properties may be inherited properties from the super class in TypeScript. | ||
// We need to exclude such properties to prevent to overwrite | ||
// the component options object which stored on the extended constructor (See #192). | ||
// If the value is a referenced value (object or function), | ||
// we can check equality of them and exclude it if they have the same reference. | ||
// If it is a primitive value, it will be forwarded for safety. | ||
if (!hasProto) { | ||
// Only `cid` is explicitly exluded from property forwarding | ||
// because we cannot detect whether it is a inherited property or not | ||
// on the no `__proto__` environment even though the property is reserved. | ||
if (key === 'cid') { | ||
var reservedPropertyNames = [ | ||
// Unique id | ||
'cid', | ||
// Super Vue constructor | ||
'super', | ||
// Component options that will be used by the component | ||
'options', | ||
'superOptions', | ||
'extendOptions', | ||
'sealedOptions', | ||
// Private assets | ||
'component', | ||
'directive', | ||
'filter' | ||
]; | ||
function forwardStaticMembers(Extended, Original, Super) { | ||
// We have to use getOwnPropertyNames since Babel registers methods as non-enumerable | ||
Object.getOwnPropertyNames(Original).forEach(function (key) { | ||
// `prototype` should not be overwritten | ||
if (key === 'prototype') { | ||
return; | ||
} | ||
var superDescriptor = Object.getOwnPropertyDescriptor(Super, key); | ||
if (!isPrimitive(descriptor.value) | ||
&& superDescriptor | ||
&& superDescriptor.value === descriptor.value) { | ||
// Some browsers does not allow reconfigure built-in properties | ||
var extendedDescriptor = Object.getOwnPropertyDescriptor(Extended, key); | ||
if (extendedDescriptor && !extendedDescriptor.configurable) { | ||
return; | ||
} | ||
var descriptor = Object.getOwnPropertyDescriptor(Original, key); | ||
// If the user agent does not support `__proto__` or its family (IE <= 10), | ||
// the sub class properties may be inherited properties from the super class in TypeScript. | ||
// We need to exclude such properties to prevent to overwrite | ||
// the component options object which stored on the extended constructor (See #192). | ||
// If the value is a referenced value (object or function), | ||
// we can check equality of them and exclude it if they have the same reference. | ||
// If it is a primitive value, it will be forwarded for safety. | ||
if (!hasProto) { | ||
// Only `cid` is explicitly exluded from property forwarding | ||
// because we cannot detect whether it is a inherited property or not | ||
// on the no `__proto__` environment even though the property is reserved. | ||
if (key === 'cid') { | ||
return; | ||
} | ||
var superDescriptor = Object.getOwnPropertyDescriptor(Super, key); | ||
if (!isPrimitive(descriptor.value) && | ||
superDescriptor && | ||
superDescriptor.value === descriptor.value) { | ||
return; | ||
} | ||
} | ||
// Warn if the users manually declare reserved properties | ||
if (reservedPropertyNames.indexOf(key) >= 0) { | ||
warn("Static property name '" + key + "' declared on class '" + Original.name + "' " + | ||
'conflicts with reserved property name of Vue internal. ' + | ||
'It may cause unexpected behavior of the component. Consider renaming the property.'); | ||
} | ||
Object.defineProperty(Extended, key, descriptor); | ||
}); | ||
} | ||
function Component(options) { | ||
if (typeof options === 'function') { | ||
return componentFactory(options); | ||
} | ||
// Warn if the users manually declare reserved properties | ||
if ("development" !== 'production' | ||
&& reservedPropertyNames.indexOf(key) >= 0) { | ||
warn("Static property name '" + key + "' declared on class '" + Original.name + "' " + | ||
'conflicts with reserved property name of Vue internal. ' + | ||
'It may cause unexpected behavior of the component. Consider renaming the property.'); | ||
} | ||
Object.defineProperty(Extended, key, descriptor); | ||
}); | ||
} | ||
function Component(options) { | ||
if (typeof options === 'function') { | ||
return componentFactory(options); | ||
return function (Component) { | ||
return componentFactory(Component, options); | ||
}; | ||
} | ||
return function (Component) { | ||
return componentFactory(Component, options); | ||
Component.registerHooks = function registerHooks(keys) { | ||
$internalHooks.push.apply($internalHooks, keys); | ||
}; | ||
} | ||
(function (Component) { | ||
function registerHooks(keys) { | ||
$internalHooks.push.apply($internalHooks, keys); | ||
} | ||
Component.registerHooks = registerHooks; | ||
})(Component || (Component = {})); | ||
var Component$1 = Component; | ||
exports.default = Component$1; | ||
exports.createDecorator = createDecorator; | ||
exports.mixins = mixins; | ||
exports.default = Component; | ||
exports.createDecorator = createDecorator; | ||
exports.mixins = mixins; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
/** | ||
* vue-class-component v6.2.0 | ||
* vue-class-component v6.3.0 | ||
* (c) 2015-present Evan You | ||
* @license MIT | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t(e.VueClassComponent={},e.Vue)}(this,function(e,t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var r={__proto__:[]}instanceof Array;var o=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured"];function n(e,n){void 0===n&&(n={}),n.name=n.name||e._componentTag||e.name;var i=e.prototype;Object.getOwnPropertyNames(i).forEach(function(e){if("constructor"!==e)if(o.indexOf(e)>-1)n[e]=i[e];else{var t=Object.getOwnPropertyDescriptor(i,e);"function"==typeof t.value?(n.methods||(n.methods={}))[e]=t.value:(t.get||t.set)&&((n.computed||(n.computed={}))[e]={get:t.get,set:t.set})}}),(n.mixins||(n.mixins=[])).push({data:function(){return function(e,t){var r=t.prototype._init;t.prototype._init=function(){var t=this,r=Object.getOwnPropertyNames(e);if(e.$options.props)for(var o in e.$options.props)e.hasOwnProperty(o)||r.push(o);r.forEach(function(r){"_"!==r.charAt(0)&&Object.defineProperty(t,r,{get:function(){return e[r]},set:function(t){return e[r]=t},configurable:!0})})};var o=new t;t.prototype._init=r;var n={};return Object.keys(o).forEach(function(e){void 0!==o[e]&&(n[e]=o[e])}),n}(this,e)}});var c=e.__decorators__;c&&(c.forEach(function(e){return e(n)}),delete e.__decorators__);var u,a,f,p=Object.getPrototypeOf(e.prototype),s=p instanceof t?p.constructor:t,d=s.extend(n);return u=d,a=e,f=s,Object.getOwnPropertyNames(a).forEach(function(e){if("prototype"!==e){var t=Object.getOwnPropertyDescriptor(u,e);if(!t||t.configurable){var o,n,i=Object.getOwnPropertyDescriptor(a,e);if(!r){if("cid"===e)return;var c=Object.getOwnPropertyDescriptor(f,e);if(o=i.value,n=typeof o,null!=o&&("object"===n||"function"===n)&&c&&c.value===i.value)return}Object.defineProperty(u,e,i)}}}),d}function i(e){return"function"==typeof e?n(e):function(t){return n(t,e)}}!function(e){(i||(i={})).registerHooks=function(e){o.push.apply(o,e)}}();var c=i;e.default=c,e.createDecorator=function(e){return function(t,r,o){var n="function"==typeof t?t:t.constructor;n.__decorators__||(n.__decorators__=[]),"number"!=typeof o&&(o=void 0),n.__decorators__.push(function(t){return e(t,r,o)})}},e.mixins=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.extend({mixins:e})},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t(e.VueClassComponent={},e.Vue)}(this,function(e,d){"use strict";function y(r,o,n){(n?Reflect.getOwnMetadataKeys(o,n):Reflect.getOwnMetadataKeys(o)).forEach(function(e){var t=n?Reflect.getOwnMetadata(e,o,n):Reflect.getOwnMetadata(e,o);n?Reflect.defineMetadata(e,t,r,n):Reflect.defineMetadata(e,t,r)})}d=d&&d.hasOwnProperty("default")?d.default:d;var v={__proto__:[]}instanceof Array;var O=["data","beforeCreate","created","beforeMount","mounted","beforeDestroy","destroyed","beforeUpdate","updated","activated","deactivated","render","errorCaptured"];function r(e,o){void 0===o&&(o={}),o.name=o.name||e._componentTag||e.name;var n=e.prototype;Object.getOwnPropertyNames(n).forEach(function(t){if("constructor"!==t)if(-1<O.indexOf(t))o[t]=n[t];else{var r=Object.getOwnPropertyDescriptor(n,t);void 0!==r.value?"function"==typeof r.value?(o.methods||(o.methods={}))[t]=r.value:(o.mixins||(o.mixins=[])).push({data:function(){var e;return(e={})[t]=r.value,e}}):(r.get||r.set)&&((o.computed||(o.computed={}))[t]={get:r.get,set:r.set})}}),(o.mixins||(o.mixins=[])).push({data:function(){return function(o,e){var t=e.prototype._init;e.prototype._init=function(){var e=this,t=Object.getOwnPropertyNames(o);if(o.$options.props)for(var r in o.$options.props)o.hasOwnProperty(r)||t.push(r);t.forEach(function(t){"_"!==t.charAt(0)&&Object.defineProperty(e,t,{get:function(){return o[t]},set:function(e){o[t]=e},configurable:!0})})};var r=new e;e.prototype._init=t;var n={};return Object.keys(r).forEach(function(e){void 0!==r[e]&&(n[e]=r[e])}),n}(this,e)}});var t=e.__decorators__;t&&(t.forEach(function(e){return e(o)}),delete e.__decorators__);var c,i,f,r,a,u=Object.getPrototypeOf(e.prototype),p=u instanceof d?u.constructor:d,s=p.extend(o);return c=s,i=e,f=p,Object.getOwnPropertyNames(i).forEach(function(e){if("prototype"!==e){var t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.configurable){var r,o,n=Object.getOwnPropertyDescriptor(i,e);if(!v){if("cid"===e)return;var a=Object.getOwnPropertyDescriptor(f,e);if(r=n.value,o=typeof r,null!=r&&("object"===o||"function"===o)&&a&&a.value===n.value)return}Object.defineProperty(c,e,n)}}}),void 0!==(Reflect&&Reflect.defineMetadata)&&(y(r=s,a=e),Object.getOwnPropertyNames(a.prototype).forEach(function(e){y(r.prototype,a.prototype,e)}),Object.getOwnPropertyNames(a).forEach(function(e){y(r,a,e)})),s}function t(t){return"function"==typeof t?r(t):function(e){return r(e,t)}}t.registerHooks=function(e){O.push.apply(O,e)},e.default=t,e.createDecorator=function(n){return function(e,t,r){var o="function"==typeof e?e:e.constructor;o.__decorators__||(o.__decorators__=[]),"number"!=typeof r&&(r=void 0),o.__decorators__.push(function(e){return n(e,t,r)})}},e.mixins=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return d.extend({mixins:e})},Object.defineProperty(e,"__esModule",{value:!0})}); |
import Vue from 'vue'; | ||
import { copyReflectionMetadata, reflectionIsSupported } from './reflect'; | ||
import { collectDataFromConstructor } from './data'; | ||
@@ -34,5 +35,16 @@ import { hasProto, isPrimitive, warn } from './util'; | ||
var descriptor = Object.getOwnPropertyDescriptor(proto, key); | ||
if (typeof descriptor.value === 'function') { | ||
if (descriptor.value !== void 0) { | ||
// methods | ||
(options.methods || (options.methods = {}))[key] = descriptor.value; | ||
if (typeof descriptor.value === 'function') { | ||
(options.methods || (options.methods = {}))[key] = descriptor.value; | ||
} | ||
else { | ||
// typescript decorated data | ||
(options.mixins || (options.mixins = [])).push({ | ||
data: function () { | ||
var _a; | ||
return _a = {}, _a[key] = descriptor.value, _a; | ||
} | ||
}); | ||
} | ||
} | ||
@@ -65,2 +77,5 @@ else if (descriptor.get || descriptor.set) { | ||
forwardStaticMembers(Extended, Component, Super); | ||
if (reflectionIsSupported()) { | ||
copyReflectionMetadata(Extended, Component); | ||
} | ||
return Extended; | ||
@@ -111,5 +126,5 @@ } | ||
var superDescriptor = Object.getOwnPropertyDescriptor(Super, key); | ||
if (!isPrimitive(descriptor.value) | ||
&& superDescriptor | ||
&& superDescriptor.value === descriptor.value) { | ||
if (!isPrimitive(descriptor.value) && | ||
superDescriptor && | ||
superDescriptor.value === descriptor.value) { | ||
return; | ||
@@ -119,4 +134,4 @@ } | ||
// Warn if the users manually declare reserved properties | ||
if (process.env.NODE_ENV !== 'production' | ||
&& reservedPropertyNames.indexOf(key) >= 0) { | ||
if (process.env.NODE_ENV !== 'production' && | ||
reservedPropertyNames.indexOf(key) >= 0) { | ||
warn("Static property name '" + key + "' declared on class '" + Original.name + "' " + | ||
@@ -123,0 +138,0 @@ 'conflicts with reserved property name of Vue internal. ' + |
@@ -22,3 +22,3 @@ import Vue from 'vue'; | ||
get: function () { return vm[key]; }, | ||
set: function (value) { return vm[key] = value; }, | ||
set: function (value) { vm[key] = value; }, | ||
configurable: true | ||
@@ -25,0 +25,0 @@ }); |
@@ -5,6 +5,9 @@ import Vue, { ComponentOptions } from 'vue'; | ||
declare function Component<V extends Vue>(options: ComponentOptions<V> & ThisType<V>): <VC extends VueClass<V>>(target: VC) => VC; | ||
declare namespace Component { | ||
var registerHooks: (keys: string[]) => void; | ||
} | ||
declare function Component<VC extends VueClass<Vue>>(target: VC): VC; | ||
declare namespace Component { | ||
function registerHooks(keys: string[]): void; | ||
var registerHooks: (keys: string[]) => void; | ||
} | ||
export default Component; |
@@ -11,8 +11,5 @@ import { componentFactory, $internalHooks } from './component'; | ||
} | ||
(function (Component) { | ||
function registerHooks(keys) { | ||
$internalHooks.push.apply($internalHooks, keys); | ||
} | ||
Component.registerHooks = registerHooks; | ||
})(Component || (Component = {})); | ||
Component.registerHooks = function registerHooks(keys) { | ||
$internalHooks.push.apply($internalHooks, keys); | ||
}; | ||
export default Component; |
import Vue from 'vue'; | ||
export var noop = function () { }; | ||
export var hasProto = { __proto__: [] } instanceof Array; | ||
var fakeArray = { __proto__: [] }; | ||
export var hasProto = fakeArray instanceof Array; | ||
export function createDecorator(factory) { | ||
@@ -27,3 +28,3 @@ return function (target, key, index) { | ||
var type = typeof value; | ||
return value == null || (type !== "object" && type !== "function"); | ||
return value == null || (type !== 'object' && type !== 'function'); | ||
} | ||
@@ -30,0 +31,0 @@ export function warn(message) { |
{ | ||
"name": "vue-class-component", | ||
"version": "6.2.0", | ||
"version": "6.3.0", | ||
"description": "ES201X/TypeScript class decorator for Vue components", | ||
@@ -19,2 +19,3 @@ "main": "dist/vue-class-component.common.js", | ||
"dev:test": "node build/dev-test.js", | ||
"lint": "eslint --ext js,jsx,ts,tsx,vue .", | ||
"test": "npm run build && webpack --config test/webpack.config.js && mocha test/test.build.js", | ||
@@ -40,27 +41,33 @@ "release": "bash build/release.sh" | ||
"devDependencies": { | ||
"@babel/core": "^7.1.2", | ||
"@babel/plugin-proposal-class-properties": "^7.1.0", | ||
"@babel/plugin-proposal-decorators": "^7.1.2", | ||
"@babel/plugin-syntax-jsx": "^7.0.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"@types/chai": "^4.1.2", | ||
"@types/mocha": "^2.2.48", | ||
"babel-core": "^6.26.0", | ||
"@types/mocha": "^5.2.5", | ||
"babel-helper-vue-jsx-merge-props": "^2.0.3", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-syntax-jsx": "^6.18.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-plugin-transform-vue-jsx": "^3.5.1", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-loader": "^8.0.4", | ||
"babel-plugin-transform-vue-jsx": "^4.0.1", | ||
"chai": "^4.1.2", | ||
"css-loader": "^0.28.9", | ||
"css-loader": "^1.0.0", | ||
"eslint": "^5.7.0", | ||
"eslint-plugin-vue-libs": "^3.0.0", | ||
"mocha": "^5.0.1", | ||
"reflect-metadata": "^0.1.12", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.55.5", | ||
"rollup": "^0.66.5", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"testdouble": "^3.5.0", | ||
"ts-loader": "^3.5.0", | ||
"typescript": "^2.7.1", | ||
"ts-loader": "^5.2.1", | ||
"typescript": "^3.1.1", | ||
"typescript-eslint-parser": "^20.0.0", | ||
"uglify-js": "^3.3.10", | ||
"vue": "^2.5.13", | ||
"vue-loader": "^14.1.1", | ||
"vue-loader": "^15.4.2", | ||
"vue-template-compiler": "^2.5.13", | ||
"webpack": "^3.11.0" | ||
"vuex": "^3.0.1", | ||
"webpack": "^4.20.2", | ||
"webpack-cli": "^3.1.2" | ||
} | ||
} |
@@ -29,3 +29,3 @@ # vue-class-component | ||
Following is the example written in Babel. If you are looking for TypeScript version, [it's in the example directory](example/App.vue). | ||
Following is the example written in Babel. If you are looking for TypeScript version, [it's in the example directory](example/src/App.vue). | ||
@@ -173,8 +173,10 @@ ``` vue | ||
// and beforeRouteLeave as Vue Router hooks | ||
beforeRouteEnter () { | ||
beforeRouteEnter (to, from, next) { | ||
console.log('beforeRouteEnter') | ||
next() // needs to be called to confirm the navigation | ||
} | ||
beforeRouteLeave () { | ||
beforeRouteLeave (to, from, next) { | ||
console.log('beforeRouteLeave') | ||
next() // needs to be called to confirm the navigation | ||
} | ||
@@ -181,0 +183,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46075
18
841
273
30