Skip to content

Commit 44b7287

Browse files
committed
add eslint
1 parent 2a3768b commit 44b7287

File tree

7 files changed

+618
-65
lines changed

7 files changed

+618
-65
lines changed

example/counter.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<!-- simple usage -->
1111
<button v-stream:click="plus$">Add on Click</button>
1212

13-
1413
<button v-stream:click="{ subject: plus$, data: minusDelta1, options:{once:true} }">Add on Click (Option once:true)</button>
1514

1615
<!-- you can also stream to the same subject with different events/data -->
@@ -21,6 +20,8 @@
2120
</button>
2221

2322
<pre>{{ $data }}</pre>
23+
24+
<my-button v-stream:click="plus$"></my-button>
2425
</div>
2526

2627
<script>
@@ -34,6 +35,12 @@
3435
}
3536
},
3637

38+
components: {
39+
myButton: {
40+
template: '<button>MyButton</button>'
41+
}
42+
},
43+
3744
created () {
3845
//Speed up mousemove minus delta after 5s
3946
setTimeout(() => {

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@
2424
"scripts": {
2525
"dev": "rollup -c rollup.config.js -w",
2626
"build": "rollup -c rollup.config.js",
27+
"lint": "eslint src test example --fix",
2728
"test": "jest",
2829
"dev:test": "jest --watch",
30+
"prebuild": "npm run lint",
2931
"pretest": "npm run build",
3032
"prepublish": "npm run build"
3133
},
3234
"devDependencies": {
3335
"buble": "^0.15.2",
36+
"eslint": "^3.0.0",
37+
"eslint-plugin-vue-libs": "^1.2.0",
3438
"jest": "^19.0.2",
3539
"rollup": "^0.41.6",
3640
"rollup-plugin-buble": "^0.15.0",
3741
"rollup-watch": "^3.2.2",
3842
"rxjs": "^5.2.0",
3943
"vue": "^2.2.4"
44+
},
45+
"eslintConfig": {
46+
"root": true,
47+
"extends": [
48+
"plugin:vue-libs/recommended"
49+
]
4050
}
4151
}

src/directives/stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default {
4343
)
4444
return
4545
}
46-
let fromEventArgs = handle.options ? [el, event, handle.options] : [el, event]
46+
const fromEventArgs = handle.options ? [el, event, handle.options] : [el, event]
4747
handle.subscription = Rx.Observable.fromEvent(...fromEventArgs).subscribe(e => {
4848
next({
4949
event: e,

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global Vue, Rx */
2+
13
import { install } from './util'
24
import rxMixin from './mixin'
35
import streamDirective from './directives/stream'

src/methods/eventToObservable.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export default function eventToObservable (evtName) {
1010
return
1111
}
1212
const vm = this
13-
let evtNames = Array.isArray(evtName) ? evtName : [evtName]
13+
const evtNames = Array.isArray(evtName) ? evtName : [evtName]
1414
const obs$ = Rx.Observable.create(observer => {
15-
let eventPairs = evtNames.map(name => {
16-
let callback = msg => observer.next({name, msg})
15+
const eventPairs = evtNames.map(name => {
16+
const callback = msg => observer.next({ name, msg })
1717
vm.$on(name, callback)
18-
return {name, callback}
18+
return { name, callback }
1919
})
2020
return () => {
2121
// Only remove the specific callback

test/test.js

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
/* eslint-env jest */
2+
13
'use strict'
4+
25
const Vue = require('vue/dist/vue.js')
36
const VueRx = require('../dist/vue-rx.js')
47

5-
//library
8+
// library
69
const Observable = require('rxjs/Observable').Observable
710
const Subject = require('rxjs/Subject').Subject
811
const Subscription = require('rxjs/Subscription').Subscription
912
require('rxjs/add/observable/fromEvent')
1013

11-
//user
14+
// user
1215
require('rxjs/add/operator/map')
1316
require('rxjs/add/operator/startWith')
1417
require('rxjs/add/operator/scan')
@@ -88,7 +91,7 @@ test('bind subscriptions to render', done => {
8891
})
8992

9093
test('subscriptions() has access to component state', () => {
91-
const { ob, next } = mock()
94+
const { ob } = mock()
9295

9396
const vm = new Vue({
9497
data: {
@@ -112,8 +115,6 @@ test('subscriptions() has access to component state', () => {
112115
})
113116

114117
test('v-stream directive (basic)', done => {
115-
const { ob, next } = mock()
116-
117118
const vm = new Vue({
118119
template: `
119120
<div>
@@ -128,7 +129,7 @@ test('v-stream directive (basic)', done => {
128129
.startWith(0)
129130
.scan((total, change) => total + change)
130131
}
131-
},
132+
}
132133
}).$mount()
133134

134135
expect(vm.$el.querySelector('span').textContent).toBe('0')
@@ -140,8 +141,6 @@ test('v-stream directive (basic)', done => {
140141
})
141142

142143
test('v-stream directive (with data)', done => {
143-
const { ob, next } = mock()
144-
145144
const vm = new Vue({
146145
data: {
147146
delta: -1
@@ -159,7 +158,7 @@ test('v-stream directive (with data)', done => {
159158
.startWith(0)
160159
.scan((total, change) => total + change)
161160
}
162-
},
161+
}
163162
}).$mount()
164163

165164
expect(vm.$el.querySelector('span').textContent).toBe('0')
@@ -178,8 +177,6 @@ test('v-stream directive (with data)', done => {
178177
})
179178

180179
test('v-stream directive (multiple bindings on same node)', done => {
181-
const { ob, next } = mock()
182-
183180
const vm = new Vue({
184181
template: `
185182
<div>
@@ -196,7 +193,7 @@ test('v-stream directive (multiple bindings on same node)', done => {
196193
.startWith(0)
197194
.scan((total, change) => total + change)
198195
}
199-
},
196+
}
200197
}).$mount()
201198

202199
expect(vm.$el.querySelector('span').textContent).toBe('0')
@@ -212,8 +209,6 @@ test('v-stream directive (multiple bindings on same node)', done => {
212209
})
213210

214211
test('$fromDOMEvent()', done => {
215-
const { ob, next } = mock()
216-
217212
const vm = new Vue({
218213
template: `
219214
<div>
@@ -285,41 +280,39 @@ test('$subscribeTo()', () => {
285280
expect(results).toEqual([1]) // should not trigger anymore
286281
})
287282

288-
289283
test('$eventToObservable()', done => {
290-
let calls = 0;
284+
let calls = 0
291285
const vm = new Vue({
292-
created(){
293-
let ob = this.$eventToObservable('ping')
286+
created () {
287+
this.$eventToObservable('ping')
294288
.subscribe(function (event) {
295-
expect(event.name).toEqual('ping');
296-
expect(event.msg).toEqual('ping message');
289+
expect(event.name).toEqual('ping')
290+
expect(event.msg).toEqual('ping message')
297291
calls++
298-
});
292+
})
299293
}
300-
});
301-
vm.$emit('ping','ping message');
302-
303-
nextTick(()=>{
304-
vm.$destroy();
305-
//Should not emit
306-
vm.$emit('pong','pong message');
307-
expect(calls).toEqual(1);
308-
done()
309-
});
310-
});
294+
})
295+
vm.$emit('ping', 'ping message')
311296

297+
nextTick(() => {
298+
vm.$destroy()
299+
// Should not emit
300+
vm.$emit('pong', 'pong message')
301+
expect(calls).toEqual(1)
302+
done()
303+
})
304+
})
312305

313306
test('$eventToObservable() with lifecycle hooks', done => {
314307
const vm = new Vue({
315-
created(){
308+
created () {
316309
this.$eventToObservable('hook:beforeDestroy')
317310
.subscribe(function (event) {
318311
done(event)
319-
});
312+
})
320313
}
321-
});
322-
nextTick(()=>{
314+
})
315+
nextTick(() => {
323316
vm.$destroy()
324317
})
325-
});
318+
})

0 commit comments

Comments
 (0)