Skip to content

Remove lodash.omit#478

Merged
eddywashere merged 2 commits intoreactstrap:masterfrom
balloob:omit-omit
Jun 27, 2017
Merged

Remove lodash.omit#478
eddywashere merged 2 commits intoreactstrap:masterfrom
balloob:omit-omit

Conversation

@balloob
Copy link
Copy Markdown
Contributor

@balloob balloob commented Jun 27, 2017

When I was analyzing the source map for #474 I noticed that the package lodash.omit takes up 9.29kB!

Looking at the source, we can see that it pulls in a lot of dependent lodash functions.

I've added our own omit function to utils.js, which minifies to 105 bytes, and works with the use cases that we provide to it:

export function omit(obj, omitKeys) {
  const result = {};
  Object.keys(obj).forEach(key => {
    if (omitKeys.indexOf(key) === -1) {
      result[key] = obj[key];
    }
  });
  return result;
}

This saves the user ~9kB.

Comment thread src/utils.js
*/
export function omit(obj, omitKeys) {
const result = {};
Object.keys(obj).forEach(key => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it worth having a null/undefined check before this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right now we have the following 2 ways that omit is used:

omit(this.props, ['some', 'keys', 'to', 'omit'])

omit(this.props, Object.keys(propTypes))

That means that both the object and the keys to omit are always passed in.

Right now if you pass in null for either parameter, it will blow up because it will execute Object.keys(null) or null.indexOf(key).

Would you expect obj or omitKeys to be able to be null ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking of potential of obj to be null, but after a second I agree that it is unnecessary.

@eddywashere eddywashere merged commit ba69f71 into reactstrap:master Jun 27, 2017
@eddywashere
Copy link
Copy Markdown
Member

I'd imagine most people already use a ton of lodash so this would be a minor increase in filesize. But for those not using all of it, this will be a big save. 👍

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.

3 participants