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 gist aims to explain how it's possible that async functions inside React | |
// using createFetcher(Promise).next(key) can work. | |
// A possible implementation of the new createFetcher function | |
// as shown by https://twitter.com/jamiebuilds/status/969169357094842368 | |
// @param method, should be a function returning a Promise. | |
// @returns an object with a property 'read', used to read values from the resolved 'cache'. | |
const createFetcher = function(method) { | |
// First create a Map for the resolved values. | |
const resolved = new Map() |