Browse Source

Move main logic out of reduce callback

pull/6/head
Luke Childs 8 years ago
parent
commit
958ba8bf50
  1. 8
      src/index.js

8
src/index.js

@ -22,8 +22,8 @@ function checkResponseCache(response) {
return maxAge && maxAge[1];
}
module.exports = endpoints.reduce((onionoo, endpoint) => {
onionoo[endpoint] = args => new Promise((resolve, reject) => {
function createEndpointMethod(endpoint) {
return args => new Promise((resolve, reject) => {
// Build query string (don't encode ':' for search filters)
const qs = querystring.encode(args).replace(/%3A/g, ':');
@ -56,6 +56,10 @@ module.exports = endpoints.reduce((onionoo, endpoint) => {
}));
}
});
}
module.exports = endpoints.reduce((onionoo, endpoint) => {
onionoo[endpoint] = createEndpointMethod(endpoint);
return onionoo;
}, {});

Loading…
Cancel
Save