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
| /** | |
| * This function shuffles an array of items. | |
| * @param arr {Array} array of items | |
| * @param clone {Boolean} immutable or not | |
| * @returns {Array} the array of items in random order. | |
| */ | |
| function shuffle(arr, clone) { | |
| var array = clone ? arr.slice(0) : arr; | |
| var m = array.length, t, i; |
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 CATEGORIES = [ | |
| { id: 'animals', parent: null }, | |
| { id: 'mammals', parent: 'animals' }, | |
| { id: 'cats', parent: 'mammals' }, | |
| { id: 'dogs', parent: 'mammals' }, | |
| { id: 'labrador', parent: 'dogs' }, | |
| { id: 'cocker spaniel', parent: 'dogs' }, | |
| { id: 'rag doll', parent: 'cats' }, | |
| { id: 'burmese', parent: 'cats' }, | |
| ]; |
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 "babel-polyfill"; | |
| const asyncQuerySelector = async (node, query) => { | |
| try { | |
| return await (query ? node.querySelector(query) : node); | |
| } catch (error) { | |
| console.error(`Cannot find ${query ? `${query} in`: ''} ${node}.`, error); | |
| return null; | |
| } | |
| }; |
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
| /** | |
| * Clamp value between | |
| * Creates a function that will restrict a given value between `min` and `max` | |
| * @param {number} min | |
| * @param {number} max | |
| * @return {number} | |
| */ | |
| const clamp = (min, max) => (v) => Math.min(Math.max(v, min), max); | |
| /* |
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
| function pipe(...fns) { | |
| return param => fns.reduce( | |
| (result, fn) => fn(result), | |
| param | |
| ) | |
| } | |
| /* | |
| The above function takes a list of functions and returns a function that can | |
| apply the list from left to right, starting with a given parameter and then |
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
| 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 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
| // @flow | |
| import React, { PureComponent } from 'react'; | |
| type ObjectType = { [key: string]: string }; | |
| type Keys = Array<string>; | |
| type Props = { | |
| attributes: ObjectType, | |
| styles: ObjectType, | |
| target: HTMLElement, |
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
| function get(obj, ...props) { | |
| const val = obj[props[0]]; | |
| if (props.length === 1 || !val) return val; | |
| const rest = props.slice(1); | |
| return get.apply(null, [val, ...rest]); | |
| } |
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 raf from 'raf'; | |
| /** | |
| @param t: time (elapsed) | |
| @param b: initial value | |
| @param c: amount of change | |
| @param d: duration | |
| */ | |
| function easeOutCubic(t: number, b: number, c: number, d: number): number { | |
| return c * ((t = t / d - 1) * t * t + 1) + 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
| import React, { Component } from 'react'; | |
| import PropTypes from 'prop-types'; | |
| const DefaultBaseComponent = props => <div {...props} />; | |
| const withContextFromProps = ( | |
| propTypes: PropTypes.object, | |
| BaseComponent: PropTypes.func = DefaultBaseComponent | |
| ) => { | |
| class ContextProps extends Component { |