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

Object Type-Detection and Replacing object.assign #3757

Merged
merged 4 commits into from
Dec 2, 2016

Conversation

misteroneill
Copy link
Member

@misteroneill misteroneill commented Nov 7, 2016

Description

This pulls in a few updates I made to utils/obj from #3690 so they can be more isolated and make it into 5.x.

Perhaps more impactful, this removes object.assign as a dependency and re-implements the functionality we were depending on. This change reduces the minified size of Video.js by over 2KB off the gzipped size.

Specific Changes proposed

  • Introduce the isObject method: essentially, typeof x === 'object' with a null check.
  • Introduce the isPlain method: taken from mergeOptions, this does a reasonable job at identifying plain objects.
  • Remove object.assign.

Requirements Checklist

  • Feature implemented / Bug fixed
  • Reviewed by Two Core Contributors

@misteroneill misteroneill added the patch This PR can be added to a patch release. label Nov 7, 2016
* @return {Boolean}
*/
export function isObject(value) {
return !!value && typeof value === 'object';
Copy link
Member

Choose a reason for hiding this comment

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

this directly contradicts the jsdoc comment.

Copy link
Member

Choose a reason for hiding this comment

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

I guess it doesn't but the line 63 is a bit unclear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will clarify! 👍

* @return {Boolean}
*/
export function isPlain(value) {
return isObject(value) && value.constructor === Object;
Copy link
Member

Choose a reason for hiding this comment

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

why remove the toString check.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think a copy-paste mistake.

@brandonocasey
Copy link
Contributor

brandonocasey commented Nov 8, 2016

Should mergeOptions just use this new function? (allows us to remove lodash-compat/object/merge/, another large dependency)

@misteroneill
Copy link
Member Author

@brandonocasey Yeah, I do think we ought to not have the partial lodash dependency there, but that function is a bit more complex in that it's recursive and has the "customizer" thing; so, it's a bit more prone to unforeseen breaking changes. That said, I do plan to take a stab at it.

@brandonocasey
Copy link
Contributor

SPACE SAVING AHOY! 🚀

*
* @return {Function}
*/
export const throttle = function(fn, wait) {
Copy link
Member

Choose a reason for hiding this comment

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

can this be done in a separate PR?

* @param {Object} value
* @return {Boolean}
*/
export function isPlain(value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

My next PR is eliminating lodash as a dependency. It's not worth the extra weight of including lodash just for this.

* @param {Object} value
* @return {Boolean}
*/
export function isObject(value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be better to just use https://lodash.com/docs/4.16.6#isObject?

Copy link
Member Author

Choose a reason for hiding this comment

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

My next PR is eliminating lodash as a dependency. It's not worth the extra weight of including lodash just for this.

@misteroneill misteroneill mentioned this pull request Nov 8, 2016
2 tasks
@gkatsev gkatsev modified the milestone: 5.14 Nov 9, 2016
@gkatsev gkatsev merged commit 8f16de2 into videojs:master Dec 2, 2016
@misteroneill misteroneill deleted the object-madness branch December 2, 2016 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed patch This PR can be added to a patch release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants