-
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
Tech registry #2782
Tech registry #2782
Changes from 5 commits
ec1d7e3
28e20f7
7c400bd
25f7d80
3d832d9
e0b9824
3437f8d
96b7879
c58e037
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -449,6 +449,46 @@ class Tech extends Component { | |
component instanceof Tech || | ||
component === Tech; | ||
} | ||
|
||
/** | ||
* Registers a Tech | ||
* | ||
* @param {String} name Name of the Tech to register | ||
* @param {Object} tech The tech to register | ||
* @static | ||
* @method registerComponent | ||
*/ | ||
static registerTech(name, tech) { | ||
if (!Tech.techs_) { | ||
Tech.techs_ = {}; | ||
} | ||
|
||
if (!Tech.isTech(tech)) { | ||
throw new Error(`Tech ${name} must be a Tech`); | ||
} | ||
|
||
Tech.techs_[name] = tech; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I'm thinking about it, should we do that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. In the case that we don't necessarily want to inherit from |
||
return tech; | ||
} | ||
|
||
/** | ||
* Gets a component by name | ||
* | ||
* @param {String} name Name of the component to get | ||
* @return {Component} | ||
* @static | ||
* @method getComponent | ||
*/ | ||
static getTech(name) { | ||
if (Tech.techs_ && Tech.techs_[name]) { | ||
return Tech.techs_[name]; | ||
} | ||
|
||
if (window && window.videojs && window.videojs[name]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like there should probably be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should it do if it isn't a tech? Component doesn't do that checking currently either and I basically just copied the code from there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not 100% sure on that - or that anything needs to be done, given more reflection. My original thinking was that if someone were to reach this with a value that wasn't a tech, but was available on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided not to do anything here but throw if trying to register a non-tech as a tech. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
log.warn(`The ${name} tech was added to the videojs object when it should be registered using videojs.registerTech(name, tech)`); | ||
return window.videojs[name]; | ||
} | ||
} | ||
} | ||
|
||
/* | ||
|
@@ -649,4 +689,5 @@ Tech.withSourceHandlers = function(_Tech){ | |
Component.registerComponent('Tech', Tech); | ||
// Old name for Tech | ||
Component.registerComponent('MediaTechController', Tech); | ||
Tech.registerTech('Tech', Tech); | ||
export default Tech; |
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.
This would mean that the tech was only registered as a component? I think it's worth a comment above this to remind ourselves to one day get rid of 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.
Yep, this is basically to support the now-deprecated feature of registering techs as components.
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'll add a comment.