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

Framework: Use warn module in place of react/lib/warn #787

Merged
merged 2 commits into from
Nov 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions client/lib/warn/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* Internal Dependencies
*/
var config = require( 'config' );
import config from 'config';

function warn() {
if ( config( 'env' ) !== 'production' ) {
try{
window.console.warn.apply( window.console, arguments );
} catch( e ) {}
}
let warn;
if ( config( 'env' ) !== 'production' && 'function' === typeof console.warn ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use also process.env.NODE_ENV !== 'production' and the block should be removed during compilation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can use also process.env.NODE_ENV !== 'production'

It's my understanding that we're not to use NODE_ENV and instead rely on the value specified in config, which is equal to the current environment's CALYPSO_ENV environment variable specified in the Dockerfile for each environment's build.

the block should be removed during compilation.

I'm not sure the uglifier is that smart. A common approach to achieve this is to use something like Webpack's DefinePlugin to replace occurrences of a text with false, which the uglifier would be smart enough to remove.

// 1. Variable comparison
var env = 'production';
if ( env !== 'production' ) {
    // Could be, but probably not removed by uglifier
}

// 2. Use `DefinePlugin` to replace `__DEV__` with `false`
if ( false ) {
    // Definitely removed by uglifier
}

Copy link
Contributor

Choose a reason for hiding this comment

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

NODE_ENV is set in during the build process and will replaced by 'production' !== 'production', which will be removed by uglifier.

warn = console.warn.bind( console );
} else {
warn = () => {};
}

module.exports = warn;
export default warn;
4 changes: 2 additions & 2 deletions shared/lib/formatting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External Dependencies
*/
var trim = require( 'lodash/string/trim' ),
warning = require( 'react/lib/warning' );
warn = require( 'lib/warn' );

/**
* Internal Dependencies
Expand All @@ -11,7 +11,7 @@ var decode = require( './decode-entities' );

function decodeEntities( text ) {
if ( text === undefined || text === false || text === null ) {
warning( false, 'Don\'t call `decodeEntities` with an `undefined`, `false`, or `null` value.' );
warn( 'Don\'t call `decodeEntities` with an `undefined`, `false`, or `null` value.' );
return text;
}

Expand Down