This file contains hidden or 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
const ENTER_KEY_CODE = 13 | |
let keyCodesBuffer = [] | |
document.addEventListener("keypress", (event) => { | |
const keyCode = event.keyCode | |
if(keyCode === ENTER_KEY_CODE) { | |
fillInputWithKeyCodesBuffer() | |
cleanBuffer() | |
} else { |
This file contains hidden or 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
downloadClicks$: -------x------x----------------x----------> | |
csvData$: ---A---------------B----C--D-------E------> | |
withLatestFrom((clicks, data) => data) | |
downloadData$: -------A------A----------------D----------> |
This file contains hidden or 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
import R from 'ramda'; | |
// Export a driver to be used in our Cycle.js app. | |
// It takes an `input$` stream that contains `data` to be download. | |
function exportToCSVDriver(input$) { | |
// `data` should be formatted as an Array of Arrays (= lines of CSV). | |
// -> `[["name1", "city1", "other info"], ["name2", "city2", "more info"]]` | |
input$.subscribe((data) => { | |
// Parse data to create a CSV file. | |
// See: http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side |
This file contains hidden or 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
import {pipe, pluck, over, head, last, spread} from 'lodash/fp'; | |
import {daysSpent} from './utils/dates'; | |
// leadTime : [{date: Date}] -> Number | |
const leadTime = pipe( | |
pluck( 'date' ), // first convert input into [Date] | |
over( [ head, last ] ), // then turns them to our arguments array [ FirstDate, LastDate ] | |
spread( daysSpent ) // finally spread arguments to the function | |
); |
This file contains hidden or 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
import {pipe, pluck, converge, head, last} from 'ramda'; | |
import {daysSpent} from './utils/dates'; | |
// leadTime : [{date: Date}] -> Number | |
const leadTime = pipe( | |
pluck('date'), // first convert input into [Date] | |
converge( daysSpent, [ head, last ] ) // then pick proper ones for calculation | |
); |
This file contains hidden or 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
import {converge, pipe, prop, head, last} from 'ramda'; | |
import {daysSpent} from './utils/dates'; | |
// leadTime : [{date: Date}] -> Number | |
const leadTime = converge( | |
daysSpent, | |
[ pipe( head, prop('date') ), pipe( last, prop('date') ) ] | |
); |
This file contains hidden or 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
// What I ended up with | |
const getX = ( input ) => getY( parseA( input ), parseB( input ) ); | |
// What I was trying to achieve, some sort of: | |
const getX = anyFunction( getY( parseA, parseB ) ); |
This file contains hidden or 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
import {pipe, prop, head, last} from 'ramda'; | |
import {daysSpent} from './utils/dates'; | |
// leadTime : [{date: Date}] -> Number | |
const leadTime = (items) => daysSpent( | |
pipe( head, prop('date') )(items), | |
pipe( last, prop('date') )(items) | |
); |
This file contains hidden or 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
[ | |
{ "list": "Backlog", "date": "2016-04-01" }, | |
{ "list": "Card Preparation [2]", "date": "2016-04-01" }, | |
{ "list": "Production [3]", "date": "2016-04-02" }, | |
{ "list": "Tests QA [2]", "date": "2016-04-05" }, | |
{ "list": "Mise en live [1]", "date": "2016-04-05" }, | |
{ "list": "In Production", "date": "2016-04-06" }, | |
{ "list": "Live (April 2016)", "date": "2016-04-08" } | |
] |
This file contains hidden or 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
// From https://github.com/MostlyAdequate/mostly-adequate-guide/blob/master/ch5.md#pointfree | |
// Not point-free because we mention the data: name | |
let initials = (name) => name.split(' ').map(compose(toUpperCase, head)).join('. '); | |
// Point-free style | |
let initials = compose( | |
join('. '), | |
map(compose(toUpperCase, head)), | |
split(' ') |