Skip to content

Instantly share code, notes, and snippets.

View lupomontero's full-sized avatar

Lupo Montero lupomontero

View GitHub Profile
const splitArrayIntoBatches = (arr, limit) => arr.reduce((memo, item) => {
if (memo.length && memo[memo.length - 1].length < limit) {
memo[memo.length - 1].push(item);
return memo;
}
return [...memo, [item]];
}, []);
const pact = (tasks, concurrency, interval = 0, failFast = true) => {
@lupomontero
lupomontero / throttled.js
Created June 20, 2018 03:47
Process promise-based tasks in batches, with a delay between batches
const splitArrayIntoBatches = (arr, limit) => arr.reduce((memo, item) => {
if (memo.length && memo[memo.length - 1].length < limit) {
memo[memo.length - 1].push(item);
return memo;
}
return [...memo, [item]];
}, []);
const throttled = (tasks, concurrency, interval = 0) => {
@lupomontero
lupomontero / batched.js
Last active September 14, 2018 12:45
Process promise-based tasks in batches
const splitArrayIntoBatches = (arr, limit) => arr.reduce((memo, item) => {
if (memo.length && memo[memo.length - 1].length < limit) {
memo[memo.length - 1].push(item);
return memo;
}
return [...memo, [item]];
}, []);
const batched = (tasks, concurrency) => {
@lupomontero
lupomontero / splitArrayIntoBatches.js
Created June 20, 2018 03:39
Split array into batches
const splitArrayIntoBatches = (arr, limit) => arr.reduce((memo, item) => {
if (memo.length && memo[memo.length - 1].length < limit) {
memo[memo.length - 1].push(item);
return memo;
}
return [...memo, [item]];
}, []);
import React from 'react';
import Profile from './Profile';
export default () => (
<div>
<Profile user={{ name: 'Jimi Hendrix', email: '[email protected]' }} />
</div>
);
import React from 'react';
import PropTypes from 'prop-types';
const Profile = ({ user = {} }) => (
<div>
<h2>{user.name}</h2>
<p>
<a href={`mailto:${user.email}`}>
{user.email}
</a>
import React from 'react';
import PropTypes from 'prop-types';
const Profile = ({ user = {} }) => (
<div>
<h2>{user.name}</h2>
<p>
<a href={`mailto:${user.email}`}>
{user.email}
</a>
import React from 'react';
export default ({ user = {} }) => (
<div>
<h2>{user.name}</h2>
<p>
<a href={`mailto:${user.email}`}>
{user.email}
</a>
</p>
<Profile user={{ name: 'Jimi Hendrix', email: '[email protected]' }} />
import React from 'react';
export default props => (
<div>
<h2>{props.user.name}</h2>
<p>
<a href={`mailto:${props.user.email}`}>
{props.user.email}
</a>
</p>