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
function flatten(arr) { | |
return function f(arr, newArr) { | |
arr.forEach(function(v)) { | |
Array.isArray(v) ? f(v, newArr) : newArr.push(v); | |
}); | |
return newArr; | |
}(arr, []); | |
} |
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
export function requiredParam (param) { | |
const requiredParamError = new Error( | |
`Required parameter, "${param}" is missing.` | |
) | |
// preserve original stack trace | |
if (typeof Error.captureStackTrace === ‘function’) { | |
Error.captureStackTrace( | |
requiredParamError, | |
requiredParam | |
) |
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
export function pipe(...fns) { | |
return param => fns.reduce( | |
(result, fn) => fn(result), | |
param | |
) | |
} |
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
export const getFilteredPair = (base: object, checker: (value: any) => boolean): object => { | |
return Object.keys(base).reduce((acc, key) => { | |
if (checker(key)) { | |
acc[key] = base[key]; | |
} | |
return acc; | |
}, {}); | |
} |
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
const minify = require('html-minifier').minify; | |
const fs = require('fs'); | |
class HtmlMinifierPlugin { | |
constructor(options) { | |
this.options = options; | |
} | |
apply(compiler) { | |
compiler.plugin("emit", (compilation, callback) => { | |
fs.readFile(this.options.template, 'utf-8', (err, html) => { |
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
export const delay = (time: number) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(resolve, time); | |
}); | |
}; |
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
class Store { | |
constructor(state = {}, actions = {}) { | |
this.state = state; | |
this.actions = actions; | |
this.dispatch = (action, data) => { | |
const newMergedData = this.actions[action](this.state, data); | |
Object.assign(this.state, newMergedData); | |
}; | |
} | |
} |
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
export class Marker extends EventEmitter { | |
constructor( | |
private id: number, | |
) { | |
super(); | |
document.querySelector("marker").addEventListener("click", () => { | |
// do something | |
this.trigger("card_action", this.id); | |
}); |
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
class Card extends React.Component<CardProps> { | |
do() { | |
// do something... | |
} | |
render() { | |
const { index } = this.props; | |
return ( ... ); | |
} | |
} |
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
const counter = (state = 0, action) => { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1; | |
case 'DECREMENT': | |
return state - 1; | |
default: | |
return state; | |
} | |
} |