UNPKG

@smyld/vue-property-decorator

Version:

SMYLD Fork version of vue-property-decorator to port the latest version of vue-class-component

28 lines (27 loc) 1.09 kB
import { createDecorator } from 'vue-class-component'; //import { Constructor } from 'vue/types/options' import { applyMetadata } from '../helpers/metadata'; /** * decorator of a synced prop * @param propName the name to interface with from outside, must be different from decorated property * @param options the options for the synced prop * @return PropertyDecorator | void */ export function PropSync(propName, options) { if (options === void 0) { options = {}; } return function (target, key) { applyMetadata(options, target, key); createDecorator(function (componentOptions, k) { ; (componentOptions.props || (componentOptions.props = {}))[propName] = options; (componentOptions.computed || (componentOptions.computed = {}))[k] = { get: function () { return this[propName]; }, set: function (value) { this.$emit("update:" + propName, value); }, }; })(target, key); }; }