Skip to content

Commit b249273

Browse files
authored
Merge pull request #29 from cyclejs-community/add-eslint
Add ESLint
2 parents 03b423d + 84137ec commit b249273

File tree

5 files changed

+101
-67
lines changed

5 files changed

+101
-67
lines changed

.eslintrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es6": true,
5+
"node": true
6+
},
7+
"extends": "eslint:recommended",
8+
"parserOptions": {
9+
"sourceType": "module"
10+
},
11+
"rules": {
12+
"indent": [
13+
"error",
14+
2
15+
],
16+
"linebreak-style": [
17+
"error",
18+
"unix"
19+
],
20+
"quotes": [
21+
"error",
22+
"single"
23+
],
24+
"semi": [
25+
"error",
26+
"never"
27+
]
28+
}
29+
};

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
}
2020
],
2121
"scripts": {
22-
"test": "npm run build && jest",
22+
"eslint": "eslint --fix src/ test/",
23+
"test": "npm run build && npm run eslint && jest",
2324
"build": "babel --presets es2015 src --out-dir dist",
2425
"prepublish": "npm run build"
2526
},
2627
"jest": {
27-
"testPathIgnorePatterns": ["/example"]
28+
"testPathIgnorePatterns": [
29+
"/example"
30+
]
2831
},
2932
"license": "MIT",
3033
"dependencies": {
@@ -35,6 +38,7 @@
3538
"babel-cli": "^6.18.0",
3639
"babel-jest": "^18.0.0",
3740
"babel-preset-es2015": "^6.9.0",
41+
"eslint": "^3.15.0",
3842
"jest": "^18.1.0",
3943
"redux": "^3.6.0"
4044
}

src/combineCycles.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import xs from 'xstream';
1+
import xs from 'xstream'
22

33
export default function combineCycles(...mains) {
44
return sources => {
5-
const sinks = mains.map(main => main(sources));
5+
const sinks = mains.map(main => main(sources))
66

77
const drivers = Object.keys(
88
sinks.reduce((drivers, sink) => Object.assign(drivers, sink), {})
9-
);
9+
)
1010

1111
const combinedSinks = drivers
1212
.reduce((combinedSinks, driver) => {
1313
const driverSinks = sinks
1414
.filter(sink => sink[driver])
15-
.map(sink => sink[driver]);
15+
.map(sink => sink[driver])
1616

17-
combinedSinks[driver] = xs.merge(...driverSinks);
18-
return combinedSinks;
19-
}, {});
17+
combinedSinks[driver] = xs.merge(...driverSinks)
18+
return combinedSinks
19+
}, {})
2020

21-
return combinedSinks;
21+
return combinedSinks
2222
}
2323
}

src/createCycleMiddleware.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
import {run} from '@cycle/xstream-run';
2-
import xs from 'xstream';
1+
import {run} from '@cycle/xstream-run'
2+
import xs from 'xstream'
33

44
export default function createCycleMiddleware(mainFn, drivers = {}) {
55
return store =>
66
next => {
7-
let actionListener = null;
8-
let stateListener = null;
7+
let actionListener = null
8+
let stateListener = null
99

1010
function actionDriver(outgoing$) {
1111
outgoing$.addListener({
1212
next: outgoing => {
13-
store.dispatch(outgoing);
13+
store.dispatch(outgoing)
1414
},
1515
error: () => {},
1616
complete: () => {},
17-
});
17+
})
1818

1919
return xs.create({
2020
start: listener => {
21-
actionListener = listener;
21+
actionListener = listener
2222
},
2323
stop: () => {},
24-
});
24+
})
2525
}
2626

27-
const isSame = {};
28-
const getCurrent = store.getState;
27+
const isSame = {}
28+
const getCurrent = store.getState
2929
function stateDriver() {
3030
return xs.create({
3131
start: listener => {
32-
stateListener = listener;
32+
stateListener = listener
3333
},
3434
stop: () => {},
3535
})
3636
.fold((prevState, currState) => {
3737
if (prevState === getCurrent) {
38-
prevState = getCurrent();
38+
prevState = getCurrent()
3939
}
4040
if (prevState === currState) {
41-
return isSame;
41+
return isSame
4242
}
43-
return currState;
43+
return currState
4444
}, getCurrent)
4545
.map(state => state === getCurrent ? getCurrent() : state)
46-
.filter(state => state !== isSame);
46+
.filter(state => state !== isSame)
4747
}
4848

49-
drivers.ACTION = actionDriver;
50-
drivers.STATE = stateDriver;
51-
run(mainFn, drivers);
49+
drivers.ACTION = actionDriver
50+
drivers.STATE = stateDriver
51+
run(mainFn, drivers)
5252

5353
return action => {
5454
let result = next(action)
5555
if (actionListener) {
56-
actionListener.next(action);
56+
actionListener.next(action)
5757
}
5858
if (stateListener) {
59-
stateListener.next(store.getState());
59+
stateListener.next(store.getState())
6060
}
6161
return result
6262
}
6363
}
64-
}
64+
}

test/createCycleMiddleware.test.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import { createCycleMiddleware } from '../';
2-
import { createStore, applyMiddleware } from 'redux';
3-
import xs from 'xstream';
4-
jest.useFakeTimers();
1+
/* eslint-disable no-undef */
2+
import { createCycleMiddleware } from '../'
3+
import { createStore, applyMiddleware } from 'redux'
4+
import xs from 'xstream'
5+
jest.useFakeTimers()
56

