-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from cyclejs-community/add-eslint
Add ESLint
- Loading branch information
Showing
5 changed files
with
101 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
2 | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"never" | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import xs from 'xstream'; | ||
import xs from 'xstream' | ||
|
||
export default function combineCycles(...mains) { | ||
return sources => { | ||
const sinks = mains.map(main => main(sources)); | ||
const sinks = mains.map(main => main(sources)) | ||
|
||
const drivers = Object.keys( | ||
sinks.reduce((drivers, sink) => Object.assign(drivers, sink), {}) | ||
); | ||
) | ||
|
||
const combinedSinks = drivers | ||
.reduce((combinedSinks, driver) => { | ||
const driverSinks = sinks | ||
.filter(sink => sink[driver]) | ||
.map(sink => sink[driver]); | ||
.map(sink => sink[driver]) | ||
|
||
combinedSinks[driver] = xs.merge(...driverSinks); | ||
return combinedSinks; | ||
}, {}); | ||
combinedSinks[driver] = xs.merge(...driverSinks) | ||
return combinedSinks | ||
}, {}) | ||
|
||
return combinedSinks; | ||
return combinedSinks | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
import {run} from '@cycle/xstream-run'; | ||
import xs from 'xstream'; | ||
import {run} from '@cycle/xstream-run' | ||
import xs from 'xstream' | ||
|
||
export default function createCycleMiddleware(mainFn, drivers = {}) { | ||
return store => | ||
next => { | ||
let actionListener = null; | ||
let stateListener = null; | ||
let actionListener = null | ||
let stateListener = null | ||
|
||
function actionDriver(outgoing$) { | ||
outgoing$.addListener({ | ||
next: outgoing => { | ||
store.dispatch(outgoing); | ||
store.dispatch(outgoing) | ||
}, | ||
error: () => {}, | ||
complete: () => {}, | ||
}); | ||
}) | ||
|
||
return xs.create({ | ||
start: listener => { | ||
actionListener = listener; | ||
actionListener = listener | ||
}, | ||
stop: () => {}, | ||
}); | ||
}) | ||
} | ||
|
||
const isSame = {}; | ||
const getCurrent = store.getState; | ||
const isSame = {} | ||
const getCurrent = store.getState | ||
function stateDriver() { | ||
return xs.create({ | ||
start: listener => { | ||
stateListener = listener; | ||
stateListener = listener | ||
}, | ||
stop: () => {}, | ||
}) | ||
.fold((prevState, currState) => { | ||
if (prevState === getCurrent) { | ||
prevState = getCurrent(); | ||
prevState = getCurrent() | ||
} | ||
if (prevState === currState) { | ||
return isSame; | ||
return isSame | ||
} | ||
return currState; | ||
return currState | ||
}, getCurrent) | ||
.map(state => state === getCurrent ? getCurrent() : state) | ||
.filter(state => state !== isSame); | ||
.filter(state => state !== isSame) | ||
} | ||
|
||
drivers.ACTION = actionDriver; | ||
drivers.STATE = stateDriver; | ||
run(mainFn, drivers); | ||
drivers.ACTION = actionDriver | ||
drivers.STATE = stateDriver | ||
run(mainFn, drivers) | ||
|
||
return action => { | ||
let result = next(action) | ||
if (actionListener) { | ||
actionListener.next(action); | ||
actionListener.next(action) | ||
} | ||
if (stateListener) { | ||
stateListener.next(store.getState()); | ||
stateListener.next(store.getState()) | ||
} | ||
return result | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters