-
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
fix: copy basic plugin properties onto the wrapper #4100
Conversation
src/js/plugin.js
Outdated
@@ -312,6 +312,9 @@ class Plugin { | |||
if (name !== BASE_PLUGIN_NAME) { | |||
if (Plugin.isBasic(plugin)) { | |||
Player.prototype[name] = createBasicPlugin(name, plugin); | |||
Object.keys(plugin).forEach(function(prop) { | |||
Player.prototype[name][prop] = plugin[prop]; | |||
}); |
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 feel like this belongs in the createBasicPlugin
function.
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 thought that too at first, but Player.prototype[name]
does not exist until we get the return value from createBasicPlugin
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.
If we really want it in createBasicPlugin, then we have to do the Player.prototype[name]
assign in there as well. I don't see any problems with that. Thoughts?
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.
couldn't it just copy the props from plugin
onto the instance
that createBasicPlugin
returns`?
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.
basic plugins don't have to return an instance though
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.
createBasicPlugin
is a function that returns a function. It's a bit confusing.
But instance
is inside the returned function, you'd want to do the property copying in the outer arrow function instead.
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 almost thought just now that createBasicPlugin
initialized basic plugins when called, but it doesn't do 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.
yeah calling the function that createBasicPlugin
returns on player is actually what initializes. The question is do we want to copy the methods that are on the plugin right away (this is how it used to work in 5.x)? or only after the plugin has been initialized.
Examples:
After initialization copy properties
var basic = () => {};
basic.VERSION = '9.9.9';
videojs.registerPlugin('basic', basic);
var player = videojs('some-id');
console.log(player.basic.VERSION);
// undefined
player.basic();
console.log(player.basic.VERSION);
// 9.9.9
Before initialization copy properties
var basic = () => {};
basic.VERSION = '9.9.9';
videojs.registerPlugin('basic', basic);
var player = videojs('some-id');
console.log(player.basic.VERSION);
// '9.9.9'
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 think we want to mimic current behavior, which means that we want to copy it before init and the plugin would need to handle things after init, like they do now.
2616d80
to
afa747c
Compare
3fa1de0
to
8caed38
Compare
Tests are fine except that IE8 is being weird on browserstack. |
Description
Copy basic plugin properties to prevent breaking older basic plugins
Requirements Checklist