-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(core): stop accepting GestureTypes enum as an eventName #10537
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the names suggest, these tests are not actually automated tests; they're purely auto-documented code-snippets for use on the old docs site. I thought I'd just remove the now-unsupported ones to save some mental burden when using the search functionality.
export function fromString(type: string): GestureTypes | undefined { | ||
return GestureTypes[type.trim()]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the .toLowerCase()
as:
- Event names have mostly been input via the
toString()
convenience function up until now. - Users should have been getting the string keys from the
GestureTypes
enum to begin with.
To be honest, we can likely remove the .trim()
too, but I'd prefer to do that in the PR where we remove support for multiple event names.
this.on(GestureTypes.touch, this._highlightedHandler); | ||
this.on(GestureTypes[GestureTypes.touch], this._highlightedHandler); | ||
} else { | ||
this.off(GestureTypes.touch, this._highlightedHandler); | ||
this.off(GestureTypes[GestureTypes.touch], this._highlightedHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@farfromrefug As requested, now using the string constants instead (forgot how enums worked).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is we have guided people to use the types as explained in old docs for years: https://old.docs.nativescript.org/ui/gestures
How are we going to make up for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 🤔
Optimistically, I’d imagine they’d see a compiler error, see that it now accepts only a string, and be able to take a good guess at what the string is (as it comes from the same enum).
Arguably, it’s now left unmentioned in the new docs, so the typings serve as the up-to-date documentation.
I’d rather not handle it at runtime and just pull the plaster, if possible. It’s unlikely to be the only breaking change regarding event-handling that’s to come, so once the dust has settled, we could provide a migration guide based on what makes it into the release. Most likely in the blog post announcing the new release.
@farfromrefug @edusperoni @CatchABus Sorry to poke. Anything holding this back from approval? |
Good with me |
This PR is related to #10538, but can be merged independently. Whichever is merged first will cause minor conflicts with the other, but it's a simple rebase that I'd be happy to take care of.
PR Checklist
What is the current behavior?
ViewCommon is a subclass of Observable. When overriding
addEventListener
andremoveEventListener
, it makes the following changes to the signature:Although this is allowed in TypeScript, even in strict mode, here are my motivations for removing it:
What is the new behavior?
Accept only strings for event names.
This is not a breaking change within Core (no tests were relying on it, and I've migrated the only four lines relying on it), and any plugins making use of it should see what to do by heeding the updated typings.