From f60366f51e5ab7cbe54dd24d2a79607a417fd7bd Mon Sep 17 00:00:00 2001 From: Huseyn Guliyev Date: Thu, 17 Oct 2019 16:04:28 +0100 Subject: [PATCH] Reformatted code and added missing exports --- fixtures/emit.ts | 26 +++++--- fixtures/inject.ts | 28 +++++--- fixtures/model.ts | 14 ++-- lib/nuxt-property-decorator.d.ts | 92 ++++++++++++++++---------- lib/nuxt-property-decorator.umd.js | 52 ++++++++------- rollup.config.js | 44 +++++++------ src/nuxt-property-decorator.ts | 100 ++++++++++++++++++----------- tsconfig.json | 22 ++----- 8 files changed, 221 insertions(+), 157 deletions(-) diff --git a/fixtures/emit.ts b/fixtures/emit.ts index 990b002..bd622e7 100644 --- a/fixtures/emit.ts +++ b/fixtures/emit.ts @@ -1,23 +1,31 @@ -import Vue, { VNode } from 'vue'; -import { Component, Emit, Inject, Model, Prop, Provide, Watch } from '../src/nuxt-property-decorator'; +import Vue, { VNode } from "vue" +import { + Component, + Emit, + Inject, + Model, + Prop, + Provide, + Watch +} from "../src/nuxt-property-decorator" @Component export default class EmitFixture extends Vue { - count = 0; + count = 0 - @Emit('reset') resetCount() { - this.count = 0; + @Emit("reset") resetCount() { + this.count = 0 } @Emit() increment(n: number) { - this.count += n; + this.count += n } @Emit() canceled() { - return false; + return false } - render (createElement: any): VNode { - return createElement('div'); + render(createElement: any): VNode { + return createElement("div") } } diff --git a/fixtures/inject.ts b/fixtures/inject.ts index f28a3a7..6827270 100644 --- a/fixtures/inject.ts +++ b/fixtures/inject.ts @@ -1,18 +1,26 @@ -import Vue, { VNode } from 'vue'; -import { Component, Emit, Inject, Model, Prop, Provide, Watch } from '../src/nuxt-property-decorator'; +import Vue, { VNode } from "vue" +import { + Component, + Emit, + Inject, + Model, + Prop, + Provide, + Watch +} from "../src/nuxt-property-decorator" const s = Symbol() @Component({ provide() { return { - [s]: 'one', - bar: 'two' + [s]: "one", + bar: "two" } } }) export class Parent extends Vue { - render (createElement: any): VNode { - return createElement('div'); + render(createElement: any): VNode { + return createElement("div") } } @@ -20,8 +28,8 @@ export class Parent extends Vue { export class Child extends Vue { @Inject(s) foo: string @Inject() bar: string - render (createElement: any): VNode { - return createElement('div'); + render(createElement: any): VNode { + return createElement("div") } } @@ -29,7 +37,7 @@ export class Child extends Vue { export class GrandChild extends Vue { @Inject(s) foo: string @Inject() bar: string - render (createElement: any): VNode { - return createElement('div'); + render(createElement: any): VNode { + return createElement("div") } } diff --git a/fixtures/model.ts b/fixtures/model.ts index e1ef316..8a1aec9 100644 --- a/fixtures/model.ts +++ b/fixtures/model.ts @@ -1,13 +1,13 @@ -import Vue, { VNode } from 'vue'; -import { Component, Model } from '../src/nuxt-property-decorator'; +import Vue, { VNode } from "vue" +import { Component, Model } from "../src/nuxt-property-decorator" @Component({ - name: 'test' + name: "test" }) export default class ModelFixture extends Vue { - @Model('change') - checked: boolean; - render (createElement: any): VNode { - return createElement('div'); + @Model("change") + checked: boolean + render(createElement: any): VNode { + return createElement("div") } } diff --git a/lib/nuxt-property-decorator.d.ts b/lib/nuxt-property-decorator.d.ts index ed3591e..6130d0b 100644 --- a/lib/nuxt-property-decorator.d.ts +++ b/lib/nuxt-property-decorator.d.ts @@ -1,33 +1,59 @@ -import Vue from 'vue'; -import { /*Component,*/ Emit, Inject, Model, Prop, PropSync, Provide, Watch } from "vue-property-decorator"; -import Component, { mixins } from 'vue-class-component'; -import 'reflect-metadata'; -export declare type Constructor = { - new (...args: any[]): any; -}; -/** - * decorator of $off - * @param event The name of the event - * @param method The name of the method - */ -export declare function Off(event?: string, method?: string): MethodDecorator; -/** - * decorator of $on - * @param event The name of the event - */ -export declare function On(event?: string): MethodDecorator; -/** - * decorator of $once - * @param event The name of the event - */ -export declare function Once(event?: string): MethodDecorator; -/** - * decorator of $nextTick - * - * @export - * @param {string} method - * @returns {MethodDecorator} - */ -export declare function NextTick(method: string): MethodDecorator; -import { State, Getter, Action, Mutation, namespace } from 'vuex-class'; -export { Vue, Component, Emit, Inject, Model, Prop, PropSync, Provide, Watch, mixins, State, Getter, Action, Mutation, namespace }; +import Vue from "vue" +import { + /*Component,*/ Emit, + Inject, + Model, + Prop, + PropSync, + Provide, + Ref, + Watch +} from "vue-property-decorator" +import Component, { mixins } from "vue-class-component" +import "reflect-metadata" +export declare type Constructor = { + new (...args: any[]): any +} +/** + * decorator of $off + * @param event The name of the event + * @param method The name of the method + */ +export declare function Off(event?: string, method?: string): MethodDecorator +/** + * decorator of $on + * @param event The name of the event + */ +export declare function On(event?: string): MethodDecorator +/** + * decorator of $once + * @param event The name of the event + */ +export declare function Once(event?: string): MethodDecorator +/** + * decorator of $nextTick + * + * @export + * @param {string} method + * @returns {MethodDecorator} + */ +export declare function NextTick(method: string): MethodDecorator +import { State, Getter, Action, Mutation, namespace } from "vuex-class" +export { + Vue, + Component, + Emit, + Inject, + Model, + Prop, + PropSync, + Provide, + Ref, + Watch, + mixins, + State, + Getter, + Action, + Mutation, + namespace +} diff --git a/lib/nuxt-property-decorator.umd.js b/lib/nuxt-property-decorator.umd.js index 2d93889..dde15d9 100644 --- a/lib/nuxt-property-decorator.umd.js +++ b/lib/nuxt-property-decorator.umd.js @@ -8,24 +8,24 @@ var Component__default = 'default' in Component ? Component['default'] : Component; Component__default.registerHooks([ - 'beforeRouteEnter', - 'beforeRouteUpdate', - 'beforeRouteLeave', - 'asyncData', - 'fetch', - 'head', - 'key', - 'layout', - 'loading', - 'middleware', - 'scrollToTop', - 'transition', - 'validate', - 'watchQuery' + "beforeRouteEnter", + "beforeRouteUpdate", + "beforeRouteLeave", + "asyncData", + "fetch", + "head", + "key", + "layout", + "loading", + "middleware", + "scrollToTop", + "transition", + "validate", + "watchQuery" ]); // Code copied from Vue/src/shared/util.js var hyphenateRE = /\B([A-Z])/g; - var hyphenate = function (str) { return str.replace(hyphenateRE, '-$1').toLowerCase(); }; + var hyphenate = function (str) { return str.replace(hyphenateRE, "-$1").toLowerCase(); }; /** * decorator of $off * @param event The name of the event @@ -42,11 +42,11 @@ } if (original.apply(this, args) !== false) { if (method) { - if (typeof this[method] === 'function') { + if (typeof this[method] === "function") { this.$off(event || key, this[method]); } else { - throw new TypeError('must be a method name'); + throw new TypeError("must be a method name"); } } else if (event) { @@ -66,13 +66,13 @@ function On(event) { return Component.createDecorator(function (componentOptions, k) { var key = hyphenate(k); - if (typeof componentOptions.created !== 'function') { + if (typeof componentOptions.created !== "function") { componentOptions.created = function () { }; } var original = componentOptions.created; componentOptions.created = function () { original(); - if (typeof componentOptions.methods !== 'undefined') { + if (typeof componentOptions.methods !== "undefined") { this.$on(event || key, componentOptions.methods[k]); } }; @@ -85,13 +85,13 @@ function Once(event) { return Component.createDecorator(function (componentOptions, k) { var key = hyphenate(k); - if (typeof componentOptions.created !== 'function') { + if (typeof componentOptions.created !== "function") { componentOptions.created = function () { }; } var original = componentOptions.created; componentOptions.created = function () { original(); - if (typeof componentOptions.methods !== 'undefined') { + if (typeof componentOptions.methods !== "undefined") { this.$once(event || key, componentOptions.methods[k]); } }; @@ -113,11 +113,11 @@ args[_i] = arguments[_i]; } if (original.apply(this, args) !== false) - if (typeof this[method] === 'function') { + if (typeof this[method] === "function") { this.$nextTick(this[method]); } else { - throw new TypeError('must be a method name'); + throw new TypeError("must be a method name"); } }; }; @@ -160,6 +160,12 @@ return vuePropertyDecorator.Provide; } }); + Object.defineProperty(exports, 'Ref', { + enumerable: true, + get: function () { + return vuePropertyDecorator.Ref; + } + }); Object.defineProperty(exports, 'Watch', { enumerable: true, get: function () { diff --git a/rollup.config.js b/rollup.config.js index 218e737..5c35c6d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,24 +1,28 @@ -import typescript from 'rollup-plugin-typescript2'; +import typescript from "rollup-plugin-typescript2" export default { - input: './src/nuxt-property-decorator.ts', - plugins: [ - typescript({ - tsconfig: './tsconfig.json' + input: "./src/nuxt-property-decorator.ts", + plugins: [ + typescript({ + tsconfig: "./tsconfig.json" }) - ], - output:{ - format: 'umd', - name: 'NuxtPropertyDecorator', - file: 'lib/nuxt-property-decorator.umd.js', - globals: { - 'vue': 'Vue', - 'vuex-class': 'VuexClass', - 'vue-class-component': 'VueClassComponent', - 'vue-property-decorator': 'VuePropertyDecorator' - } - }, - external: [ - 'vue', 'vuex-class', 'vue-property-decorator', 'vue-class-component', 'reflect-metadata' - ] + ], + output: { + format: "umd", + name: "NuxtPropertyDecorator", + file: "lib/nuxt-property-decorator.umd.js", + globals: { + vue: "Vue", + "vuex-class": "VuexClass", + "vue-class-component": "VueClassComponent", + "vue-property-decorator": "VuePropertyDecorator" + } + }, + external: [ + "vue", + "vuex-class", + "vue-property-decorator", + "vue-class-component", + "reflect-metadata" + ] } diff --git a/src/nuxt-property-decorator.ts b/src/nuxt-property-decorator.ts index b1babc7..49f7132 100644 --- a/src/nuxt-property-decorator.ts +++ b/src/nuxt-property-decorator.ts @@ -1,24 +1,33 @@ -'use strict' +"use strict" -import Vue, { PropOptions, WatchOptions } from 'vue' -import { /*Component,*/ Emit, Inject, Model, Prop, PropSync, Provide, Watch, Ref /*, Vue, Mixins */ } from "vue-property-decorator" -import Component, { createDecorator, mixins } from 'vue-class-component' +import Vue, { PropOptions, WatchOptions } from "vue" +import { + /*Component,*/ Emit, + Inject, + Model, + Prop, + PropSync, + Provide, + Ref, + Watch /*, Vue, Mixins */ +} from "vue-property-decorator" +import Component, { createDecorator, mixins } from "vue-class-component" Component.registerHooks([ - 'beforeRouteEnter', - 'beforeRouteUpdate', - 'beforeRouteLeave', - 'asyncData', - 'fetch', - 'head', - 'key', - 'layout', - 'loading', - 'middleware', - 'scrollToTop', - 'transition', - 'validate', - 'watchQuery' + "beforeRouteEnter", + "beforeRouteUpdate", + "beforeRouteLeave", + "asyncData", + "fetch", + "head", + "key", + "layout", + "loading", + "middleware", + "scrollToTop", + "transition", + "validate", + "watchQuery" ]) // const Component = require('nuxt-class-component'); @@ -30,8 +39,7 @@ export type Constructor = { // Code copied from Vue/src/shared/util.js const hyphenateRE = /\B([A-Z])/g -const hyphenate = (str: string) => str.replace(hyphenateRE, '-$1').toLowerCase() - +const hyphenate = (str: string) => str.replace(hyphenateRE, "-$1").toLowerCase() /** * decorator of $off @@ -39,16 +47,16 @@ const hyphenate = (str: string) => str.replace(hyphenateRE, '-$1').toLowerCase() * @param method The name of the method */ export function Off(event?: string, method?: string): MethodDecorator { - return function (target: Vue, key: string, descriptor: any) { + return function(target: Vue, key: string, descriptor: any) { key = hyphenate(key) const original = descriptor.value descriptor.value = function offer(...args: any[]) { if (original.apply(this, args) !== false) { if (method) { - if (typeof this[method] === 'function') { + if (typeof this[method] === "function") { this.$off(event || key, this[method]) } else { - throw new TypeError('must be a method name') + throw new TypeError("must be a method name") } } else if (event) { this.$off(event || key) @@ -67,16 +75,15 @@ export function Off(event?: string, method?: string): MethodDecorator { export function On(event?: string): MethodDecorator { return createDecorator((componentOptions, k) => { const key = hyphenate(k) - if (typeof componentOptions.created !== 'function') { - componentOptions.created = function () { } + if (typeof componentOptions.created !== "function") { + componentOptions.created = function() {} } const original = componentOptions.created - componentOptions.created = function () { + componentOptions.created = function() { original() - if (typeof componentOptions.methods !== 'undefined') { + if (typeof componentOptions.methods !== "undefined") { this.$on(event || key, componentOptions.methods[k]) } - } }) } @@ -88,14 +95,14 @@ export function On(event?: string): MethodDecorator { export function Once(event?: string): MethodDecorator { return createDecorator((componentOptions, k) => { const key = hyphenate(k) - if (typeof componentOptions.created !== 'function') { - componentOptions.created = function () { } + if (typeof componentOptions.created !== "function") { + componentOptions.created = function() {} } const original = componentOptions.created - componentOptions.created = function () { + componentOptions.created = function() { original() - if (typeof componentOptions.methods !== 'undefined') { - this.$once(event || key, componentOptions.methods[k]); + if (typeof componentOptions.methods !== "undefined") { + this.$once(event || key, componentOptions.methods[k]) } } }) @@ -109,18 +116,35 @@ export function Once(event?: string): MethodDecorator { * @returns {MethodDecorator} */ export function NextTick(method: string): MethodDecorator { - return function (target: Vue, key: string, descriptor: any) { + return function(target: Vue, key: string, descriptor: any) { const original = descriptor.value descriptor.value = function emitter(...args: any[]) { if (original.apply(this, args) !== false) - if (typeof this[method] === 'function') { + if (typeof this[method] === "function") { this.$nextTick(this[method]) } else { - throw new TypeError('must be a method name') + throw new TypeError("must be a method name") } } } } -import { State, Getter, Action, Mutation, namespace } from 'vuex-class' -export { Vue, Component, Emit, Inject, Model, Prop, PropSync, Provide, Watch, Ref, mixins, State, Getter, Action, Mutation, namespace } \ No newline at end of file +import { State, Getter, Action, Mutation, namespace } from "vuex-class" +export { + Vue, + Component, + Emit, + Inject, + Model, + Prop, + PropSync, + Provide, + Ref, + Watch, + mixins, + State, + Getter, + Action, + Mutation, + namespace +} diff --git a/tsconfig.json b/tsconfig.json index 5a8401a..b0eafc6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "outDir": "./lib", - "esModuleInterop": true, + "esModuleInterop": true, "target": "es5", "module": "es2015", "moduleResolution": "node", @@ -11,23 +11,11 @@ "noImplicitAny": true, "removeComments": false, "strictNullChecks": true, - "typeRoots": [ - "./node_modules/@types/" - ], + "typeRoots": ["./node_modules/@types/"], "allowSyntheticDefaultImports": true, - "lib": [ - "dom", - "es2015", - "es2016", - "es2017" - ] + "lib": ["dom", "es2015", "es2016", "es2017"] }, - "include": [ - "src/**/*.ts" - ], - "exclude": [ - "node_modules", - "lib" - ], + "include": ["src/**/*.ts"], + "exclude": ["node_modules", "lib"], "compileOnSave": false }