Skip to content

Instantly share code, notes, and snippets.

@dark4eg
Created November 5, 2019 16:07
Show Gist options
  • Save dark4eg/bcb3593ca3865665940a719a481184e7 to your computer and use it in GitHub Desktop.
Save dark4eg/bcb3593ca3865665940a719a481184e7 to your computer and use it in GitHub Desktop.
finction memoize (fn) {
const cache = {};
return function (...args) {
let stringifiedArgs = JSON.stringify(args);
if (cache[stringifiedArgs]) {
return cache[stringifiedArgs];
}
const result = fn(...arguments);
cache[stringifiedArgs] = result;
return result;
};
};
const getBondsDataFn = async ({date, isins}) => {
const result = await http.post({
url: `/bonds/${date}`,
body: isins
});
return result;
};
const getBondsData = memoize(getBondsDataFn);
getBondsData({  date: '20180120',   isins: ['XS0971721963', 'RU000A0JU4L3']  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment