-
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
Break up utility functions into smaller libraries #2139
Conversation
Anyone know what might have changed with source maps recently? Travis is failing on them. |
Fixed source maps error by locking down grunt-browserify version to 3.5.1 (it's now at 3.8.0). Probably not good long term. (ping @forbesjo) |
@videojs/core-committers can I get someone to glance at this? Now would be a good time to merge it in to prevent big merge conflicts. It's probably most valuable to look at the commit messages. The code itself didn't get changes all that much, just got moved around. The next step is to switch the wildcard |
import document from 'global/document'; | ||
import window from 'global/window'; | ||
|
||
const USER_AGENT = window.navigator.userAgent; |
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.
export const USER_AGENT = ...
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.
USER_AGENT isn't used externally so I left it private.
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.
there are a few other uses of the user agent, should we change those to use browser.USER_AGENT
instead, maybe?
👍 lgtm |
Broke out bind, guid, and element data functions from Lib Separated out more dom functions in to dom.js Broke out URL functions into url.js Removed setLocalStorage since it wasn't being used Moved browser tests out of lib Moved log functions into their own file Removed trim() since it wasn't being used Moved formatTime into its own file Moved round into its own file and renamed roundFloat() Moved capitalize into its own file and renamed as toTitleCase() Moved createTimeRange into its own file Removed Lib.arr.forEach infavor of the native forEach Removed Lib.obj.create in favor of native Object.create (ES6-sham) Removed obj.each in favor of native Object.getOwnPropertyNames().forEach() Removed obj.merge and copy. Using lodash.assign instead. Replaced Lib.obj.isPlain with lodash.isPlainObject Removed Lib.obj.isArray in favor of the native Array.isArray Also removed the lib.js tests file as all tests have been moved or removed. Removed Lib.isEmpty in favor of !Object.getOwnPropertyNames().length Switched Util.mergeOptions and deepMerge to use new mergeOptions() Moved Lib.TEST_VID to Html5.TEST_VID Removed Lib references everywhere. Woo! Attempting to fix sourcemap test errors by setting grunt-browserify version Switched to object.assign from lodash.assign Removed unused 'inherits' dependency Reorganzied test files and added '.test' to file names Combined js/core.js and js/video.js Moved events.js into the utils directory
Looking over this now. We can always make new PRs if there's anything we want to change. As for the naming, we shouldn't do any special naming. From a functionality perspective, there shouldn't be a different between internal and external functions. However, I've seen styleguides that suggest (or require, eslint might be able to help with this, though, not sure) that the imports at the top of the file are grouped by where they're coming from. |
@@ -24,8 +24,11 @@ | |||
"style": "./dist/video-js.css", | |||
"dependencies": { | |||
"global": "^4.3.0", | |||
"lodash.clonedeep": "^3.0.0", | |||
"lodash.isplainobject": "^3.0.2", | |||
"lodash.merge": "^3.2.1", |
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.
is this package used anymore?
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, it's used in mergeOptions
Do we require es5-sham for other babelify things? If not, I think we should still make our own shims for Anyway, mostly minor stuff. Looks good! |
Yeah, so far the sham (as far as I know) is only needed for Object.create in the es6 classes. I'd also prefer to only need the shim, but I don't know how we'd make babel use our own Object.create shim. |
Yeah, if babel requires it, that's fine. We could theoretically make another transform that removes uses of |
@@ -0,0 +1,89 @@ | |||
import document from 'global/document'; |
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.
we should evaluate whether the built-in url module gives us everything we care about.
Hmm...that's an interesting idea. I'm on the fence of whether or not it's worth it. We'd still need to bundle the es5 shim with the html5 video shim, so I can't tell if that would remove complication or add more. @mmcc @dmlap, any other opinions on whether we should go that route to avoid needing the sham? |
I think I'd prefer a minimal shim for what we need if we can get away with it. I'm not an es5-sham expert though, so factor in this opinion is coming from a place of great ignorance. |
Getting started on this one but interested in feedback early on.
I've started by just breaking up lib into libraries (e.g. dom.js), and maintaining the
Dom.createEl
library object property style. The next piece will be determining how to pull in individual functions instead of the entire library.If you look at lodash modularized or npm dom the examples just have you name the function variable the same as simple function name.
I'm not super comfortable with that as a standard.
An example on the second one is Component createEl. Babel creates named functions for class methods and I wonder if the createEl named function for the method would overwrite the createEl that's been imported.
My best thoughts are finding some common prefix for functions that are imported.
I'm not in love with any of those options but could live with any of them.
Anyone seen or used better options? Or are most people fine with the simple variable names.