-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consolidate [NpmDownloads] into one service #3318
Conversation
This moves the four npm download services into a single class, in line with #3174, and other service implementations we've written in the last couple months.
|
return this.constructor.render({ downloads }) | ||
} | ||
async handle({ interval, scope, packageName }) { | ||
const { query, schema, transform } = intervalMap[interval] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like using destructuring here. It makes this code particularly readable and I think a bit less error prone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I like this a lot too
dm: { | ||
query: 'point/last-month', | ||
schema: pointResponseSchema, | ||
transform: json => json.downloads, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little bit of repetition here, though it helps with clarity.
} | ||
} | ||
// For testing. | ||
static get _intervalMap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! This makes things easy to test without having to define (and unnecessarily call) a class level render/transform function
This moves the four npm download services into a single class, in line with #3174, and other service implementations we've written in the last couple months.
intervalMap
pattern that I think @calebcartwright started us using.