invariant
Advanced tools
Comparing version 1.0.2 to 2.0.0
/** | ||
* BSD License | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* For Flux software | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* Copyright (c) 2014, Facebook, Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name Facebook nor the names of its contributors may be used to | ||
* endorse or promote products derived from this software without specific | ||
* prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @providesModule invariant | ||
*/ | ||
@@ -48,8 +25,10 @@ | ||
var __DEV__ = process.env.NODE_ENV !== 'production'; | ||
var invariant = function(condition, format, a, b, c, d, e, f) { | ||
// if (process.env.NODE_ENV !== 'production') { | ||
// if (format === undefined) { | ||
// throw new Error('invariant requires an error message argument'); | ||
// } | ||
// } | ||
if (__DEV__) { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
} | ||
@@ -56,0 +35,0 @@ if (!condition) { |
{ | ||
"name": "invariant", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "invariant", | ||
"licence": "BSD", | ||
"author": "Andres Suarez <zertosh@gmail.com>", | ||
"main": "invariant.js", | ||
"files": [ | ||
"README.md", | ||
"invariant.js", | ||
"browser.js" | ||
], | ||
"repository": { | ||
@@ -13,11 +17,18 @@ "type": "git", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "NODE_ENV=production mocha && NODE_ENV=development mocha" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^1.21.4" | ||
"mocha": "^2.1.0" | ||
}, | ||
"engines": { | ||
"node": ">=0.10" | ||
}, | ||
"main": "invariant.js", | ||
"browser": "browser.js", | ||
"browserify": { | ||
"transform": [ | ||
"envify" | ||
] | ||
} | ||
} |
@@ -5,22 +5,18 @@ # invariant # | ||
**Modifications:** In the original code, the "invariant message" (`format`) is expected to not be `undefined` when `__DEV__` is `true`. `__DEV__` is transformed during the build process to `process.env.NODE_ENV !== 'production'`. Because `process.env` is not a regular object, but rather an object with getters to the environment, it has performance implications. So, to mitigate, the code has been commented out and `__DEV__` has been replaced with `process.env.NODE_ENV !== 'production'` for clarity. | ||
### Usage | ||
_Original_:_ | ||
```js | ||
if (__DEV__) { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
} | ||
```sh | ||
npm install envify invariant | ||
``` | ||
_Modified:_ | ||
```js | ||
// if (process.env.NODE_ENV !== 'production') { | ||
// if (format === undefined) { | ||
// throw new Error('invariant requires an error message argument'); | ||
// } | ||
// } | ||
var invariant = require('invariant'); | ||
``` | ||
Additional information: [Server rendering is slower with npm react #812](https://github.com/facebook/react/issues/812) | ||
#### Browser | ||
Use [`browserify`](https://github.com/substack/node-browserify) in conjunction with [`envify`](https://github.com/hughsk/envify). **envify must be installed separately since it is not explicitly listed as a dependency in the `package.json`** (because not everyone will use `invariant` on the browser). | ||
#### Node | ||
Just use it. The node version is optimized around the performance implications of accessing `process.env`. The value of `process.env.NODE_ENV` is cache, and repeatedly used instead of querying `proces.env`. See [Server rendering is slower with npm react #812](https://github.com/facebook/react/issues/812) |
4684
95
22