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

Consider switching to tiny-invariant or own invariant function #156

Closed
davidje13 opened this issue Apr 19, 2020 · 0 comments · Fixed by #158
Closed

Consider switching to tiny-invariant or own invariant function #156

davidje13 opened this issue Apr 19, 2020 · 0 comments · Fixed by #158

Comments

@davidje13
Copy link

The use of invariant pulls in loose-envify which in turn pulls in js-tokens. This has little consequence when used with React since it already uses them, but when used outside React these are relatively heavy dependencies (as already noted in #126)

Also as noted in #83 (comment), this way of writing invariant checks can cause significant performance penalty, since the error message arguments are always evaluated (unless combined with a compile-time code rewriter, but this project doesn't do that)

I would like to suggest at a minimum switching to use tiny-invariant, which is compatible with invariant except that it does not provide the %s formatting. The library still works with compile-time code rewriters and does not have any dependencies (and is tiny itself).

And better would be to also run the code through a transformer as part of the build process so that the built code only evaluates error arguments if the condition fails (or see my suggested improvement to tiny-invariant alexreardon/tiny-invariant#62 if a build-time transformation is not desirable).

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 a pull request may close this issue.

1 participant