paldepind / union-type

A small JavaScript library for defining and using union types.
MIT License
477 stars 28 forks source link

Remove runtime type checks for production #16

Closed alexeygolev closed 8 years ago

alexeygolev commented 9 years ago

Really nice lib! I thought it might be nice to wrap the validation logic into if(process.env.NODE_ENV!=="production"). This way the lib will be super light in production and additional type checking features could be introduce for development id needed.

paldepind commented 9 years ago

This is a great idea. Instead of just doing if(process.env.NODE_ENV!=="production") to avoid the checking it might be nicer to conditionally define the function so that the type checking is completely left out.

alexeygolev commented 9 years ago

Fair enough. The condition will still be env I assume?

paldepind commented 9 years ago

@alexeygolev Please take a look at the last commit. If it looks good to you I'll push it to npm.

alexeygolev commented 9 years ago

@paldepind Dead code elimination can't figure it out:) We are still going to have all that validation code in production:) My idea was to eliminate it completely... To do this we need to actually wrap pieces of code into if(process.env.NODE_ENV!=="production"). This way the uglyfier will see if(false) and just remove it from the output on the build stage. This way we reduce the footprint of the library in addition to disabling the validators. Thoughts?

paldepind commented 9 years ago

Oh. You mean if one uses something like envify?

alexeygolev commented 9 years ago

I use webpack which does the same kind of think as envify does. React uses the same trick for their warning messages. It lets you be quite verbose for development environments but remove it completely for production. I'm not sure if you find it useful though so the PR is more to illustrate the case)