Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feature: run query() only when query is in parts
  • Loading branch information
wachunei committed Feb 10, 2018
commit 78daaee83634263b7da64e234593864659015998
6 changes: 5 additions & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,15 +1240,19 @@
this._parts = URI.parse(String(href), this._parts);
} else if (_URI || _object) {
var src = _URI ? href._parts : href;
var hasQueryPart = false;
for (key in src) {
if (key === 'query') {
hasQueryPart = true;
Copy link
Contributor Author

@wachunei wachunei Feb 10, 2018

Choose a reason for hiding this comment

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

wait a second, this can be true even if src['query'] is undefined, isnt it?
maybe I should have changed it to

if (key === 'query' && src[key] !== undefined) {

Copy link
Member

Choose a reason for hiding this comment

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

you can keep the if (key === 'query') { continue; } part and add if (src.query) { this.query(src.query, false); }. you only need to execute .query() if there actually is a value (other than null, undefined, empty-string)

continue;
}
if (hasOwn.call(this._parts, key)) {
this._parts[key] = src[key];
}
}
this.query(src['query']);
if (hasQueryPart) {
this.query(src['query']);
}
} else {
throw new TypeError('invalid input');
}
Expand Down