67
function initStore(main, drivers, reducer = null) {
7-
const rootReducer = reducer || ((state = [], action) => state.concat(action));
8-
const cycleMiddleware = createCycleMiddleware(main, drivers);
8+
const rootReducer = reducer || ((state = [], action) => state.concat(action))
9+
const cycleMiddleware = createCycleMiddleware(main, drivers)
910
const store = createStore(
1011
rootReducer,
1112
applyMiddleware(cycleMiddleware)
12-
);
13-
return store;
13+
)
14+
return store
1415
}
1516

1617
describe('Redux cycle middleware', () => {
1718
it('dispatches a PING to see whether the middleware dispatches a PONG', (done) => {
1819
function main(sources) {
1920
const pong$ = sources.ACTION
2021
.filter(action => action.type === 'PING')
21-
.mapTo({ type: 'PONG' });
22+
.mapTo({ type: 'PONG' })
2223

2324
return {
2425
ACTION: pong$
@@ -36,19 +37,19 @@ describe('Redux cycle middleware', () => {
3637

3738
expect(store.getState()).toMatchObject(expectedActions)
3839

39-
done();
40+
done()
4041
})
4142

4243
it('dispatches a PING to see whether the middleware dispatches a PONG after 10 seconds', (done) => {
4344
function main(sources) {
4445
const pong$ = sources.ACTION
4546
.filter(action => action.type === 'PING')
46-
.map(a =>
47+
.map(() =>
4748
xs.periodic(10000)
4849
.take(1)
4950
.mapTo({ type: 'PONG' })
5051
)
51-
.flatten();
52+
.flatten()
5253

5354
return {
5455
ACTION: pong$
@@ -69,36 +70,36 @@ describe('Redux cycle middleware', () => {
6970
{ type: 'PING' }
7071
])
7172

72-
expect(store.getState()).not.toMatchObject(expectedActions);
73-
jest.runAllTimers();
74-
expect(setInterval.mock.calls[0][1]).toBe(10000);
75-
expect(store.getState()).toMatchObject(expectedActions);
76-
done();
73+
expect(store.getState()).not.toMatchObject(expectedActions)
74+
jest.runAllTimers()
75+
expect(setInterval.mock.calls[0][1]).toBe(10000)
76+
expect(store.getState()).toMatchObject(expectedActions)
77+
done()
7778
})
7879

7980
it('dispatches INCREMENT_ASYNC and INCREMENT_IF_ODD actions to check whether state updates correctly', (done) => {
8081
function main(sources) {
81-
const state$ = sources.STATE;
82+
const state$ = sources.STATE
8283
const isOdd$ = state$
8384
.map(state => state % 2 === 1)
84-
.take(1);
85+
.take(1)
8586

8687
const incrementIfOdd$ = sources.ACTION
8788
.filter(action => action.type === 'INCREMENT_IF_ODD')
88-
.map(action =>
89+
.map(() =>
8990
isOdd$
9091
)
9192
.flatten()
9293
.filter(isOdd => isOdd)
93-
.mapTo({ type: 'INCREMENT' });
94+
.mapTo({ type: 'INCREMENT' })
9495

9596
const increment$ = sources.ACTION
9697
.filter(action => action.type === 'INCREMENT_ASYNC')
97-
.mapTo({ type: 'INCREMENT' });
98+
.mapTo({ type: 'INCREMENT' })
9899

99100
const decrement$ = sources.ACTION
100101
.filter(action => action.type === 'DECREMENT_ASYNC')
101-
.mapTo({ type: 'DECREMENT' });
102+
.mapTo({ type: 'DECREMENT' })
102103

103104
const both$ = xs.merge(increment$, decrement$)
104105

@@ -109,29 +110,29 @@ describe('Redux cycle middleware', () => {
109110

110111
const store = initStore(main, {}, (state = 0, action) => {
111112
switch (action.type) {
112-
case 'INCREMENT':
113-
return state + 1;
114-
case 'DECREMENT':
115-
return state - 1;
116-
default:
117-
return state;
113+
case 'INCREMENT':
114+
return state + 1
115+
case 'DECREMENT':
116+
return state - 1
117+
default:
118+
return state
118119
}
119120
})
120121

121122
store.dispatch({ type: 'INCREMENT_ASYNC' })
122-
expect(store.getState()).toBe(1);
123+
expect(store.getState()).toBe(1)
123124
store.dispatch({ type: 'INCREMENT_ASYNC' })
124-
expect(store.getState()).toBe(2);
125+
expect(store.getState()).toBe(2)
125126
store.dispatch({ type: 'INCREMENT_ASYNC' })
126-
expect(store.getState()).toBe(3);
127+
expect(store.getState()).toBe(3)
127128
store.dispatch({ type: 'INCREMENT_IF_ODD' })
128-
expect(store.getState()).toBe(4);
129+
expect(store.getState()).toBe(4)
129130
store.dispatch({ type: 'INCREMENT_IF_ODD' })
130-
expect(store.getState()).toBe(4);
131+
expect(store.getState()).toBe(4)
131132
store.dispatch({ type: 'INCREMENT_ASYNC' })
132-
expect(store.getState()).toBe(5);
133+
expect(store.getState()).toBe(5)
133134

134-
done();
135+
done()
135136

136137
})
137138
})

0 commit comments

Comments
 (0)