Skip to content

Commit eb9cbc8

Browse files
committed
rename / simplify API
1 parent 1e65f07 commit eb9cbc8

File tree

7 files changed

+32
-48
lines changed

7 files changed

+32
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
example/build.js
3+
example/build.js.map

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
# vue-classy
1+
# vue-class-component
22

33
> Experimental ES7 / TypeScript decorator for class-style Vue components.
44
55
### Example Usage with Babel stage=0:
66

77
``` js
8-
import Vue from 'vue'
9-
import VueClassy from 'vue-classy'
8+
import component from 'vue-class-component'
109

11-
Vue.use(VueClassy)
12-
13-
@Vue.componentClass
14-
export default class Component extends Vue {
10+
@component
11+
export default class Component {
1512

1613
// template
1714
static template = `
@@ -54,4 +51,4 @@ new Component({
5451
$ npm install && npm run build
5552
```
5653

57-
Theoretically, this should also work properly as a TypeScript 1.5+ decorator. If you'd like to make it work properly with TypeScript, feel free to contribute!
54+
Theoretically, this should also work properly as a TypeScript 1.5+ decorator, but I'm not familiar enough with TypeScript to figure out how type checks would come into play. If you'd like to make it work properly with TypeScript, feel free to contribute!

example/example.es7.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import Vue from 'vue'
2-
import VueClassy from '../'
1+
import component from '../'
32

4-
Vue.use(VueClassy)
5-
6-
@Vue.componentClass
7-
export default class Component extends Vue {
3+
@component
4+
export default class Component {
85

96
// template
107
static template = `

example/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ module.exports = {
88
loaders: [
99
{ test: /\.es7\.js$/, loader: 'babel?stage=0' }
1010
]
11-
}
11+
},
12+
devtool: 'source-map'
1213
}

index.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Vue
1+
var Vue = require('vue')
22

33
var internalHooks = [
44
'created',
@@ -11,7 +11,7 @@ var internalHooks = [
1111
'detached'
1212
]
1313

14-
function decorate (Component) {
14+
function decorator (Component) {
1515
var capture = new Component(false)
1616
var options = {}
1717
// instance properties are data
@@ -22,8 +22,6 @@ function decorate (Component) {
2222
}
2323
}
2424
// prototype props.
25-
// only need to identify hooks and methods.
26-
// computed properties just work!
2725
var proto = Component.prototype
2826
Object.getOwnPropertyNames(proto).forEach(function (key) {
2927
if (key === 'constructor') {
@@ -34,25 +32,28 @@ function decorate (Component) {
3432
options[key] = proto[key]
3533
return
3634
}
37-
// methods
3835
var descriptor = Object.getOwnPropertyDescriptor(proto, key)
3936
if (typeof descriptor.value === 'function') {
37+
// methods
4038
(options.methods || (options.methods = {}))[key] = descriptor.value
39+
} else if (descriptor.get || descriptor.set) {
40+
// computed properties
41+
(options.computed || (options.computed = {}))[key] = {
42+
get: descriptor.get,
43+
set: descriptor.set
44+
}
4145
}
4246
})
4347
// copy static options
4448
Object.keys(Component).forEach(function (key) {
4549
options[key] = Component[key]
4650
})
47-
// set options
51+
// find super
4852
var Super = proto.__proto__.constructor
49-
Component.options = Vue.util.mergeOptions(Super.options, options)
50-
Component['super'] = Super
51-
Component.extend = Super.extend
52-
// asset registers
53-
Vue.config._assetTypes.forEach(function (type) {
54-
Component[type] = Super[type]
55-
})
53+
if (!(Super instanceof Vue)) {
54+
Super = Vue
55+
}
56+
return Super.extend(options)
5657
}
5758

5859
function clone (val) {
@@ -69,9 +70,4 @@ function clone (val) {
6970
}
7071
}
7172

72-
function install (externalVue) {
73-
Vue = externalVue
74-
Vue.componentClass = decorate
75-
}
76-
77-
module.exports = install
73+
module.exports = decorator

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"name": "vue-classy",
2+
"name": "vue-class-component",
33
"version": "1.0.0",
44
"description": "ES7/TypeScript class decorator for Vue components",
55
"main": "index.js",
66
"scripts": {
7-
"build": "webpack --config example/webpack.config.js"
7+
"build": "webpack --config example/webpack.config.js",
8+
"dev": "webpack --config example/webpack.config.js --watch"
89
},
910
"repository": {
1011
"type": "git",
@@ -22,6 +23,9 @@
2223
"url": "https://github.com/vuejs/vue-classy/issues"
2324
},
2425
"homepage": "https://github.com/vuejs/vue-classy#readme",
26+
"peerDependencies": {
27+
"vue": "^0.12.3"
28+
},
2529
"devDependencies": {
2630
"babel-core": "^5.6.7",
2731
"babel-loader": "^5.2.0",

webpack.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)