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 chunks = (arr, chunkSize) => { | |
let results = []; | |
while (arr.length) results.push(arr.splice(0, chunkSize)); | |
return results; | |
}; | |
module.exports = (xs, f, concurrency) => { | |
if (xs.length == 0) return Promise.resolve(); | |
return Promise.all(chunks(xs, concurrency).reduce( | |
(acc, chunk) => acc.then(() => Promise.all(chunk.map(f))), |
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
// How to ensure that our animation loop ends on component unount | |
componentDidMount() { | |
this.startLoop(); | |
} | |
componentWillUnmount() { | |
this.stopLoop(); | |
} |
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
/* | |
* Inspired by Dan Abramov's "Making setInterval Declarative with React Hooks", | |
* this is a custom hook for debouncing a callback (e.g. for click handlers) such | |
* that a callback will not be fired until some delay has passed since the last click. | |
* The callback will automatically be updated with the latest props and state on every | |
* render meaning that users don't need to worry about stale information being used. | |
* | |
* See https://overreacted.io/making-setinterval-declarative-with-react-hooks/ for the | |
* original inspiration. | |
*/ |
OlderNewer