1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

display deprecation warning only when method was called (#462)

This commit is contained in:
Naoyuki Kanezawa 2016-12-22 03:43:31 +09:00 committed by Guillermo Rauch
parent fe962b12de
commit 2a29bf6242
3 changed files with 25 additions and 3 deletions

View file

@ -31,5 +31,5 @@ const headManager = new HeadManager()
const container = document.getElementById('__next')
const appProps = { Component, props, router, headManager }
if (ids) rehydrate(ids)
if (ids && ids.length) rehydrate(ids)
render(createElement(App, appProps), container)

View file

@ -1,7 +1,11 @@
import { warn } from './utils'
import { deprecated } from './utils'
const css = require('glamor')
warn('Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.')
for (const [k, v] of Object.entries(css)) {
if (typeof v === 'function') {
css[k] = deprecated(v, 'Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.')
}
}
/**
* Expose style as default and the whole object as properties

View file

@ -3,3 +3,21 @@ export function warn (message) {
console.error(message)
}
}
export function deprecated (fn, message) {
if (process.env.NODE_ENV === 'production') return fn
let warned = false
const newFn = function (...args) {
if (!warned) {
warned = true
console.error(message)
}
return fn.apply(this, args)
}
// copy all properties
Object.assign(newFn, fn)
return newFn
}