A Pen by Tomáš Reichmann on CodePen.
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
// retries async check() untill it resolves or time runs out | |
const retry = async (check = async () => true, timeout = 1000, interval = 100, started = Date.now()) => { | |
const startTime = Date.now(); | |
return check().catch( | |
(error) => { | |
return new Promise((resolve, reject) => { | |
const resolveTime = Date.now(); | |
if (Date.now() + interval > started + timeout) { | |
reject(error); | |
} |
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
({ babel: false}) | |
const set = require('lodash/set'); | |
const get = require('lodash/get'); | |
const unset = require('lodash/unset'); | |
// Mocks === | |
const mockPromise = (response = 123, delay = 1000, willFail = false) => { | |
return new Promise((resolve, reject) => { |
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
({ babel: false }) | |
const range = require('lodash/range'); | |
const attributeItems = { | |
year: [ | |
'2018', '2017' | |
], | |
quarter: [ | |
'Q1', 'Q2', 'Q3', 'Q4' |
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 getTreeLeaves = (tree: any, getChildren = (node: any) => node && node.children) => { | |
const leaves = []; | |
const nodes = Array.isArray(tree) ? [...tree] : [tree]; | |
let node; | |
let children; | |
while ( | |
// tslint:disable-next-line:no-conditional-assignment ban-comma-operator | |
node = nodes.shift(), children = getChildren(node), | |
((children && children.length) || (leaves.push(node) && nodes.length)) | |
) { |
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 indexOfTreeNode = ( | |
node: any, | |
tree: any, | |
matchNode = (nodeA: any, nodeB: any) => (nodeA === nodeB), | |
getChildren = (node: any) => node && node.children || [], | |
indexes: number[] = [] | |
): number[] => { | |
const nodes = Array.isArray(tree) ? [...tree] : [tree]; | |
for (let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++) { | |
const currentNode = nodes[nodeIndex]; |