Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support { handleEvent() {} } object interface as a listener #4538

Merged
merged 4 commits into from
Oct 28, 2024
Merged

Support { handleEvent() {} } object interface as a listener #4538

merged 4 commits into from
Oct 28, 2024

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Oct 28, 2024

  • Implements and closes Support for handleEvent DOM interface #2382
  • Currently a draft because I couldn't get tests to run.
  • Introduces a 13 byte increase in brotli'd bundle size (4247b -> 4260b)
  • Update typescript declarations
  • Tests for new behavior

@marvinhagemeister
Copy link
Member

To run the tests:

  1. Run npm install (other package managers won't work)
  2. Run npm run test:karma:watch to run the tests.

@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 28, 2024

Thanks, I had to install chrome using playwright but I could run the tests with that command!

@lilnasy lilnasy marked this pull request as ready for review October 28, 2024 15:05
@coveralls
Copy link

Coverage Status

coverage: 99.488%. remained the same
when pulling 9c267a1 on lilnasy:event-listener-object
into 4181cba on preactjs:main.

Comment on lines 1487 to +1489
export type EventHandler<E extends TargetedEvent> = {
bivarianceHack(event: E): void;
}['bivarianceHack'];
}['bivarianceHack'] | EventHandlerObject<E>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This worked for my projects, but I'm still cautious of changing an exported type. It might be necessary to leave this intact and instead add to the attribute interfaces one-by-one.

Copy link
Member

Choose a reason for hiding this comment

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

This seems to cause issues elsewhere (see #4581), though I'm not quite sure what it's even doing? If you have a moment, would love an explanation. A lot of this TS stuff flies right over my head

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll reply in the issue.

Copy link
Member

Choose a reason for hiding this comment

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

Cheers, and no rush! If that's incorrect usage then fair enough too! I'm very much unfamiliar with what this is doing.

Comment on lines +169 to +170
if (options.event) e = options.event(e);
return "handleEvent" in eventHandler ? eventHandler.handleEvent(e) : eventHandler(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The method must be called using the dot syntax; pulling it as an intermediate value would prevent it from receiving the object as this. The alternative is .apply()/.call() but I suspect that would add even more to the size.

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

Sweet, thanks!

@marvinhagemeister marvinhagemeister merged commit 8447cf7 into preactjs:main Oct 28, 2024
13 checks passed
@JoviDeCroock JoviDeCroock mentioned this pull request Nov 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for handleEvent DOM interface
4 participants