Skip to content

Conversation

@dmiller9911
Copy link

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

Copy link
Collaborator

@ljharb ljharb left a 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.


function invalidMethodError(invalidMethodName) {
return new TypeError(`
react-with-styles internal error: An invalid Style Interface has been registed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

registered

}

function resolve(...styles) {
validateStyleInterface();
Copy link
Collaborator

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') { ... }

?

Copy link
Author

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?

Copy link
Collaborator

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.

@lencioni
Copy link
Collaborator

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
@lencioni
Copy link
Collaborator

lencioni commented Jul 3, 2018

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants