@samitouri / QOS-React / commits / cba2b19b84

Remove ReactDOMInstrumentation (#7481)

Its events are not being used anywhere.

Dan Abramov committed Aug 12, 2016 at 20:09 UTC cba2b19b84b339e937b4bbc258cd09b2b8303391
5 files changed +9 -181
src/renderers/dom/ReactDOM.js
+9
@@ -135,4 +135,13 @@ if (__DEV__) {
135 }
136 }
137
138 +if (__DEV__) {
139 + var ReactInstrumentation = require('ReactInstrumentation');
140 + var ReactDOMUnknownPropertyHook = require('ReactDOMUnknownPropertyHook');
141 + var ReactDOMNullInputValuePropHook = require('ReactDOMNullInputValuePropHook');
142 +
143 + ReactInstrumentation.debugTool.addHook(ReactDOMUnknownPropertyHook);
144 + ReactInstrumentation.debugTool.addHook(ReactDOMNullInputValuePropHook);
145 +}
146 +
147 module.exports = ReactDOM;
src/renderers/dom/shared/DOMPropertyOperations.js
-7
@@ -13,7 +13,6 @@
13
14 var DOMProperty = require('DOMProperty');
15 var ReactDOMComponentTree = require('ReactDOMComponentTree');
16 -var ReactDOMInstrumentation = require('ReactDOMInstrumentation');
16 var ReactInstrumentation = require('ReactInstrumentation');
17
18 var quoteAttributeValueForBrowser = require('quoteAttributeValueForBrowser');
@@ -89,9 +88,6 @@ var DOMPropertyOperations = {
88 * @return {?string} Markup string, or null if the property was invalid.
89 */
90 createMarkupForProperty: function(name, value) {
92 - if (__DEV__) {
93 - ReactDOMInstrumentation.debugTool.onCreateMarkupForProperty(name, value);
94 - }
91 var propertyInfo = DOMProperty.properties.hasOwnProperty(name) ?
92 DOMProperty.properties[name] : null;
93 if (propertyInfo) {
@@ -168,7 +164,6 @@ var DOMPropertyOperations = {
164 }
165
166 if (__DEV__) {
171 - ReactDOMInstrumentation.debugTool.onSetValueForProperty(node, name, value);
167 var payload = {};
168 payload[name] = value;
169 ReactInstrumentation.debugTool.onHostOperation(
@@ -209,7 +204,6 @@ var DOMPropertyOperations = {
204 deleteValueForAttribute: function(node, name) {
205 node.removeAttribute(name);
206 if (__DEV__) {
212 - ReactDOMInstrumentation.debugTool.onDeleteValueForProperty(node, name);
207 ReactInstrumentation.debugTool.onHostOperation(
208 ReactDOMComponentTree.getInstanceFromNode(node)._debugID,
209 'remove attribute',
@@ -246,7 +240,6 @@ var DOMPropertyOperations = {
240 }
241
242 if (__DEV__) {
249 - ReactDOMInstrumentation.debugTool.onDeleteValueForProperty(node, name);
243 ReactInstrumentation.debugTool.onHostOperation(
244 ReactDOMComponentTree.getInstanceFromNode(node)._debugID,
245 'remove attribute',
src/renderers/dom/shared/ReactDOMDebugTool.js deleted
-78
@@ -1,78 +0,0 @@
1 -/**
2 - * Copyright 2013-present, Facebook, Inc.
3 - * All rights reserved.
4 - *
5 - * This source code is licensed under the BSD-style license found in the
6 - * LICENSE file in the root directory of this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @providesModule ReactDOMDebugTool
10 - */
11 -
12 -'use strict';
13 -
14 -var ReactDOMNullInputValuePropHook = require('ReactDOMNullInputValuePropHook');
15 -var ReactDOMUnknownPropertyHook = require('ReactDOMUnknownPropertyHook');
16 -var ReactDebugTool = require('ReactDebugTool');
17 -
18 -var warning = require('warning');
19 -
20 -var hooks = [];
21 -var didHookThrowForEvent = {};
22 -
23 -function callHook(event, fn, context, arg1, arg2, arg3, arg4, arg5) {
24 - try {
25 - fn.call(context, arg1, arg2, arg3, arg4, arg5);
26 - } catch (e) {
27 - warning(
28 - didHookThrowForEvent[event],
29 - 'Exception thrown by hook while handling %s: %s',
30 - event,
31 - e + '\n' + e.stack
32 - );
33 - didHookThrowForEvent[event] = true;
34 - }
35 -}
36 -
37 -function emitEvent(event, arg1, arg2, arg3, arg4, arg5) {
38 - for (var i = 0; i < hooks.length; i++) {
39 - var hook = hooks[i];
40 - var fn = hook[event];
41 - if (fn) {
42 - callHook(event, fn, hook, arg1, arg2, arg3, arg4, arg5);
43 - }
44 - }
45 -}
46 -
47 -var ReactDOMDebugTool = {
48 - addHook(hook) {
49 - ReactDebugTool.addHook(hook);
50 - hooks.push(hook);
51 - },
52 - removeHook(hook) {
53 - ReactDebugTool.removeHook(hook);
54 - for (var i = 0; i < hooks.length; i++) {
55 - if (hooks[i] === hook) {
56 - hooks.splice(i, 1);
57 - i--;
58 - }
59 - }
60 - },
61 - onCreateMarkupForProperty(name, value) {
62 - emitEvent('onCreateMarkupForProperty', name, value);
63 - },
64 - onSetValueForProperty(node, name, value) {
65 - emitEvent('onSetValueForProperty', node, name, value);
66 - },
67 - onDeleteValueForProperty(node, name) {
68 - emitEvent('onDeleteValueForProperty', node, name);
69 - },
70 - onTestEvent() {
71 - emitEvent('onTestEvent');
72 - },
73 -};
74 -
75 -ReactDOMDebugTool.addHook(ReactDOMUnknownPropertyHook);
76 -ReactDOMDebugTool.addHook(ReactDOMNullInputValuePropHook);
77 -
78 -module.exports = ReactDOMDebugTool;
src/renderers/dom/shared/ReactDOMInstrumentation.js deleted
-21
@@ -1,21 +0,0 @@
1 -/**
2 - * Copyright 2013-present, Facebook, Inc.
3 - * All rights reserved.
4 - *
5 - * This source code is licensed under the BSD-style license found in the
6 - * LICENSE file in the root directory of this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @providesModule ReactDOMInstrumentation
10 - */
11 -
12 -'use strict';
13 -
14 -var debugTool = null;
15 -
16 -if (__DEV__) {
17 - var ReactDOMDebugTool = require('ReactDOMDebugTool');
18 - debugTool = ReactDOMDebugTool;
19 -}
20 -
21 -module.exports = {debugTool};
src/renderers/dom/shared/__tests__/ReactDOMDebugTool-test.js deleted
-75
@@ -1,75 +0,0 @@
1 -/**
2 - * Copyright 2016-present, Facebook, Inc.
3 - * All rights reserved.
4 - *
5 - * This source code is licensed under the BSD-style license found in the
6 - * LICENSE file in the root directory of this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @emails react-core
10 - */
11 -
12 -'use strict';
13 -
14 -describe('ReactDOMDebugTool', function() {
15 - var ReactDOMDebugTool;
16 -
17 - beforeEach(function() {
18 - jest.resetModuleRegistry();
19 - ReactDOMDebugTool = require('ReactDOMDebugTool');
20 - });
21 -
22 - it('should add and remove hooks', () => {
23 - var handler1 = jasmine.createSpy('spy');
24 - var handler2 = jasmine.createSpy('spy');
25 - var hook1 = {onTestEvent: handler1};
26 - var hook2 = {onTestEvent: handler2};
27 -
28 - ReactDOMDebugTool.addHook(hook1);
29 - ReactDOMDebugTool.onTestEvent();
30 - expect(handler1.calls.count()).toBe(1);
31 - expect(handler2.calls.count()).toBe(0);
32 -
33 - ReactDOMDebugTool.onTestEvent();
34 - expect(handler1.calls.count()).toBe(2);
35 - expect(handler2.calls.count()).toBe(0);
36 -
37 - ReactDOMDebugTool.addHook(hook2);
38 - ReactDOMDebugTool.onTestEvent();
39 - expect(handler1.calls.count()).toBe(3);
40 - expect(handler2.calls.count()).toBe(1);
41 -
42 - ReactDOMDebugTool.onTestEvent();
43 - expect(handler1.calls.count()).toBe(4);
44 - expect(handler2.calls.count()).toBe(2);
45 -
46 - ReactDOMDebugTool.removeHook(hook1);
47 - ReactDOMDebugTool.onTestEvent();
48 - expect(handler1.calls.count()).toBe(4);
49 - expect(handler2.calls.count()).toBe(3);
50 -
51 - ReactDOMDebugTool.removeHook(hook2);
52 - ReactDOMDebugTool.onTestEvent();
53 - expect(handler1.calls.count()).toBe(4);
54 - expect(handler2.calls.count()).toBe(3);
55 - });
56 -
57 - it('warns once when an error is thrown in hook', () => {
58 - spyOn(console, 'error');
59 - ReactDOMDebugTool.addHook({
60 - onTestEvent() {
61 - throw new Error('Hi.');
62 - },
63 - });
64 -
65 - ReactDOMDebugTool.onTestEvent();
66 - expect(console.error.calls.count()).toBe(1);
67 - expect(console.error.calls.argsFor(0)[0]).toContain(
68 - 'Exception thrown by hook while handling ' +
69 - 'onTestEvent: Error: Hi.'
70 - );
71 -
72 - ReactDOMDebugTool.onTestEvent();
73 - expect(console.error.calls.count()).toBe(1);
74 - });
75 -});