Skip to content

Move source code to src #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ node_modules
example/build.js
example/build.js.map
test/test.build.js

/index.js
/index.d.ts
lib
2 changes: 1 addition & 1 deletion example/example.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Vue from 'vue'
import Component from '../index'
import Component from '../lib/index'

@Component({
props: {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"name": "vue-class-component",
"version": "4.2.0",
"description": "ES201X/TypeScript class decorator for Vue components",
"main": "index.js",
"typings": "index.d.ts",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
"index.js",
"index.d.ts",
"lib",
"tsconfig.json"
],
"scripts": {
"build": "tsc -p .",
"clean": "rm -rf lib",
"example": "npm run build && webpack --config example/webpack.config.js",
"dev": "webpack --config example/webpack.config.js --watch",
"test": "npm run build && webpack --config test/webpack.config.js && mocha test/test.build.js",
"prepublish": "npm run build"
"prepublish": "npm run clean && npm run build"
},
"repository": {
"type": "git",
Expand Down
17 changes: 2 additions & 15 deletions index.ts → src/component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Vue from 'vue'
import { VueClass } from './declarations'

const internalHooks = [
'data',
Expand All @@ -15,9 +16,7 @@ const internalHooks = [
'render'
]

export type VueClass = { new (): Vue } & typeof Vue

function componentFactory (
export function componentFactory (
Component: VueClass,
options: Vue.ComponentOptions<any> = {}
): VueClass {
Expand Down Expand Up @@ -52,15 +51,3 @@ function componentFactory (
: Vue
return Super.extend(options)
}

export default function decorator <U extends Vue>(options: Vue.ComponentOptions<U>): <V extends VueClass>(target: V) => V
export default function decorator <V extends VueClass>(target: V): V
export default function decorator <V extends VueClass>(options: Vue.ComponentOptions<any> | V): any {
if (typeof options === 'function') {
return componentFactory(options)
}
return function (Component: any) {
return componentFactory(Component, options)
}
}

3 changes: 3 additions & 0 deletions src/declarations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as Vue from 'vue'

export type VueClass = { new (): Vue } & typeof Vue
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as Vue from 'vue'
import { VueClass } from './declarations'

import { componentFactory } from './component'

export default function Component <U extends Vue>(options: Vue.ComponentOptions<U>): <V extends VueClass>(target: V) => V
export default function Component <V extends VueClass>(target: V): V
export default function Component <V extends VueClass>(options: Vue.ComponentOptions<any> | V): any {
if (typeof options === 'function') {
return componentFactory(options)
}
return function (Component: V) {
return componentFactory(Component, options)
}
}
2 changes: 1 addition & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Component from '../index'
import Component from '../lib/index'
import { expect } from 'chai'
import * as Vue from 'vue'

Expand Down
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "lib",
"isolatedModules": false,
"experimentalDecorators": true,
"declaration": true,
Expand All @@ -16,10 +17,8 @@
"removeComments": true,
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
"node_modules",
"test",
"example"
"include": [
"src/**/*.ts"
],
"compileOnSave": false
}