-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
ES6 Classes #1993
ES6 Classes #1993
Conversation
Changes Unknown when pulling b7f6934 on heff:es6classes into * on videojs:master*. |
So apparently static methods are inherited in ES6 classes, so that makes the old Also I'm using the latest version of babelify but it's yelling at me for something I think it shouldn't.
I instead have to do
The first way works in the babel demo interface, so I'm not sure what's going on there. |
I think the spec changed to be the second example. I can find out for sure later. |
Had to modify some of the workflow because class syntax restrictions e.g. no `this` before super(). But all tests are passing.
The ES6 class work has been updated and all classes have been converted. All tests are passing so it could be merged in. I broke out any individual class into its own file, and some of the library got reorganized because of that. This was mostly a syntax and organization change, with almost no functionality change. However, there's a limitation where you can't use However, I've realized we should be using I also renamed MediaTechController to Tech and the /media/ directory to /tech/ for clarity. But I also aliased Tech to MediaTechController so old techs won't break on that alone. I have not converted over all static methods, and not sure if we need to. Also, this and #2015... |
|
||
export default BigPlayButton; | ||
Button.registerComponent('BigPlayButton', BigPlayButton); | ||
export default BigPlayButton; |
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.
Am I reading this right that this is removing the trailing newline? I won't comment on every instance of this, but I feel as strongly about a trailing newline as I do about removing empty white space.
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.
Which is to say, very strongly. I'm pretty sure revolutions have been fought over the need for trailing newlines.
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.
Ha, I guess that's what it is. And I guess Atom isn't configured to keep those for me. I'll update it.
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.
Looks like it's enabled by default now, which would be weird if you're not seeing it.
This isn't a problem with the PR itself, obviously, but this diff is useless. |
let parentOptions = parent.options(); | ||
let children = parentOptions['children']; | ||
|
||
let handleAdd; |
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.
Why is this defined outside of the if
block if it's only used within? The only other path is the else, which could easily be changed to Lib.obj.each(children, null);
and honestly be more readable.
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.
Wait a second, think the diff was screwing with me there, it doesn't look like there's any reason to define this outside of the if
block.
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.
It made sense when it was vars. The if block used children which was defined with parentOptions which was defined with parent. I didn't actually touch this part but I've cleaned it up for you. :)
Yeah, the diff is bad. I could have avoided moving files for the first pass, but even in the files I didn't move, the complete restructuring of the class makes it impossible to tell what exactly changed. |
It's a lot better if you switch to the split diff, so that's what I'm using now. |
this.el_ = null; | ||
}; | ||
// Remove element from DOM | ||
if (this.el_.parentNode) { |
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.
Should we use the #el()
method instead of the "private" var when just reading this (throughout the module)?
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 official Closure Library style is to use the private references everywhere internally so compiler can mangle them, and then export the methods for anything you want accessible externally. That's not always obvious for other contributors, and I also started to worry that people would start using the private properties externally after seeing internal code, but then on the other hand I think uglify has an option to mangle private props now if we wanted to keep that part of the file size savings.
Either way it's open for a change.
|
||
addRemoteTextTrack(options) { | ||
if (!this['featuresNativeTextTracks']) { | ||
return Tech.prototype.addRemoteTextTrack.call(this, options); |
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.
super
I'll take another pass tomorrow, but first pass showed a few things that can refactored to Just a note not necessarily related to this PR: things seem a bit inconsistent about when we use things like |
@@ -3,7 +3,7 @@ | |||
* | |||
*/ | |||
|
|||
import CoreObject from './core-object.js'; | |||
// import CoreObject from './core-object.js'; |
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.
remove if not needed.
I guess the punishment for having a crappy diff and forcing people to look at every line of code is you get to address every style problem from ever :) There's at least fewer than I'd expect. |
Updated with the super calls and cleanup changes mentioned. I've moved some not directly related discussions to their own issues. Otherwise the important bits here are done so going to merge this in so we can move forward. |
This is built on #1976 so the commit to look at is b7f6934An easier view of the changes here: mmcc#7
So far I just converted Component to an ES6 class, and then re-added
init
andextend
so that all the subclasses would still work (all tests are passing). After fully implementing this we would't have either of those methods anymore.Important notes
MyComponent.extend()
static method, for all components, techs, etc., breaking that major API. We can't automatically add the static extend() method in the ES6 inheritance process like we're doing now for every sub class. We can manually add it for each component if we think that's important for backwards compatibility, maybe at least for techs. Otherwise we should introduce avideojs.extends/videojs.inherits
for external projects that don't use ES6 classes. We can even just use Node's.Please let me know any thoughts on this.