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

feat(signal): remove passed signal from defautlMapOptionsToKey #83

Merged
merged 5 commits into from
Aug 24, 2023

Conversation

dogpatch626
Copy link
Member

Description

add support for abortController by allowing a signal to be passed as an option

Motivation and Context

How Has This Been Tested?

tested locally passing signal as options

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • My changes are in sync with the code style of this project.
  • There aren't any other open Pull Requests for the same issue/update.
  • These changes should be applied to a maintenance branch.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using Fetchye?

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 3, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit aedde24:

Sandbox Source
quick-install Configuration
fetchye-provider-install Configuration
fetchye-redux-provider-install Configuration
nextjs-fetchye-ssr Configuration

@@ -16,6 +16,7 @@

export const defaultMapOptionsToKey = (options) => {
const {
signal,
Copy link
Member

Choose a reason for hiding this comment

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

Can you make a unit tests that calls this function with this name and shows that it is removed.

One that would fail if this change was reverted

Copy link
Member

@10xLaCroixDrinker 10xLaCroixDrinker left a comment

Choose a reason for hiding this comment

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

Add unit test

README.md Outdated
@@ -748,7 +773,7 @@ A React Hook used for dispatching asynchronous API requests.
**Shape**

```
const { isLoading, data, error, run } = useFetchye(key, { defer: Boolean, mapOptionsToKey: options => options, ...fetchOptions }, fetcher);
const { isLoading, data, error, run } = useFetchye(key, { signal: {}, defer: Boolean, mapOptionsToKey: options => options, ...fetchOptions }, fetcher);
Copy link
Contributor

@JAdshead JAdshead Aug 21, 2023

Choose a reason for hiding this comment

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

signal is a fetch api that would be included as part of fetchOptions and is not part of the useFetchye api so should be removed from here.

Suggested change
const { isLoading, data, error, run } = useFetchye(key, { signal: {}, defer: Boolean, mapOptionsToKey: options => options, ...fetchOptions }, fetcher);
const { isLoading, data, error, run } = useFetchye(key, { defer: Boolean, mapOptionsToKey: options => options, ...fetchOptions }, fetcher);

README.md Outdated
@@ -765,6 +790,7 @@ const { isLoading, data, error, run } = useFetchye(key, { defer: Boolean, mapOpt
|--------------------|-------------------------------------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mapOptionsToKey` | `(options: Options) => transformedOptions` | `false` | A function that maps options to the key that will become part of the cache key |
| `mapKeyToCacheKey` | `(key: String, options: Options) => cacheKey: String` | `false` | A function that maps the key for use as the cacheKey allowing direct control of the cacheKey |
| `signal` | `Object` | `false` | Prevents execution of `useFetchye` when desired cancelling DOM request (See [Abort Controller](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)). |
Copy link
Contributor

@JAdshead JAdshead Aug 21, 2023

Choose a reason for hiding this comment

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

This is not a useFetchye api so should be removed.

Suggested change
| `signal` | `Object` | `false` | Prevents execution of `useFetchye` when desired cancelling DOM request (See [Abort Controller](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)). |

README.md Outdated
@@ -337,6 +337,31 @@ const NewBookForm = () => {
};
```

### Abort Signal
Copy link
Contributor

@JAdshead JAdshead Aug 21, 2023

Choose a reason for hiding this comment

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

Im not sure that this should be documented in this mannor, else the readme should document all of the fetch apis.
Maybe this should be framed as an example of aborting an inflight request on unmount to demonstraight that useFetchye is just a wrapper around fetch.

Copy link
Contributor

@JAdshead JAdshead left a comment

Choose a reason for hiding this comment

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

Update documentation based on comments.

README.md Outdated
### Abort Signal

When you neeed to abort the execution of a `useFetchye` call, you may
pass a signal as an option in such way.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pass a signal as an option in such way.
pass a signal as an option, as demonstrated below.

@JAdshead JAdshead merged commit 8bb4b36 into main Aug 24, 2023
6 checks passed
@JAdshead JAdshead deleted the feat/abort-signal branch August 24, 2023 22:46
@dogpatch626 dogpatch626 mentioned this pull request Aug 28, 2023
9 tasks
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

5 participants