Skip to content

Commit

Permalink
Reformatted code and added missing exports
Browse files Browse the repository at this point in the history
  • Loading branch information
husayt committed Oct 17, 2019
1 parent 673a4d4 commit f60366f
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 157 deletions.
26 changes: 17 additions & 9 deletions fixtures/emit.ts
Original file line number Diff line number Diff line change
@@ -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")
}
}
28 changes: 18 additions & 10 deletions fixtures/inject.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
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")
}
}

@Component
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")
}
}

@Component
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")
}
}
14 changes: 7 additions & 7 deletions fixtures/model.ts
Original file line number Diff line number Diff line change
@@ -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")
}
}
92 changes: 59 additions & 33 deletions lib/nuxt-property-decorator.d.ts
Original file line number Diff line number Diff line change
@@ -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
}
52 changes: 29 additions & 23 deletions lib/nuxt-property-decorator.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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]);
}
};
Expand All @@ -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]);
}
};
Expand All @@ -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");
}
};
};
Expand Down Expand Up @@ -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 () {
Expand Down
44 changes: 24 additions & 20 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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"
]
}
Loading

0 comments on commit f60366f

Please sign in to comment.