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

Combined components.js and component.js #4

Closed
wants to merge 6 commits into from

Conversation

heff
Copy link

@heff heff commented Dec 5, 2014

What do you think of this direction? I like it because it combines all the component logic into one file and takes the require out of the component.addChild function, which is what was creating the circular dependency.

Also I changed it so components get registered in the file where they're created. I like that because it's more like exports, instead of having to look in another file for which components can be reference by name (i.e. we could have components that are only used inside other components and don't get registered for use elsewhere).

We could also combine the register and extend into one line, if that's preferable.

Button = Component.registerComponent('Button', Component.extend({});

I guess we could also shorten it to Component.register() if that's still clear enough.

(I have not run tests on this)

@heff
Copy link
Author

heff commented Dec 6, 2014

I added videojs.getComponent methods and also exported the components in the old way. With these changes it's looking to me like we could pull this in even before 5.0. What are the main API breaking changes you've run into?

@@ -374,7 +372,7 @@ Component.prototype.addChild = function(child, options){
// If there's no .player_, this is a player
// Closure Compiler throws an 'incomplete alias' warning if we use the vjs variable directly.
// Every class should be exported, so this should never be a problem here.
component = new components[componentClass](this.player_ || this, options);
component = new Component.components[componentClass](this.player_ || this, options);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use getComponent here as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, we should be.

@gkatsev
Copy link
Owner

gkatsev commented Dec 6, 2014

@heff not having the components available as vjs.{{ComponentName}} is a breaking change.

@gkatsev
Copy link
Owner

gkatsev commented Dec 6, 2014

But otherwise, this looks really good.

@heff
Copy link
Author

heff commented Dec 6, 2014

Awesome. On a side not, as I'm going through the code base, the new structure feels a lot better.

module.exports.registerComponent = Component.registerComponent;

// Expose but deprecate the window[componentName] method for accessing components
lib.obj.each(Component.components, function(name, component){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the piece I was thinking could make it backwards compatible. See any issues with it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, so, all the current components would still be exposed on the videojs object?
We should also double check to make sure we aren't running into circular module inclusion.

@heff
Copy link
Author

heff commented Dec 16, 2014

I added the global module for accessing the window.

There shouldn't be any more circular dependencies now that component and components live together, and the components aren't ever used internally from the main object. This seems like a safe way to make it backwards compatible to me.

Once this looks good to you can you accept the pull request?

@gkatsev
Copy link
Owner

gkatsev commented Dec 16, 2014

Would you be able to also swap out the references to document with global/document?

@heff
Copy link
Author

heff commented Dec 16, 2014

Done with the document change. This all probably needs a rebasing sooner than later. Also closure compiler probably won't ever play nice with this, so we should switch to uglify in this or before hand.

Also, npm build doesn't do anything for me. What am I missing?

@@ -12,6 +12,8 @@
"undef" : true,
"laxbreak" : true,
"predef" : [
"document",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need that here now that we're making specific variables for doc and window?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah...jshint was yelling at me for redefining read-only vars.

@gkatsev
Copy link
Owner

gkatsev commented Dec 17, 2014

@heff I was confused for a second but then realized that you need to run it as npm run build. Basically, npm has a few built-in scripts like start and test but you can add whatever other script you want it to run. I added build. And to run it you need to invoke it via run-scripts, or just run for short.

@heff
Copy link
Author

heff commented Dec 17, 2014

Aha! Thank you.

@heff heff mentioned this pull request Mar 10, 2015
@gkatsev gkatsev closed this Aug 12, 2015
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.

2 participants