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
// https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c | |
interface Counter { | |
// callable part | |
(): string; | |
// static properties | |
interval: number; | |
reset(): void; | |
} |
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 bubbleSort = nums => { | |
let wip = nums.slice() | |
let swapped; | |
do { | |
swapped = false; | |
for(let i = 0; i < wip.length; i++) { | |
let thisItem = wip[i]; | |
let nextItem = wip[i + 1]; |
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 { trimEnd } = require('lodash'); | |
const buildParamsString = params => | |
trimEnd( | |
Object.keys(params).reduce( | |
(acc, key) => `${acc}${key}=${params[key]}&`, | |
'?', | |
), | |
['?', '&'], | |
); |
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 React, { Component } from 'react'; | |
import { graphql } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
import { getQuery } from '.queries'; | |
class MyComponent extends Component { | |
render() { | |
return null // render stuff here. | |
} | |
} |
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 wait = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
// Usage | |
const method = async () => { | |
await wait(200); | |
console.log('do something 200ms later'); | |
}; |
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 React, {Component} from "react"; | |
import ReactDOM from "react-dom"; | |
class App extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
mounted: false | |
} | |
} |
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 render = (props, strings, ...toInterpolate) => | |
`.generatedClass {${strings.reduce((prev, next, i) => `${prev}${next}${typeof toInterpolate[i] === 'function' ? toInterpolate[i](props) : ''}`, '')}}`; | |
const StyledComponent = (...args) => ({ | |
render: props => render(props, ...args) | |
}); | |
const MyComponent = StyledComponent` | |
color: ${props => (props.primary ? 'red' : 'blue')}; | |
font-size: ${props => (props.primary ? '3em' : '2em')}; |
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
// input action | |
// default output action | |
// blockers : [{condition, action}] | |
const createConditionalAction = (inputActionType, final, potentialBlockers: []) => { | |
return (action$, store) => ( | |
action$ | |
.ofType(inputActionType) | |
.map(action => { | |
const blockers = potentialBlockers.filter(b => b[0](action, store)) |
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
/* | |
eslint no-unused-vars: 2, | |
react/no-unused-prop-types: 2, | |
react/prop-types: 2, | |
react/jsx-no-duplicate-props: 2, | |
eqeqeq: 2, | |
no-case-declarations: 2, | |
react/no-deprecated: 2 | |
*/ | |
const BemClassGenerator = (b = "") => { |
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 isIPhone6Plus = () => { | |
if (typeof window.device === "object" && | |
window.device.model && | |
window.device.model === "iPhone7,1") { | |
return true; | |
} | |
return false; | |
}; | |
export default isIPhone6Plus; |