Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor!: split file input change event into seperate function #129

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

Open
jonkoops wants to merge 1 commit into react-dropzone:beta
base: beta
Choose a base branch
Loading
from jonkoops:split-change-event

Conversation

@jonkoops
Copy link
Collaborator

@jonkoops jonkoops commented Feb 24, 2025

What kind of change does this PR introduce?

  • Bug Fix
  • Feature
  • Refactoring
  • Style
  • Build
  • Chore
  • Documentation
  • CI

Did you add tests for your changes?

  • Yes, my code is well tested
  • Not relevant

If relevant, did you update the documentation?

  • Yes, I've updated the documentation
  • Not relevant

Summary
This PR is a continuation of #126 and removes the handling of the change event from the fromEvent() function, and moves it to a dedicated fromChangeEvent() function purposefully made for handling this specific event.

This reduces the need to handle polymorphic input and narrow down what the exact type should be in fromEvent(), in this case also removing the need for this operation to be async. Additionally, this allows bundlers to more effectively tree-shake the module in case the other code is never used. The JSDoc on the function itself has also been improved with additional details for the consumer.

Does this PR introduce a breaking change?
Yes, change events are now handled in a dedicated fromChangeEvent() function. Users that were previously using fromEvent() will now have to use this dedicated function instead.

Other information
Not applicable.

Signed-off-by: Jon Koops <jonkoops@gmail.com>
BREAKING CHANGE: File input `change` events are now handled in a dedicated `fromChangeEvent()` function.
Copy link

Pull Request Test Coverage Report for Build 13499636153

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 13480585681: 0.0%
Covered Lines: 93
Relevant Lines: 93

💛 - Coveralls

@@ -1,2 +1,6 @@
export { fromEvent, fromFileHandles } from "./file-selector.js";
export {
Copy link
Collaborator

@rolandjitsu rolandjitsu Feb 25, 2025

Choose a reason for hiding this comment

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

I do believe that providing a convenience function that runs though each would help users migrate smoothly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am going to rename and refactor fromEvent to something else as well, perhaps we can then evaluate adding it back and see if it is worth to keep it in a deprecated manner?

I have to do some digging as well and see how we're going to go about upgrading this dependency in the main project, so there will likely be a beta branch there as well.

* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event|MDN - HTMLElement: `change` event}
*/
export function fromChangeEvent(event: Event): FileWithPath[] {
if (!(event.target instanceof HTMLInputElement) || !event.target.files) {
Copy link
Collaborator

@rolandjitsu rolandjitsu Feb 25, 2025

Choose a reason for hiding this comment

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

Could we also check with isObject? Since we don't know what to expect at runtime.

Suggested change
if (!(event.target instanceof HTMLInputElement) || !event.target.files) {
if (!isObject(event)||!(event.target instanceof HTMLInputElement) || !event.target.files) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think that is needed, we already have a very specific type of Event, so this value should always be correct. Of course users can pass whatever they want if they are not using TypeScript, but then they are still violating the API contract, and it is their responsibility to do this check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rolandjitsu rolandjitsu Awaiting requested review from rolandjitsu

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /