Browse Source

Move main logic out of reduce callback

refactor-class
Luke Childs 8 years ago
parent
commit
5f3b425ff9
  1. 8
      src/index.js

8
src/index.js

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

Loading…
Cancel
Save