-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override
FetchOptions
from event listeners
The problem --- Prior to this commit, instances of `FormSubmission` and `FetchRequest` referenced in dispatched `turbo:submit-start` and `turbo:before-fetch-request` events were tedious to update. For example, the `FormSubmission` instance made available through `event.detail.formSubmission` exposed properties that _seemed_ readable and writable. However, mutations to `formSubmission.method` or `formSubmission.location` occur _after_ the underlying `FetchRequest` instance is built. This timing of that instance's construction has subtle and not obvious implications. In practice, writes to these properties are unobserved by the underlying `FetchRequest` instance, and have no effect on the `fetch` call. If calling applications are aware of these issues and limitations, they can work around them by mutating the `event.detail.formSubission.fetchRequest` instance. The proposal --- After this commit, the `FormSubmission.constructor` will deduce the required data (like `[method]` and `[action]` values) then use those values to construct the `FetchRequest` instance. After that construction, the reads and writes to the `FormSubmission` properties will _delegate_ to the `FetchRequest` instance. In tandem with those changes, the `FetchRequest` will follow a similar pattern: extract as much information up-front during construction, then delegate property reads and writes to the correct instance. In most cases, it will delegate to its [`fetchOptions: RequestInit`][RequestInit] instance. To achieve this behavior, several module-local functions and type definitions were shuffled around between the `FormSubmission` and `FetchRequest` modules. The order of arguments for the `FetchRequest` constructor were also re-arranged to support omitting values that are made redundant by default arguments. [RequestInit]: https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters
- Loading branch information
1 parent
495de2e
commit d0a147e
Showing
7 changed files
with
253 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.