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

fix(core): drop support for plural event/gesture names #10539

Merged
merged 8 commits into from
May 7, 2024

Conversation

shirakaba
Copy link
Contributor

@shirakaba shirakaba commented May 5, 2024

This PR is based onto the following PRs that are in review:

I'd suggest reviewing this by just selecting the commits from this PR, excluding the commits from those prior two PRs. As per the screenshot, you'd scroll to the bottom of the commits (most recent at the bottom), and select the same commits as I've indicated in blue. In other words, the first included commit should be chore(core): drop support for plural events.

image

PR Checklist

What is the current behavior?

Currently, it is possible to listen for plural events by passing a comma-delimited series of event names (which may optionally be surrounded by whitespace):

observable.addEventListener("propertyChange,loaded");
// Adds listeners for the "propertyChange" and "loaded" events

observable.addEventListener("propertyChange  ,  loaded");
// Adds listeners for the "propertyChange" and "loaded" events

It is also possible to observe plural gestures, but due to bugs in the implementation, it is only possible via a plural enum and not a plural string.

observable.addEventListener("tap,doubleTap");
// Fails.
//
// The fromString() method in `gestures-common.ts` doesn't split on commas, so
// the gesture name here coerces to `undefined`, thus
// Observable.prototype.addEventListener() throws a TypeError saying
// "Event name(s) must be a string.".

observable.addEventListener(GestureTypes.tap & GestureTypes.doubleTap);
// Succeeds, though will cease to be allowed if #10537 (which disallows numeric
// event names) is merged.
//
// At the time of writing, adds a single observer that manages two GestureHandlers:
// - one for the "tap" gesture
// - one for the "doubleTap" gesture

What is the new behavior?

We now interpret event names as-is, corresponding to a singular event listener or observer. So we no longer trim event names, nor split on commas. As this PR is based on #10537, we only accept string names, so don't support enums at all (so avoid having to special-case plural enums).

observable.addEventListener("propertyChange,loaded");
// Adds a (probably not very useful) listener for the non-existent
// "propertyChange,loaded" event

observable.addEventListener("  propertyChange  ,  loaded  ");
// Adds a (probably not very useful) listener for the non-existent
// "  propertyChange  ,  loaded  " event

observable.addEventListener("tap,doubleTap");
// Adds a (probably not very useful) listener for the non-existent
// "propertyChange,loaded" event.
//
// Since it doesn't exactly match any gesture name, it is indeed
// an event listener and not a gesture observer.

observable.addEventListener("  propertyChange  ,  loaded  ");
// Adds a (probably not very useful) listener for the non-existent
// "  propertyChange  ,  loaded  " event.
//
// Since it doesn't exactly match any gesture name, it is indeed
// an event listener and not a gesture observer.

Benefits

  • Improves performance of event-handling by avoiding unnecessary trimming and splitting of event names.
  • Avoids users hitting upon the broken functionality for observing plural gestures when passing a string rather than an enum.
  • May make life easier for renderers (reduces divergence from DOM Events)
  • Greatly simplifies the codebase, as now we only operate on singular GestureTypes rather than combinatorial ones.

Breaking changes

This PR drops support for listening for:

  • whitespace-padded event names, e.g. " propertyChange "
  • plural events, e.g. "propertyChange,loaded"
  • plural gestures, e.g. GestureTypes.tap & GestureTypes.doubleTap (though support for this form should be removed in fix(core): stop accepting GestureTypes enum as an eventName #10537, and the string form "tap,doubleTap" was never working to begin with).

Impact

From TSC discussions, it doesn't seem that this feature is commonly, if ever, used, so impact may be low in practice. Certainly, it wasn't used anywhere within Core except in some test cases (which I've updated accordingly).

Migration steps

Any plugins or userland code using plural event/gesture names should instead split them into singular names and listen for them individually.

@cla-bot cla-bot bot added the cla: yes label May 5, 2024
@shirakaba shirakaba changed the title fix(core): remove multiple event/gesture name handling fix(core): drop support for plural event/gesture names May 5, 2024
Copy link
Collaborator

@farfromrefug farfromrefug left a comment

Choose a reason for hiding this comment

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

@shirakaba shouldn't the regexp for names be removed now ?
The rest looks good

@shirakaba shirakaba force-pushed the remove-multiple-event-name-handling branch from 4ad7108 to b2b207e Compare May 5, 2024 07:18
farfromrefug
farfromrefug previously approved these changes May 5, 2024
@shirakaba shirakaba force-pushed the remove-multiple-event-name-handling branch from 00a3608 to c469a40 Compare May 7, 2024 01:05
@NathanWalker NathanWalker merged commit 9be392f into main May 7, 2024
4 checks passed
@NathanWalker NathanWalker deleted the remove-multiple-event-name-handling branch May 7, 2024 01:20
apburgess pushed a commit to apburgess/NativeScript that referenced this pull request May 15, 2024
apburgess pushed a commit to apburgess/NativeScript that referenced this pull request May 15, 2024
apburgess pushed a commit to apburgess/NativeScript that referenced this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants