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

fix: merge URLSearchParams qs arguments #134

Merged
merged 7 commits into from
May 23, 2022

Conversation

dbushong
Copy link
Member

@dbushong dbushong commented May 22, 2022

const client = new Gofer({ c: { qs: { id: 'x' } } }, 'c');
// both of these now work and request /go?id=x&other=y
await client.get('/go', { qs: { other: 'y' } });
// fixed
await client.get('/go', { qs: new URLSearchParams({ other: 'y' }) });

NOTE: values for a given key replace all values for existing key
(don't think this rises to the level of breaking):

const config = { c: { qs: { a: '1', b: '3' } } };
const client = new Gofer(config, 'c');
console.log(client.getMergedOptions(
  {},
  { qs: new URLSearchParams([['a', '2'], ['a', '4']]) }
));

// before:
// new URLSearchParams([['a', '1'], ['b', '3'], ['a', '2'], ['a', '4']])

// now: (note existing a: 1 has been removed)
// new URLSearchParams([['a', '2'], ['b', '3'], ['a', '4']])

This PR was started by: git wf pr

* use modern classes
* use assert instead of assertive
```js
const client = new Gofer({ c: { qs: { id: 'x' } } }, 'c');
// both of these now work and request /go?id=x&other=y
await client.get('/go', { qs: { other: 'y' } });
// fixed
await client.get('/go', { qs: new URLSearchParams({ other: 'y' }) });
```
Comment on lines -93 to +97
function preventComplexMerge(objValue, srcValue) {
function goferMerge(objValue, srcValue) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Just renamed to reflect broader functionality

Copy link
Member

@aotarola aotarola left a comment

Choose a reason for hiding this comment

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

sweet 💚

values for a given key replace all values for existing key
(don't think this rises to the level of breaking):

```js
const config = { c: { qs: { a: '1', b: '3' } } };
const client = new Gofer(config, 'c');
console.log(client.getMergedOptions(
  {},
  { qs: new URLSearchParams([['a', '2'], ['a', '4']]) }
));

// before:
// new URLSearchParams([['a', '1'], ['b', '3'], ['a', '2'], ['a', '4']])

// now: (note existing a: 1 has been removed)
// new URLSearchParams([['a', '2'], ['b', '3'], ['a', '4']])
```
@dbushong dbushong requested a review from aotarola May 23, 2022 17:02
Copy link
Member

@aotarola aotarola left a comment

Choose a reason for hiding this comment

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

💚

@dbushong dbushong merged commit 21d69e5 into main May 23, 2022
@dbushong dbushong deleted the dbushong/feature/main/merge-qs branch May 23, 2022 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants