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

Remove lodash as a production dependency #1122

Merged

Conversation

calebmer
Copy link
Contributor

@calebmer calebmer commented Jan 4, 2017

Removes lodash as a production dependency to reduce size. Many of the utilities were inlined such as isString and isNumber. For more involved utilities, I created a smaller version in src/util and added tests. These utilities include isEqual, cloneDeep, and assign. The smaller version in src/util do not cover all the edge cases that there Lodash equivalents cover. Most notably they do not handle circular objects gracefully (let me know if this is important).

Removing Lodash takes us from 136 kB to 94 kB ungzipped and 35.3 kB to 24.5 kB gzipped. Roughly a 30% decrease in size 🎉

  • Make sure all of the significant new logic is covered by tests
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change
  • Add your name and email to the AUTHORS file (optional)

@apollo-cla
Copy link

@calebmer: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@zol zol added the in progress label Jan 4, 2017
@@ -435,7 +432,7 @@ export default class ApolloClient {
}

// ensure existing store has apolloReducer
if (isUndefined(reduxRootSelector(store.getState()))) {
if (reduxRootSelector(store.getState()) === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The better way to do this is typeof x === 'undefined' right? Since undefined isn't a keyword and could be reassigned.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's right in theory. I wonder if it's ever made a difference for anyone in practice?

Copy link
Contributor

Choose a reason for hiding this comment

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

IDK maybe it's just one of those old JavaScript trivia things that nobody cares about anymore then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's still a valid thing to change. The only reason I didn't do that in the first place is because lodash implements it this way: https://github.com/lodash/lodash/blob/4.17.4/lodash.js#L12212

…but they do also have this which I missed: https://github.com/lodash/lodash/blob/4.17.4/lodash.js#L12

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, interesting (L12). I wonder why they did that instead of using typeof.

@helfer helfer force-pushed the refactor/remove-lodash branch from a816598 to 8996670 Compare January 5, 2017 05:02
@helfer
Copy link
Contributor

helfer commented Jan 5, 2017

Great stuff @calebmer!

I'd say that's enough low-hanging fruit so we can close the other issue. Except maybe that we want to get rid of whatwg-fetch as well for other reasons.

img

@helfer helfer merged commit 95ca7b6 into apollographql:zero-decimal-six Jan 5, 2017
@helfer helfer removed the in progress label Jan 5, 2017
@stubailo
Copy link
Contributor

stubailo commented Jan 5, 2017

Gosh guys this is incredible. Great work @calebmer!

@stubailo
Copy link
Contributor

stubailo commented Jan 5, 2017

BTW other low-hanging fruit: getFromAST and storeUtils are duplicated in apollo-client and graphql-anywhere both.

@calebmer calebmer deleted the refactor/remove-lodash branch January 5, 2017 17:42
@calebmer calebmer mentioned this pull request Jan 5, 2017
3 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants