Remove ReactDOMInstrumentation (#7481)

Its events are not being used anywhere.
This commit is contained in:
Dan Abramov
2016-08-12 20:09:27 +01:00
committed by GitHub
parent 4b734f7a02
commit cba2b19b84
5 changed files with 9 additions and 181 deletions
+9
View File
@@ -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;
@@ -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',
@@ -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;
@@ -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};
@@ -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);
});
});