1 |
|
2 | var warned = {};
|
3 | var preWarningFns = [];
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export var preMessage = function preMessage(fn) {
|
10 | preWarningFns.push(fn);
|
11 | };
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export function warning(valid, message) {
|
25 | if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
|
26 | var finalMessage = preWarningFns.reduce(function (msg, preMessageFn) {
|
27 | return preMessageFn(msg !== null && msg !== void 0 ? msg : '', 'warning');
|
28 | }, message);
|
29 | if (finalMessage) {
|
30 | console.error("Warning: ".concat(finalMessage));
|
31 | }
|
32 | }
|
33 | }
|
34 |
|
35 |
|
36 | export function note(valid, message) {
|
37 | if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
|
38 | var finalMessage = preWarningFns.reduce(function (msg, preMessageFn) {
|
39 | return preMessageFn(msg !== null && msg !== void 0 ? msg : '', 'note');
|
40 | }, message);
|
41 | if (finalMessage) {
|
42 | console.warn("Note: ".concat(finalMessage));
|
43 | }
|
44 | }
|
45 | }
|
46 | export function resetWarned() {
|
47 | warned = {};
|
48 | }
|
49 | export function call(method, valid, message) {
|
50 | if (!valid && !warned[message]) {
|
51 | method(false, message);
|
52 | warned[message] = true;
|
53 | }
|
54 | }
|
55 |
|
56 |
|
57 | export function warningOnce(valid, message) {
|
58 | call(warning, valid, message);
|
59 | }
|
60 |
|
61 |
|
62 | export function noteOnce(valid, message) {
|
63 | call(note, valid, message);
|
64 | }
|
65 | warningOnce.preMessage = preMessage;
|
66 | warningOnce.resetWarned = resetWarned;
|
67 | warningOnce.noteOnce = noteOnce;
|
68 | export default warningOnce; |
\ | No newline at end of file |