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

feat: make overlays mutable #223

Merged
merged 12 commits into from
Jun 15, 2023
Merged

feat: make overlays mutable #223

merged 12 commits into from
Jun 15, 2023

Conversation

usmanonazim
Copy link
Contributor

@usmanonazim usmanonazim commented Jun 8, 2023

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

  • New add function for adding overlays
  • New remove function to remove individual overlays
  • Updated docs to reflect the above changes

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Unit Tests updated or fixed
    • Docs/guides updated
  • Reviewed by Two Core Contributors

@@ -89,7 +89,6 @@
"git add"
],
"README.md": [
"npm run docs:toc",
Copy link
Contributor Author

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;
Copy link
Contributor Author

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

Copy link
Member

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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 :)

Copy link
Member

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)
Copy link
Member

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;
Copy link
Member

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');
Copy link
Member

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.

Copy link
Contributor Author

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() {
Copy link
Member

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.

@usmanonazim usmanonazim merged commit a6c0353 into main Jun 15, 2023
@usmanonazim usmanonazim deleted the feat/overlays-mutable branch June 15, 2023 15:34
Comment on lines +412 to +416
return {
add,
remove,
get
};
Copy link
Member

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! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants