-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat: make overlays mutable #223
Conversation
@@ -89,7 +89,6 @@ | |||
"git add" | |||
], | |||
"README.md": [ | |||
"npm run docs:toc", |
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.
had to remove this as this errors out whenever a change to the readme is made
src/plugin.js
Outdated
@@ -301,6 +302,7 @@ videojs.registerComponent('Overlay', Overlay); | |||
* @param {Object} [options={}] | |||
*/ | |||
const plugin = function(options) { | |||
const self = this; |
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.
needed to be able to reference this
in the add
and remove
fns, not sure if this is the best way to be able to 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.
It's a fine practice, though I would suggest calling it something like player
as that's more meaningful. That way, further down the plugin, future developers don't need to wonder what self
refers to.
README.md
Outdated
@@ -18,6 +18,11 @@ Maintenance Status: Stable | |||
|
|||
- [Getting Started](#getting-started) | |||
- [Documentation](#documentation) | |||
- [API](#api) | |||
- [`player.overlay()`](#playeroverlay) | |||
- [`overlay.overlays`](#overlayoverlays) |
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.
Maybe this should be a getter, ex. getOverlays()
, rather than a property?
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.
Good point, will make that change now :)
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 would suggest calling it get()
to align with the other new methods.
README.md
Outdated
@@ -18,6 +18,11 @@ Maintenance Status: Stable | |||
|
|||
- [Getting Started](#getting-started) | |||
- [Documentation](#documentation) | |||
- [API](#api) | |||
- [`player.overlay()`](#playeroverlay) | |||
- [`overlay.overlays`](#overlayoverlays) |
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 would suggest calling it get()
to align with the other new methods.
src/plugin.js
Outdated
@@ -301,6 +302,7 @@ videojs.registerComponent('Overlay', Overlay); | |||
* @param {Object} [options={}] | |||
*/ | |||
const plugin = function(options) { | |||
const self = this; |
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's a fine practice, though I would suggest calling it something like player
as that's more meaningful. That way, further down the plugin, future developers don't need to wonder what self
refers to.
src/plugin.js
Outdated
item.el().parentNode.removeChild(item.el()); | ||
self.overlays_.splice(index, 1); | ||
} else { | ||
throw new Error('overlay is invalid and cannot be removed'); |
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'm not sure throwing is the right thing here. It may be better to use player.log.warn
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.
Changed the error throwing to be a log.warn 🥳
src/plugin.js
Outdated
* | ||
* @return The array of overlay objects currently used by the plugin | ||
*/ | ||
function getOverlays() { |
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.
As mentioned above, I think get
would be a better name here.
return { | ||
add, | ||
remove, | ||
get | ||
}; |
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.
Longer-term, we'll want to change this to be a class-based plugin, but this works for now! 👍
Description
Related Ticket
Currently, overlays cannot be added/removed individually - this change introduces the ability to add/remove overlays individually (customer request)
Specific Changes proposed
add
function for adding overlaysremove
function to remove individual overlaysRequirements Checklist