Skip to content

Commit 63b89f3

Browse files
committed
Only warn once for deprecations
1 parent 2e862ec commit 63b89f3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

modules/routerWarning.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import warning from 'warning'
22

3+
let warned = {}
4+
35
export default function routerWarning(falseToWarn, message, ...args) {
6+
// Only issue deprecation warnings once.
7+
if (message.indexOf('deprecated') !== -1) {
8+
if (warned[message]) {
9+
return
10+
}
11+
12+
warned[message] = true
13+
}
14+
415
message = `[react-router] ${message}`
516
warning(falseToWarn, message, ...args)
617
}
18+
19+
export function _resetWarned() {
20+
warned = {}
21+
}

tests.webpack.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import expect from 'expect'
55

6+
import { _resetWarned } from './modules/routerWarning'
7+
68
beforeEach(() => {
79
expect.spyOn(console, 'error').andCall(msg => {
810
for (const about of console.error.expected) {
@@ -27,6 +29,7 @@ afterEach(() => {
2729
})
2830

2931
console.error.restore()
32+
_resetWarned()
3033
})
3134

3235
const context = require.context('./modules', true, /-test\.js$/)

0 commit comments

Comments
 (0)