Browse Source

Swap factory function for wrapper function in reduce callback

Looks simpler and saves a level of indentation
pull/15/head
Luke Childs 8 years ago
parent
commit
d4b4f42c25
  1. 6
      src/index.js

6
src/index.js

@ -30,15 +30,14 @@ class Onionoo {
// Return object containing endpoint methods // Return object containing endpoint methods
return this.options.endpoints.reduce((onionoo, endpoint) => { return this.options.endpoints.reduce((onionoo, endpoint) => {
onionoo[endpoint] = this.createEndpointMethod(endpoint); onionoo[endpoint] = options => this.get(endpoint, options);
return onionoo; return onionoo;
}, {}); }, {});
} }
// Returns a function to make requests to a given endpoint // Returns a function to make requests to a given endpoint
createEndpointMethod(endpoint) { get(endpoint, options) {
return options => {
// Build query string (don't encode ':' for search filters) // Build query string (don't encode ':' for search filters)
const qs = querystring.encode(options).replace(/%3A/g, ':'); const qs = querystring.encode(options).replace(/%3A/g, ':');
@ -86,7 +85,6 @@ class Onionoo {
return response; return response;
}); });
}); });
};
} }
// Returns a promise for a request // Returns a promise for a request

Loading…
Cancel
Save