From 1e333a09710c064b8393a14d421b0ea23a73ada1 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Tue, 20 Dec 2016 00:29:59 +0530 Subject: [PATCH] Update url.pushTo and url.replaceTo update only on dev. In order to warn the user, now we are using a warn function which is located in the lib/utils module. --- lib/app.js | 5 +++-- lib/css.js | 5 ++--- lib/utils.js | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 lib/utils.js diff --git a/lib/app.js b/lib/app.js index fe419c8a8885b..126ed594f24a2 100644 --- a/lib/app.js +++ b/lib/app.js @@ -1,5 +1,6 @@ import React, { Component, PropTypes } from 'react' import { AppContainer } from 'react-hot-loader' +import { warn } from './utils' export default class App extends Component { static childContextTypes = { @@ -67,7 +68,7 @@ function propsToState (props) { back: () => router.back(), push: (url, as) => router.push(url, as), pushTo: (href, as) => { - console.warn(`Warning: 'url.pushTo()' is deprecated. Please use 'url.push()' instead.`) + warn(`Warning: 'url.pushTo()' is deprecated. Please use 'url.push()' instead.`) const pushRoute = as ? href : null const pushUrl = as || href @@ -75,7 +76,7 @@ function propsToState (props) { }, replace: (url, as) => router.replace(url, as), replaceTo: (href, as) => { - console.warn(`Warning: 'url.replaceTo()' is deprecated. Please use 'url.replace()' instead.`) + warn(`Warning: 'url.replaceTo()' is deprecated. Please use 'url.replace()' instead.`) const replaceRoute = as ? href : null const replaceUrl = as || href diff --git a/lib/css.js b/lib/css.js index 18464ecf845be..0714d6460c009 100644 --- a/lib/css.js +++ b/lib/css.js @@ -1,8 +1,7 @@ +import { warn } from './utils' const css = require('glamor') -if (process.env.NODE_ENV !== 'production') { - console.error('Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.') -} +warn('Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.') /** * Expose style as default and the whole object as properties diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 0000000000000..55e0c29694fc4 --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,5 @@ +export function warn (message) { + if (process.env.NODE_ENV !== 'production') { + console.error(message) + } +}