-
Notifications
You must be signed in to change notification settings - Fork 101
Throw appropriate errors for invalid instantiation. #113
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
base: master
Are you sure you want to change the base?
Conversation
ljharb
left a comment
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.
Thanks, this seems like a great enhancement.
src/ThemedStyleSheet.js
Outdated
|
|
||
| function invalidMethodError(invalidMethodName) { | ||
| return new TypeError(` | ||
| react-with-styles internal error: An invalid Style Interface has been registed. |
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.
registered
46ab866 to
1cec658
Compare
src/ThemedStyleSheet.js
Outdated
| } | ||
|
|
||
| function resolve(...styles) { | ||
| validateStyleInterface(); |
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.
create and resolve are pretty hot codepaths, so I'd like to avoid as much work as possible here. What do you think about wrapping all of these validate functions in something like
if (process.env.NODE_ENV !== 'production') {
...
}?
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.
I did some benchmarks of the change and didn't notice a difference between the typeof changes and the environment checks. If it matters, not sure on your environment support, but this would also assume/restrict the usage of this to a certain environment, without doing a null check on process and process.env. A babel plugin/webpack would probably simplify the check so it would definitely be better than not having it though.
What are your thoughts on an unimplemented function for the checks? It could get replaced on register, and we would no longer need to check each time create/resolve are called. This would add some complexity to readability though.
I would say the best two options in terms of performance are using the environment check you mentioned or the unimplemented function. What would you prefer?
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.
The environment checks can be compiled out by the app's build process, so it would be as if the code is deleted.
|
Thanks for the PR! |
Throw appropriate errors if a Style Interface has not been registered or an invalid Style Interface has been registered. Throw an appropriate error if a Theme has not been registered. Resolves: airbnb#102
1cec658 to
dc0011d
Compare
|
@dmiller9911 sorry I lost track of this PR. I'd still love to get this merged in, but it seems that some merge conflicts have popped up. Could you please rebase this onto latest master and let me know when it is ready again? |
Throw appropriate errors if a Style Interface has not been registered or an invalid Style Interface has been registered.
Throw an appropriate error if a Theme has not been registered.
Resolves: #102