make dev and production environment consistent
chico committed
Jan 16, 2015 at 06:23 UTC
9185323959d87d4798e145f612ad53c61cd3a6f8
6 files changed
+33
-24
src/browser/eventPlugins/AnalyticsEventPluginFactory.js
+6
-2
@@ -80,6 +80,7 @@ var ExecutionEnvironment = require('ExecutionEnvironment');
80
81
var emptyFunction = require('emptyFunction');
82
var invariant = require('invariant');
83
+var warning = require('warning');
84
var topLevelTypes = require('EventConstants').topLevelTypes;
85
86
var ANALYTICS_ID = 'data-analytics-id';
@@ -173,7 +174,7 @@ function initAnalyticsDataForID(analyticsID, analyticsEventsArr) {
174
analyticsData[analyticsID] = {};
175
analyticsEventsArr.forEach(function(analyticsEvent) {
176
if (__DEV__) {
176
- invariant(
177
+ warning(
178
analyticsEventNameToTopLevelType[analyticsEvent],
179
'Invalid analyticsEvent:%s for analyticsID:%s',
180
analyticsEvent,
@@ -197,7 +198,10 @@ var createAnalyticsPlugin = function(cb, interval) {
198
);
199
200
if (__DEV__) {
200
- invariant(cb, 'createAnalyticsPlugin(...): You must provide a callback.');
201
+ warning(
202
+ cb,
203
+ 'createAnalyticsPlugin(...): You must provide a callback.'
204
+ );
205
}
206
cb = cb || emptyFunction;
207
src/browser/eventPlugins/__tests__/AnalyticsEventPlugin-test.js
+13
-12
@@ -53,6 +53,7 @@ describe('AnalyticsEventPlugin', function() {
53
'ChangeEventPlugin': ChangeEventPlugin
54
});
55
56
+ spyOn(console, 'warn');
57
});
58
59
it('should count events correctly', function() {
@@ -104,13 +105,15 @@ describe('AnalyticsEventPlugin', function() {
105
expect(cb).toBeCalled();
106
});
107
107
- it('error non no callback', function() {
108
- expect(function() {
109
- AnalyticsEventPluginFactory.createAnalyticsPlugin(null);
110
- }).toThrow();
108
+ it('warn on no callback', function() {
109
+ AnalyticsEventPluginFactory.createAnalyticsPlugin(null);
110
+ expect(console.warn.calls.length).toBe(1);
111
+ expect(console.warn.argsForCall[0][0]).toBe(
112
+ 'Warning: createAnalyticsPlugin(...): You must provide a callback.'
113
+ );
114
});
115
113
- it('error on invalid analytics events', function() {
116
+ it('warn on invalid analytics events', function() {
117
var TestInvalidEvents = React.createClass({
118
render: function() {
119
return (
@@ -133,13 +136,11 @@ describe('AnalyticsEventPlugin', function() {
136
)
137
});
138
136
- var error = false;
137
- try {
138
- ReactTestUtils.SimulateNative.click(renderedComponent.refs.testDiv);
139
- } catch(e) {
140
- error = true;
141
- }
139
+ ReactTestUtils.SimulateNative.click(renderedComponent.refs.testDiv);
140
143
- expect(error).toBe(true);
141
+ expect(console.warn.calls.length).toBe(1);
142
+ expect(console.warn.argsForCall[0][0]).toBe(
143
+ 'Warning: Invalid analyticsEvent:123 for analyticsID:test_invalid_events'
144
+ );
145
});
146
});
src/browser/ui/ReactMount.js
+1
-2
@@ -633,13 +633,12 @@ var ReactMount = {
633
if (__DEV__) {
634
var rootElement = rootElementsByReactRootID[reactRootID];
635
if (rootElement && rootElement.parentNode !== container) {
636
- invariant(
636
+ warning(
637
// Call internalGetID here because getID calls isValid which calls
638
// findReactContainerForID (this function).
639
internalGetID(rootElement) === reactRootID,
640
'ReactMount: Root element ID differed from reactRootID.'
641
);
642
-
642
var containerChild = container.firstChild;
643
if (containerChild &&
644
reactRootID === internalGetID(containerChild)) {
src/event/EventPluginHub.js
+2
-1
@@ -17,6 +17,7 @@ var EventPluginUtils = require('EventPluginUtils');
17
var accumulateInto = require('accumulateInto');
18
var forEachAccumulated = require('forEachAccumulated');
19
var invariant = require('invariant');
20
+var warning = require('warning');
21
22
/**
23
* Internal store for event listeners
@@ -62,7 +63,7 @@ function validateInstanceHandle() {
63
InstanceHandle &&
64
InstanceHandle.traverseTwoPhase &&
65
InstanceHandle.traverseEnterLeave;
65
- invariant(
66
+ warning(
67
valid,
68
'InstanceHandle not injected before use!'
69
);
src/event/EventPluginUtils.js
+5
-4
@@ -14,6 +14,7 @@
14
var EventConstants = require('EventConstants');
15
16
var invariant = require('invariant');
17
+var warning = require('warning');
18
19
/**
20
* Injected dependencies:
@@ -28,10 +29,10 @@ var injection = {
29
injectMount: function(InjectedMount) {
30
injection.Mount = InjectedMount;
31
if (__DEV__) {
31
- invariant(
32
+ warning(
33
InjectedMount && InjectedMount.getNode,
33
- 'EventPluginUtils.injection.injectMount(...): Injected Mount module ' +
34
- 'is missing getNode.'
34
+ 'EventPluginUtils.injection.injectMount(...): Injected Mount ' +
35
+ 'module is missing getNode.'
36
);
37
}
38
}
@@ -68,7 +69,7 @@ if (__DEV__) {
69
dispatchListeners.length :
70
dispatchListeners ? 1 : 0;
71
71
- invariant(
72
+ warning(
73
idsIsArr === listenersIsArr && IDsLen === listenersLen,
74
'EventPluginUtils: Invalid `event`.'
75
);
src/event/EventPropagators.js
+6
-3
@@ -14,6 +14,8 @@
14
var EventConstants = require('EventConstants');
15
var EventPluginHub = require('EventPluginHub');
16
17
+var warning = require('warning');
18
+
19
var accumulateInto = require('accumulateInto');
20
var forEachAccumulated = require('forEachAccumulated');
21
@@ -38,9 +40,10 @@ function listenerAtPhase(id, event, propagationPhase) {
40
*/
41
function accumulateDirectionalDispatches(domID, upwards, event) {
42
if (__DEV__) {
41
- if (!domID) {
42
- throw new Error('Dispatching id must not be null');
43
- }
43
+ warning(
44
+ domID,
45
+ 'Dispatching id must not be null'
46
+ );
47
}
48
var phase = upwards ? PropagationPhases.bubbled : PropagationPhases.captured;
49
var listener = listenerAtPhase(domID, event, phase);