-
-
Notifications
You must be signed in to change notification settings - Fork 765
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
Removed bindall
, added some types, changed source.ts factory
#2707
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2707 +/- ##
==========================================
+ Coverage 73.81% 73.85% +0.03%
==========================================
Files 238 238
Lines 18928 18916 -12
Branches 4244 4250 +6
==========================================
- Hits 13972 13970 -2
+ Misses 4956 4946 -10
☔ View full report in Codecov by Sentry. |
Why are arrow functions preferred in object/class methods? |
They preserve "this" when used with event listeners. They do the same as bindall basically. |
I'm a fan of the method definition syntax because:
The advantage of late-binding (when registering the callback) is you don't have to look at the implementing class to tell whether The problem with late-binding which can make trouble:
Another option to consider is decorators. But I don't think we should be using them. It's still too exotic a feature. It seems suspicious that many properties of e.g. |
I'm not sure what you are suggestion here, feel free to submit a PR to improve what you don't like, I generally don't see the value in |
One clear disadvantage of these arrow functions is that it breaks inheritance. Am I missing something or is it not possible to extend class methods anymore using MapLibre v3? Edit: I need to also use arrow function to override the parent method but I can't call super() I guess. |
I don't like these arrow function in general, but I dislike bind more, so I think this is a lesser evil. |
I agree with @clementmas. I also strongly dislike bind, but I'm not sure breaking inheritance is better? Also, I believe this is a breaking change if it breaks inheritance, especially in the controls. Breaking inheritance there seems especially onerous. |
Looking deeply at this PR, most of the methods are prefixed with I do think we should create some helper method to allow registering an event with an anonymous method and returning something you can unsubscribe from, like rxjs does. |
Superficial refactoring to remove bindall and introduce the typescript
() =>
way of doing things in modern code.