Socket
Socket
Sign inDemoInstall

vue-property-decorator

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-property-decorator - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

8

lib/vue-property-decorator.d.ts
import Vue = require('vue');
import { PropOptions } from 'vue';
import VueClassComponent from 'vue-class-component';
import 'reflect-metadata';
export declare type Constructor = {

@@ -9,6 +10,7 @@ new (...args: any[]): any;

* decorator of a prop
* @param options the option for the prop
* @return PropertyDecorator
* @param options the options for the prop
* @return PropertyDecorator | void
*/
export declare function Prop(options?: (PropOptions | Constructor | Constructor[])): PropertyDecorator;
export declare function Prop(target: Vue, key: string): void;
export declare function Prop(target?: (PropOptions | Constructor[])): PropertyDecorator;
/**

@@ -15,0 +17,0 @@ * decorator of a watch function

@@ -1,15 +0,35 @@

/* vue-property-decorator verson 3.3.0 MIT LICENSE copyright 2016 kaorun343 */
/* vue-property-decorator verson 3.4.0 MIT LICENSE copyright 2016 kaorun343 */
'use strict';
var Vue = require("vue");
var vue_class_component_1 = require("vue-class-component");
require("reflect-metadata");
/**
* decorator of a prop
* @param options the option for the prop
* @brief Makes a decorator for prop.
*
* @param options The options
* @param target The target
* @param key The key
*
* @return PropertyDecorator
*/
function Prop(options) {
if (options === void 0) { options = { type: null }; }
return vue_class_component_1.createDecorator(function (componentOptions, key) {
(componentOptions.props || (componentOptions.props = {}))[key] = options;
});
function makePropDecorator(options) {
if (options === void 0) { options = {}; }
return function (target, key) {
if (!(options instanceof Array) && typeof options.type === 'undefined') {
options.type = Reflect.getMetadata('design:type', target, key);
}
vue_class_component_1.createDecorator(function (componentOptions, k) {
(componentOptions.props || (componentOptions.props = {}))[k] = options;
})(target, key);
};
}
function Prop(options, key) {
if (options === void 0) { options = {}; }
if (options instanceof Vue) {
return makePropDecorator()(options, key);
}
else {
return makePropDecorator(options);
}
}
exports.Prop = Prop;

@@ -16,0 +36,0 @@ /**

{
"name": "vue-property-decorator",
"version": "3.3.0",
"version": "3.4.0",
"description": "property decorators for Vue Component",

@@ -5,0 +5,0 @@ "main": "lib/vue-property-decorator.js",

@@ -22,12 +22,11 @@ # Vue Property Decorator

```typescript
import * as Vue from 'vue'
import Component from 'vue-class-component'
import { Prop, Watch } from 'vue-property-decorator'
import Vue = require('vue')
import { Component Prop, Watch } from 'vue-property-decorator'
@Component
export class Component extends Vue {
@Prop(Number)
@Prop
propA: number
@Prop({ type: String, default: 'default value' })
@Prop({ default: 'default value' })
propB: string

@@ -38,3 +37,3 @@

@Prop()
@Prop({ type: null })
propD: any

@@ -84,38 +83,6 @@

Also, there are altanative `@Prop` which adds `PropOptions.type` automatically.
This decorator internally uses decorator metadata.
Please set `emitDecoratorMetadata` to `true`
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. Also this library needs to have `emitDecoratorMetadata` set to `true` for this to work.
```typescript
import * as Vue from 'vue'
import Component from 'vue-class-component'
import { Prop, Watch } from 'vue-property-decorator/lib/metadata'
@Component
export class Component extends Vue {
@Prop()
propA: number
@Prop({ default: 'default value' })
propB: string
// when union types, please add its types manually
@Prop([String, Boolean])
propC: string | boolean
// when `any`, please set like this manually
@Prop({ type: null })
propD: any
@Watch('child')
onChildChanged(val: string, oldVal: string) { }
@Watch('person', { immediate: true, deep: true })
onPersonChanged(val: Person, oldVal: Person) { }
}
```
## See also
[vuex-class](https://github.com/ktsn/vuex-class/)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc