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

Allow explicitly unsetting hooks on .extend() #599

Merged

Conversation

Kenneth-Sills
Copy link
Contributor

@Kenneth-Sills Kenneth-Sills commented Jun 25, 2024

Ref: #408

The implementation here is pretty simple: just give hook merging some custom logic, so it either merges OR resets to an empty array. Matches what was discussed in the related ticket.

Documentation has been updated to describe this behavior as well.

The dedicated test is just a modified copy of the existing ky.extend() one. Admittedly, I did modify a couple of other tests to cover the edge cases instead of building brand-new tests. No reason other than noticing they were already close to what I needed.. and I'm being lazy. 😅

The implementation here is pretty simple: just give hook merging some custom
logic so it either merges OR resets to an empty array. Matches what was
discussed in the related ticket.

Documentation has been updated to describe this behavior as well.

The dedicated test is just a modified copy of the existing `ky.extend()` one.
Admittedly, I did modify a couple of other tests to cover the edge cases
instead of building brand new tests. No reason other than noticing they were
already close to what I needed and I'm being lazy.

Closes #408
@Kenneth-Sills Kenneth-Sills marked this pull request as ready for review June 25, 2024 05:26
@sholladay
Copy link
Collaborator

I left my thoughts on this approach here: #408 (comment)

TL;DR: I don't like it. It continues down a path that is too convoluted and magical for my taste.

That aside, the implementation in this PR looks good to me.

…le-retry-after-statuses into kesills-better-extend-hooks

Manual resolutions required:

- Conflicts between my updated `extend()` tests in `test/main.ts`
  and the tests added with the new function form of `extend()`. Resolved by
  accepting their modified base test and just adding my changes, then putting my
  new `extend()` test below all their new cases.
- Trivial resolution for import formatting in `source/core/Ky.ts`.
- A change to `newHookValue` in `source/utils/merge.ts`, using
  `Object.hasOwn` per the linter's suggestion.
@Kenneth-Sills
Copy link
Contributor Author

Kenneth-Sills commented Jul 26, 2024

@sholladay This should be ready for re-review, following your latest comment in the related ticket. Conflict resolutions described in the merge commit. Thanks!

@sholladay sholladay changed the title feat: allow explicitly unsetting hooks on .extend() Allow explicitly unsetting hooks on .extend() Jul 30, 2024
@sholladay
Copy link
Collaborator

LGTM. Thanks for the great discussion about how to incrementally improve the extend/merge logic.

@sholladay sholladay merged commit 0017053 into sindresorhus:main Jul 30, 2024
1 check passed
sholladay pushed a commit to crisshaker/ky that referenced this pull request Jul 31, 2024
* feat: allow explicitly unsetting hooks on `.extend()`

The implementation here is pretty simple: just give hook merging some custom
logic so it either merges OR resets to an empty array. Matches what was
discussed in the related ticket.

Documentation has been updated to describe this behavior as well.

The dedicated test is just a modified copy of the existing `ky.extend()` one.
Admittedly, I did modify a couple of other tests to cover the edge cases
instead of building brand new tests. No reason other than noticing they were
already close to what I needed and I'm being lazy.

Closes sindresorhus#408

* chore: remove unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants