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

hasClass() is available in dev but not in prod #1829

Closed
nwoltman opened this issue Jan 27, 2015 · 8 comments
Closed

hasClass() is available in dev but not in prod #1829

nwoltman opened this issue Jan 27, 2015 · 8 comments

Comments

@nwoltman
Copy link
Contributor

This is another Closure Compiler problem. videojs.Component.prototype.hasClass exists in the dev file but not in the prod file.

@mmcc
Copy link
Member

mmcc commented Jan 27, 2015

We're moving away from GCC for v5 (#1586), so this (and mangling issues like it) shouldn't be an issue in the near future. Just out of curiosity, what are you using hasClass for in the wild?

@nwoltman
Copy link
Contributor Author

I'm working on a plugin and I just need to check if the player is using native controls. I looked through the documentation and couldn't find a friendly way to do this so the only way I could see to check if the player is using native controls is to check the player's class for "vjs-using-native-controls".

Perhaps the player or the control bar could have a .isUsingNativeControls() method?

@nwoltman
Copy link
Contributor Author

@MMC I found what might be a better way to check if a player is using native controls:

video.techName === 'Html5' && video.tech.el().controls

Although it looks like the techName and tech properties are mangled by the GCC in the latest production version. Is there a "more correct" way to do this sort of check? I remember reading somewhere that the tech* properties shouldn't be used, but I don't see any other way to get this information.

@mmcc
Copy link
Member

mmcc commented Feb 1, 2015

Since we use class names so extensively for handling view state, I think using it for this makes a lot of sense. We consider checking the tech to be a quasi-bad practice (#1234), so I would discourage going that route.

That being said, I can think of a few other options that might work for you:

  • There's the usingNativeControls method. This is private for a reason, but I think using it as a getter in your case could make sense.
  • You could check the nativeControlsForTouch option. It has to be explicitly set to true for native controls to be used.

@nwoltman
Copy link
Contributor Author

nwoltman commented Feb 1, 2015

Ah I see. I had looked at the usingNativeControls method, but when I called it it returned undefined, so I wasn't sure that it was working properly. I guess that was just because it isn't initially set to false here.
That got me thinking though, shouldn't private properties like that be initialized in a constructor and not on the object's prototype since the value isn't being shared between different instances of the object?

@mmcc
Copy link
Member

mmcc commented Feb 1, 2015

Yeah, the undefined bit honestly threw me for a second when I checked to make sure it was exported. I would say we should change that, but since it's technically private I guess it shouldn't matter.

I'm not sure I follow the constructor / prototype bit, but I think there's a bit of confusion as to what we intend by private here. Other VJS classes internally need access to this, but it isn't intended to be used externally as we are here. Normally methods like this aren't exported by GCC and as such are actually private from the outside world, so this is a bit of a weird example.

@nwoltman
Copy link
Contributor Author

nwoltman commented Feb 1, 2015

Sorry, I should have been more specific. It is correct to have the usingNativeControls function on the object's prototype, but the usingNativeControls_ variable that that function uses doesn't make sense to be on the prototype. On this line where the value is set, a new property is actually being created on the object, so then you end up with two properties; one at this.usingNativeControls_ and one at player.Component.prototype.usingNativeControls_ (or this.__proto__.usingNativeControls_ if it's easier to think about that way).

@nwoltman
Copy link
Contributor Author

Fixed in 265ed0e

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants