vue-property-decorator
Advanced tools
Comparing version 5.3.0 to 6.0.0
@@ -7,2 +7,3 @@ import Vue, { PropOptions, WatchOptions } from 'vue'; | ||
}; | ||
export { Component, Vue }; | ||
/** | ||
@@ -45,2 +46,1 @@ * decorator of an inject | ||
export declare function Emit(event?: string): MethodDecorator; | ||
export { Component, Vue }; |
@@ -1,2 +0,2 @@ | ||
/** vue-property-decorator verson 5.3.0 MIT LICENSE copyright 2017 kaorun343 */ | ||
/** vue-property-decorator verson 6.0.0 MIT LICENSE copyright 2017 kaorun343 */ | ||
'use strict'; | ||
@@ -6,2 +6,3 @@ import Vue from 'vue'; | ||
import 'reflect-metadata'; | ||
export { Component, Vue }; | ||
/** | ||
@@ -92,10 +93,5 @@ * decorator of an inject | ||
} | ||
// Code copy-pasted from Vue/packages/vue-server-renderer/build.js | ||
var hyphenateRE = /([^-])([A-Z])/g; | ||
var hyphenate = function (str) { | ||
return str | ||
.replace(hyphenateRE, '$1-$2') | ||
.replace(hyphenateRE, '$1-$2') | ||
.toLowerCase(); | ||
}; | ||
// Code copied from Vue/src/shared/util.js | ||
var hyphenateRE = /\B([A-Z])/g; | ||
var hyphenate = function (str) { return str.replace(hyphenateRE, '-$1').toLowerCase(); }; | ||
/** | ||
@@ -115,3 +111,3 @@ * decorator of an event-emitter function | ||
} | ||
if (false !== original.apply(this, args)) | ||
if (original.apply(this, args) !== false) | ||
this.$emit.apply(this, [event || key].concat(args)); | ||
@@ -121,2 +117,1 @@ }; | ||
} | ||
export { Component, Vue }; |
@@ -10,3 +10,4 @@ (function (global, factory) { | ||
/** vue-property-decorator verson 5.3.0 MIT LICENSE copyright 2017 kaorun343 */ | ||
/** vue-property-decorator verson 6.0.0 MIT LICENSE copyright 2017 kaorun343 */ | ||
'use strict'; | ||
/** | ||
@@ -53,6 +54,13 @@ * decorator of an inject | ||
*/ | ||
function Model(event) { | ||
return vueClassComponent.createDecorator(function (componentOptions, prop) { | ||
componentOptions.model = { prop: prop, event: event || prop }; | ||
}); | ||
function Model(event, options) { | ||
if (options === void 0) { options = {}; } | ||
return function (target, key) { | ||
if (!Array.isArray(options) && typeof options.type === 'undefined') { | ||
options.type = Reflect.getMetadata('design:type', target, key); | ||
} | ||
vueClassComponent.createDecorator(function (componentOptions, k) { | ||
(componentOptions.props || (componentOptions.props = {}))[k] = options; | ||
componentOptions.model = { prop: k, event: event || k }; | ||
})(target, key); | ||
}; | ||
} | ||
@@ -91,3 +99,27 @@ /** | ||
} | ||
// Code copied from Vue/src/shared/util.js | ||
var hyphenateRE = /\B([A-Z])/g; | ||
var hyphenate = function (str) { return str.replace(hyphenateRE, '-$1').toLowerCase(); }; | ||
/** | ||
* decorator of an event-emitter function | ||
* @param event The name of the event | ||
* @return MethodDecorator | ||
*/ | ||
function Emit(event) { | ||
return function (target, key, descriptor) { | ||
key = hyphenate(key); | ||
var original = descriptor.value; | ||
descriptor.value = function emitter() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
if (original.apply(this, args) !== false) | ||
this.$emit.apply(this, [event || key].concat(args)); | ||
}; | ||
}; | ||
} | ||
exports.Component = vueClassComponent__default; | ||
exports.Vue = vue; | ||
exports.Inject = Inject; | ||
@@ -98,4 +130,3 @@ exports.Provide = Provide; | ||
exports.Watch = Watch; | ||
exports.Component = vueClassComponent__default; | ||
exports.Vue = vue; | ||
exports.Emit = Emit; | ||
@@ -102,0 +133,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
{ | ||
"name": "vue-property-decorator", | ||
"version": "5.3.0", | ||
"version": "6.0.0", | ||
"description": "property decorators for Vue Component", | ||
@@ -19,3 +19,3 @@ "main": "lib/vue-property-decorator.umd.js", | ||
"build:umd": "rollup -c", | ||
"test": "tsc -p test/tsconfig.json && ava test/decorator.spec.js" | ||
"test": "rollup -c test/rollup.config.js && ava test/decorator.spec.js" | ||
}, | ||
@@ -26,12 +26,14 @@ "files": [ | ||
"devDependencies": { | ||
"@types/node": "^7.0.5", | ||
"ava": "^0.19.1", | ||
"rollup": "^0.45.2", | ||
"typescript": "^2.4.1", | ||
"vue": "^2.2.1" | ||
"@types/node": "^8.0.34", | ||
"ava": "^0.22.0", | ||
"rollup": "^0.50.0", | ||
"rollup-plugin-commonjs": "^8.2.1", | ||
"rollup-plugin-typescript": "^0.8.1", | ||
"typescript": "^2.5.3", | ||
"vue": "^2.5.0" | ||
}, | ||
"typings": "./lib/vue-property-decorator.d.ts", | ||
"dependencies": { | ||
"reflect-metadata": "^0.1.9", | ||
"vue-class-component": "^5.0.0" | ||
"reflect-metadata": "^0.1.10", | ||
"vue-class-component": "^6.0.0" | ||
}, | ||
@@ -38,0 +40,0 @@ "repository": { |
@@ -19,4 +19,5 @@ # Vue Property Decorator | ||
There are 6 decorators: | ||
There are 7 decorators: | ||
* `@Emit` | ||
* `@Inject` | ||
@@ -30,3 +31,3 @@ * `@Model` | ||
```typescript | ||
import { Component, Inject, Model, Prop, Vue, Watch } from 'vue-property-decorator' | ||
import { Component, Emit, Inject, Model, Prop, Provide, Vue, Watch } from 'vue-property-decorator' | ||
@@ -38,2 +39,8 @@ const s = Symbol('baz') | ||
@Emit() | ||
addToCount(n: number){ this.count += n } | ||
@Emit('reset') | ||
resetCount(){ this.count = 0 } | ||
@Inject() foo: string | ||
@@ -54,5 +61,2 @@ @Inject('bar') bar: string | ||
@Prop({ type: null }) | ||
propD: any | ||
@Provide() foo = 'foo' | ||
@@ -94,3 +98,2 @@ @Provide('bar') baz = 'bar' | ||
propC: [String, Boolean], | ||
propD: { type: null } | ||
}, | ||
@@ -108,4 +111,12 @@ data () { | ||
} | ||
} | ||
}, | ||
methods: { | ||
addToCount(n){ | ||
this.count += n | ||
this.$emit("add-to-count", n) | ||
}, | ||
resetCount(){ | ||
this.count = 0 | ||
this.$emit("reset") | ||
}, | ||
onChildChanged(val, oldVal) { }, | ||
@@ -129,2 +140,4 @@ onPersonChanged(val, oldVal) { } | ||
## emitDecoratorMetadata | ||
As you can see at `propA` and `propB`, the type can be inferred automatically when it's a simple type. For more complex types like enums you do need to specify it specifically. | ||
@@ -131,0 +144,0 @@ Also this library needs to have `emitDecoratorMetadata` set to `true` for this to work. |
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
15121
283
142
7
+ Addedvue-class-component@6.3.2(transitive)
- Removedvue-class-component@5.0.2(transitive)
Updatedreflect-metadata@^0.1.10
Updatedvue-class-component@^6.0.0