Skip to content
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

BaseService: Factor out a couple methods #1425

Merged
merged 1 commit into from
Jan 15, 2018
Merged

BaseService: Factor out a couple methods #1425

merged 1 commit into from
Jan 15, 2018

Conversation

paulmelnikow
Copy link
Member

  • Adjust test grouping
  • Rename data -> queryParams, text -> message

In the process of adding and testing some error-handling code to the base services, I factored out a couple methods. The diff is a bit gnarly. I think those changes will be easier to read if this is reviewed separately.

- Adjust test grouping
- Rename data -> queryParams, text -> message
@paulmelnikow paulmelnikow added the core Server, BaseService, GitHub auth, Shared helpers label Jan 5, 2018
@shields-ci
Copy link

Messages
📖

✨ Thanks for your contribution to Shields, @paulmelnikow!

Generated by 🚫 dangerJS

@paulmelnikow
Copy link
Member Author

@platan @RedSparr0w Would you mind giving this a read?

@platan
Copy link
Member

platan commented Jan 9, 2018

@paulmelnikow I will look at this tomorrow.

if (serviceData.text) {
text[1] = serviceData.text;
if (serviceData.message) {
text[1] = serviceData.message;
}
Object.assign(badgeData, serviceData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message is copied from serviceData to badgeData here. Do we need it in badgeData?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I don't think it is currently used in badgeData.

Also not sure if there maybe a reason why it was this way, but could we also change the following to directly assign the value:

-        const text = badgeData.text;
-        if (serviceData.text) {
-          text[1] = serviceData.text;
+        if (serviceData.message) {
+          badgeData.text[1] = serviceData.message;
         }
-        badgeData.text = text;

Same thing with line 116-118.
Seems to be ~30-50% slower when re-assigning with an array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need message in badgeData.

I think the reason the assignment was done strangely is that text was being copied from serviceData into badgeData. Since it's not called text anymore, that shouldn't matter.

Maybe the least surprising thing here would be to whitelist the acceptable keys from serviceData, and copy only what is present.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote this to make everything more explicit, but I think I will defer it to the next PR because the diff is again pretty large.

static register(camp, handleRequest) {
const serviceClass = this; // In a static context, "this" is the class.

static get _regex() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to extract _regex and _namedParamsForMatch 👍.

const captures = match.slice(1, -1);

if (this.uri.capture.length !== captures.length) {
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know all the plans for services rewrite but in my opinion it would be good idea to add test for this fragment and for other untested code in this base class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this is a great idea.

@platan
Copy link
Member

platan commented Jan 10, 2018

I looks good to me. The base class looks better now 😄 . I've left one question.

@paulmelnikow paulmelnikow merged commit b318873 into badges:node-8 Jan 15, 2018
@paulmelnikow paulmelnikow deleted the base-refactor branch January 15, 2018 18:16
paulmelnikow added a commit that referenced this pull request Mar 12, 2018
…1543

This merges the `node-8` branch. The heavy lift was by @Daniel15 with refactoring from me and a patch by @RedSparr0w.

* New API for registering services (#963)
* Disable Node 6 tests on node-8 branch (#1423)
* BaseService: Factor out methods _regex and _namedParamsForMatch (#1425)
    - Adjust test grouping
    - Rename data -> queryParams, text -> message
* BaseService tests: Use Chai (#1450)
* BaseService: make serviceData and badgeData explicit and declarative (#1451)
* fix isValidStyle test (#1544)
* Run tests in Node 9, not Node 6 (#1543)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Server, BaseService, GitHub auth, Shared helpers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants