Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // fetcher is (..args) => Promise
- export const createFetcher = fetcher => {
- let cache = {};
- return {
- read: (...args) => {
- if (cache[args] === undefined) {
- throw fetcher(args).then(v => (cache[args] = v));
- } else {
- return cache[args];
- }
- }
- };
- };
Add Comment
Please, Sign In to add comment