Comments (9)
sounds legit
from seamless-immutable.
Agreed. Those constraints are mostly not supposed to be runtime errors and should be catch in development.
from seamless-immutable.
I'm interested in working on this but I am a bit unsure on how to pass the flag to the library?
Would you use the export code:
if (typeof module === "object") {
module.exports = Immutable;
} else if (typeof exports === "object") {
exports.Immutable = Immutable;
} else if (typeof window === "object") {
window.Immutable = Immutable;
} else if (typeof global === "object") {
global.Immutable = Immutable;
}
To do different things depending on the environment, like (using global and window as examples):
var prodMode = false;
if (typeof module === "object") {
module.exports = Immutable;
} else if (typeof exports === "object") {
exports.Immutable = Immutable;
} else if (typeof window === "object") {
window.Immutable = Immutable;
prodMode = window.SEAMLESS_PROD_MODE === true;
} else if (typeof global === "object") {
global.Immutable = Immutable;
prodMode = global.SEAMLESS_PROD_MODE === true;
}
Or is there a better way?
from seamless-immutable.
What about a method on Immutable that looks like Immutable.setProduction(true/false)
, and then have people explicitly enable it and define their own way of detecting production mode?
from seamless-immutable.
Awsesome!
The best practice I've seen (which is what React does) is to make it envify-friendly.
Basically you do this:
if (process.env.NODE_ENV === "development") {
// do some stuff we wouldn't do in prod mode
}
...then run envify
on it twice, once with {NODE_ENV: "development"}
and once with {NODE_ENV: "production"}
to get two output files: seamless-immutable.development.js
and seamless-immutable.production.min.js
In the development build, envify
will replace the above with this:
if ("development" === "development") {
// do some stuff we wouldn't do in prod mode
}
....whereas in the production build, it will instead replace it with this:
if ("production" === "development") {
// do some stuff we wouldn't do in prod mode
}
Uglify will then see that this conditional will always fail and will strip this code out entirely, meaning the production build will not only avoid adding the extra attributes, it won't even run any conditionals to tell if it's in prod mode!
This implicitly means we'd need to introduce a build process to generate the two different files for library consumers.
from seamless-immutable.
I've been wondering about how to do this kind of thing for ever. Very nice solution. No non-JS syntax needed.
Alan
On Mar 19, 2015, at 2:27 PM, Richard Feldman [email protected] wrote:
Awsesome!
The best practice I've seen (which is what React does) is to make it envify-friendly.
Basically you do this:
if (process.env.NODE_ENV === "development") {
// do some stuff we wouldn't do in prod mode
}
...then run envify on it twice, once with {NODE_ENV: "development"} and once with {NODE_ENV: "production"} to get two output files: seamless-immutable.development.js and seamless-immutable.production.min.jsIn the development build, envify will replace the above with this:
if ("development" === "development") {
// do some stuff we wouldn't do in prod mode
}
....whereas in the production build, it will instead replace it with this:if ("production" === "development") {
// do some stuff we wouldn't do in prod mode
}
Uglify will then see that this conditional will always fail and will strip this code out entirely, meaning the production build will not only avoid adding the extra attributes, it won't even run any conditionals to tell if it's in prod mode!This implicitly means we'd need to introduce a build process to generate the two different files for library consumers.
—
Reply to this email directly or view it on GitHub.
from seamless-immutable.
Should we then move seamless-immutable.js
to a src
directory to indicate that it shouldn't be used directly? And place the output files of envify
in the root?
from seamless-immutable.
That makes sense to me. Let's not check in changes to the compiled files on every commit, though, as that will make the diffs miserable.
Instead just leave them out of normal commits, and once per release I'll include updated compiled files in the commit that bumps the version number.
Sound good?
from seamless-immutable.
Sounds good!
from seamless-immutable.
Related Issues (20)
- Make `without` support removing item from an array HOT 4
- how to use splice like array HOT 1
- Internet Explorer tests are failing HOT 4
- Issue regarding null values HOT 5
- Why are IE tests failing? HOT 3
- How to apply splice with seamless-immutable? HOT 1
- Merge does not work with class instances
- __immutable_invariants_hold is enumerable on Edge HOT 1
- Garbage collector features? HOT 1
- Performance characteristics
- Any difference with deepCopy? HOT 1
- [types] Mixin not applied to nested objects HOT 1
- flatMap not working HOT 2
- Add documentation for merge mode
- Files not being replaced on a deep merge
- Fails on IE 11 HOT 1
- TypeError: Object(...) is not a function HOT 1
- Lodash Vulnerability Problem
- Is the project still maintained? HOT 2
- immutable object causes rapid memory growth HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seamless-immutable.