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

[breaking] when NODE_ENV is production, export mocks instead of real validators #5

Merged
merged 1 commit into from
Jan 9, 2017

Conversation

ljharb
Copy link
Owner

@ljharb ljharb commented Jan 7, 2017

It'd be ideal to test locally and ensure this is working as intended.

Copy link
Collaborator

@lencioni lencioni left a comment

Choose a reason for hiding this comment

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

It looks like you forgot to add the build/mocks file

@lencioni
Copy link
Collaborator

lencioni commented Jan 7, 2017

It would be good to add some information about this in the readme.

Copy link
Collaborator

@lencioni lencioni left a comment

Choose a reason for hiding this comment

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

Oh, I see the mocks are in master now. Still would be good to discuss this in the readme.

@ljharb
Copy link
Owner Author

ljharb commented Jan 7, 2017

Yes, sorry, I'd pushed the mocks to master prior. Good point, I'll update the readme before merging this PR.

@ljharb
Copy link
Owner Author

ljharb commented Jan 9, 2017

Readme updated.

@@ -25,6 +25,9 @@ Custom React PropType validators that we use at Airbnb. Use of [airbnb-js-shims]
- `uniqueArrayOf`: `uniqueArray`, with a type validator applied. Like `PropTypes.arrayOf`, but with uniqueness.
- `withShape`: takes a PropType and a shape, and allows a shape to be enforced on any non-null/undefined value.

## Production
Since `PropTypes` are typically not included in production builds of React, this library’s functionality serves no useful purpose. As such, when the `NODE_ENV` environment variable is `"production"`, instead of exporting the implementations of all these prop types, we export mock functions - in other words, something that ensures that no exceptions are thrown, but does no validation. When environment variables are inlined (via a browserify transform or webpack plugin), then tool like webpack or uglify are able to determine that only the mocks will be imported - and can avoid including the entire implementations in the final bundle that is sent to the browser. This allows for a much smaller ultimate file size, and faster in-browser performance, without sacrificing the benefits of `PropTypes` themselves.
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: tool -> tools

Copy link
Owner Author

Choose a reason for hiding this comment

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

thanks, fixed

@ljharb ljharb merged commit 50771e6 into master Jan 9, 2017
@ljharb ljharb deleted the node_env branch January 9, 2017 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants