-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Use ES6 class syntax #3408
Use ES6 class syntax #3408
Conversation
Note that `util.bindHandlers` no longer works with ES6 classes (prototype methods are not enumerable), so I removed it in favor of more explicit `util.bindAll`.
4b4c641
to
59c871a
Compare
Updating the top comment with new gotchas as I go. There are quite a few, but all are reasonable. |
Benchmarks (freezed on geojson-setdata-large master, so slightly incomplete): map-load style-load buffer fps frame-duration query-point query-box geojson-setdata-small |
This is ready for review. I'm leaving out |
None of the gotchas seem particularly concerning to me. This will definitely cause merge conflicts. The one PR I'd call out specifically is #3402, because it's on a deadline. |
@jfirebaugh yeah, I specifically reviewed that one to make sure that it'll be relatively easy to rebase — I can help with that after this PR is merged. |
Great. I'm 👍 here, but will let @lucaswoj do the review approval and final say on when to time the merge. |
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.
👍
Closes #3400. Some gotchas:
util.extend(obj, Foo.prototype)
or usefor prop in obj
to iterate over methods), so all places where we depend on this need to be fixed.util.bindHandlers
in favor of explicit binding withutil.bindAll
.Evented
is now a class rather than a mixin.super
calls to constructors of all classes that have a parent class (e.g.class Map extends Evented
). This is enforced byeslint:recommended
, and I think this is a good practice, so I decided to fix this instead of turning off the rules._enabled
prototype property in handlers and replacedreturn this._enabled
withreturn !!this._enabled
. Another consequence isutil.setOptions
won't work (it depends onoptions
prototype object) so we're ditching it.module.exports
can't come beforeclass ...
— using class before it is defined is a JS error (unlike using function).module.exports
in the main class, otherwise the child class will try to extendundefined
and fail.get anchors
), but I don't see any reason not to rename those tocamelCase
.@class Foo
jsdoc comments becausedocumentation
infers that type of thing now.I suggest reviewing this PR commit by commit, and merging it without squash too, since all commits are self-contained, and the total diff is too big (5k+).
Checklist:
Make sure the generated docs are still correct.Current docs are broken in master, so I suggest fixing as a follow-up PR.Progress:
сс @jfirebaugh @lucaswoj @mollymerp