From cba2b19b84b339e937b4bbc258cd09b2b8303391 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 12 Aug 2016 20:09:27 +0100 Subject: [PATCH] Remove ReactDOMInstrumentation (#7481) Its events are not being used anywhere. --- src/renderers/dom/ReactDOM.js | 9 +++ .../dom/shared/DOMPropertyOperations.js | 7 -- src/renderers/dom/shared/ReactDOMDebugTool.js | 78 ------------------- .../dom/shared/ReactDOMInstrumentation.js | 21 ----- .../__tests__/ReactDOMDebugTool-test.js | 75 ------------------ 5 files changed, 9 insertions(+), 181 deletions(-) delete mode 100644 src/renderers/dom/shared/ReactDOMDebugTool.js delete mode 100644 src/renderers/dom/shared/ReactDOMInstrumentation.js delete mode 100644 src/renderers/dom/shared/__tests__/ReactDOMDebugTool-test.js diff --git a/src/renderers/dom/ReactDOM.js b/src/renderers/dom/ReactDOM.js index b546e46948300..bfb469e26654f 100644 --- a/src/renderers/dom/ReactDOM.js +++ b/src/renderers/dom/ReactDOM.js @@ -135,4 +135,13 @@ if (__DEV__) { } } +if (__DEV__) { + var ReactInstrumentation = require('ReactInstrumentation'); + var ReactDOMUnknownPropertyHook = require('ReactDOMUnknownPropertyHook'); + var ReactDOMNullInputValuePropHook = require('ReactDOMNullInputValuePropHook'); + + ReactInstrumentation.debugTool.addHook(ReactDOMUnknownPropertyHook); + ReactInstrumentation.debugTool.addHook(ReactDOMNullInputValuePropHook); +} + module.exports = ReactDOM; diff --git a/src/renderers/dom/shared/DOMPropertyOperations.js b/src/renderers/dom/shared/DOMPropertyOperations.js index d0cce18dcf9b2..3d6cb7f59c751 100644 --- a/src/renderers/dom/shared/DOMPropertyOperations.js +++ b/src/renderers/dom/shared/DOMPropertyOperations.js @@ -13,7 +13,6 @@ var DOMProperty = require('DOMProperty'); var ReactDOMComponentTree = require('ReactDOMComponentTree'); -var ReactDOMInstrumentation = require('ReactDOMInstrumentation'); var ReactInstrumentation = require('ReactInstrumentation'); var quoteAttributeValueForBrowser = require('quoteAttributeValueForBrowser'); @@ -89,9 +88,6 @@ var DOMPropertyOperations = { * @return {?string} Markup string, or null if the property was invalid. */ createMarkupForProperty: function(name, value) { - if (__DEV__) { - ReactDOMInstrumentation.debugTool.onCreateMarkupForProperty(name, value); - } var propertyInfo = DOMProperty.properties.hasOwnProperty(name) ? DOMProperty.properties[name] : null; if (propertyInfo) { @@ -168,7 +164,6 @@ var DOMPropertyOperations = { } if (__DEV__) { - ReactDOMInstrumentation.debugTool.onSetValueForProperty(node, name, value); var payload = {}; payload[name] = value; ReactInstrumentation.debugTool.onHostOperation( @@ -209,7 +204,6 @@ var DOMPropertyOperations = { deleteValueForAttribute: function(node, name) { node.removeAttribute(name); if (__DEV__) { - ReactDOMInstrumentation.debugTool.onDeleteValueForProperty(node, name); ReactInstrumentation.debugTool.onHostOperation( ReactDOMComponentTree.getInstanceFromNode(node)._debugID, 'remove attribute', @@ -246,7 +240,6 @@ var DOMPropertyOperations = { } if (__DEV__) { - ReactDOMInstrumentation.debugTool.onDeleteValueForProperty(node, name); ReactInstrumentation.debugTool.onHostOperation( ReactDOMComponentTree.getInstanceFromNode(node)._debugID, 'remove attribute', diff --git a/src/renderers/dom/shared/ReactDOMDebugTool.js b/src/renderers/dom/shared/ReactDOMDebugTool.js deleted file mode 100644 index f30426b2818ec..0000000000000 --- a/src/renderers/dom/shared/ReactDOMDebugTool.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactDOMDebugTool - */ - -'use strict'; - -var ReactDOMNullInputValuePropHook = require('ReactDOMNullInputValuePropHook'); -var ReactDOMUnknownPropertyHook = require('ReactDOMUnknownPropertyHook'); -var ReactDebugTool = require('ReactDebugTool'); - -var warning = require('warning'); - -var hooks = []; -var didHookThrowForEvent = {}; - -function callHook(event, fn, context, arg1, arg2, arg3, arg4, arg5) { - try { - fn.call(context, arg1, arg2, arg3, arg4, arg5); - } catch (e) { - warning( - didHookThrowForEvent[event], - 'Exception thrown by hook while handling %s: %s', - event, - e + '\n' + e.stack - ); - didHookThrowForEvent[event] = true; - } -} - -function emitEvent(event, arg1, arg2, arg3, arg4, arg5) { - for (var i = 0; i < hooks.length; i++) { - var hook = hooks[i]; - var fn = hook[event]; - if (fn) { - callHook(event, fn, hook, arg1, arg2, arg3, arg4, arg5); - } - } -} - -var ReactDOMDebugTool = { - addHook(hook) { - ReactDebugTool.addHook(hook); - hooks.push(hook); - }, - removeHook(hook) { - ReactDebugTool.removeHook(hook); - for (var i = 0; i < hooks.length; i++) { - if (hooks[i] === hook) { - hooks.splice(i, 1); - i--; - } - } - }, - onCreateMarkupForProperty(name, value) { - emitEvent('onCreateMarkupForProperty', name, value); - }, - onSetValueForProperty(node, name, value) { - emitEvent('onSetValueForProperty', node, name, value); - }, - onDeleteValueForProperty(node, name) { - emitEvent('onDeleteValueForProperty', node, name); - }, - onTestEvent() { - emitEvent('onTestEvent'); - }, -}; - -ReactDOMDebugTool.addHook(ReactDOMUnknownPropertyHook); -ReactDOMDebugTool.addHook(ReactDOMNullInputValuePropHook); - -module.exports = ReactDOMDebugTool; diff --git a/src/renderers/dom/shared/ReactDOMInstrumentation.js b/src/renderers/dom/shared/ReactDOMInstrumentation.js deleted file mode 100644 index 4f31a7818dd36..0000000000000 --- a/src/renderers/dom/shared/ReactDOMInstrumentation.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @providesModule ReactDOMInstrumentation - */ - -'use strict'; - -var debugTool = null; - -if (__DEV__) { - var ReactDOMDebugTool = require('ReactDOMDebugTool'); - debugTool = ReactDOMDebugTool; -} - -module.exports = {debugTool}; diff --git a/src/renderers/dom/shared/__tests__/ReactDOMDebugTool-test.js b/src/renderers/dom/shared/__tests__/ReactDOMDebugTool-test.js deleted file mode 100644 index 5253963630aad..0000000000000 --- a/src/renderers/dom/shared/__tests__/ReactDOMDebugTool-test.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2016-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - -describe('ReactDOMDebugTool', function() { - var ReactDOMDebugTool; - - beforeEach(function() { - jest.resetModuleRegistry(); - ReactDOMDebugTool = require('ReactDOMDebugTool'); - }); - - it('should add and remove hooks', () => { - var handler1 = jasmine.createSpy('spy'); - var handler2 = jasmine.createSpy('spy'); - var hook1 = {onTestEvent: handler1}; - var hook2 = {onTestEvent: handler2}; - - ReactDOMDebugTool.addHook(hook1); - ReactDOMDebugTool.onTestEvent(); - expect(handler1.calls.count()).toBe(1); - expect(handler2.calls.count()).toBe(0); - - ReactDOMDebugTool.onTestEvent(); - expect(handler1.calls.count()).toBe(2); - expect(handler2.calls.count()).toBe(0); - - ReactDOMDebugTool.addHook(hook2); - ReactDOMDebugTool.onTestEvent(); - expect(handler1.calls.count()).toBe(3); - expect(handler2.calls.count()).toBe(1); - - ReactDOMDebugTool.onTestEvent(); - expect(handler1.calls.count()).toBe(4); - expect(handler2.calls.count()).toBe(2); - - ReactDOMDebugTool.removeHook(hook1); - ReactDOMDebugTool.onTestEvent(); - expect(handler1.calls.count()).toBe(4); - expect(handler2.calls.count()).toBe(3); - - ReactDOMDebugTool.removeHook(hook2); - ReactDOMDebugTool.onTestEvent(); - expect(handler1.calls.count()).toBe(4); - expect(handler2.calls.count()).toBe(3); - }); - - it('warns once when an error is thrown in hook', () => { - spyOn(console, 'error'); - ReactDOMDebugTool.addHook({ - onTestEvent() { - throw new Error('Hi.'); - }, - }); - - ReactDOMDebugTool.onTestEvent(); - expect(console.error.calls.count()).toBe(1); - expect(console.error.calls.argsFor(0)[0]).toContain( - 'Exception thrown by hook while handling ' + - 'onTestEvent: Error: Hi.' - ); - - ReactDOMDebugTool.onTestEvent(); - expect(console.error.calls.count()).toBe(1); - }); -});