mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
renamed methods (devtool -> hook)
This commit is contained in:
1 parent
f2fc182250
commit
81f554817c
8 files changed
+44
-44
No files matched your search
@@ -86,7 +86,7 @@ var ReactComponentTreeHook = {
|
||||
var nextChild = tree[nextChildID];
|
||||
invariant(
|
||||
nextChild,
|
||||
'Expected devtool events to fire for the child ' +
|
||||
'Expected hook events to fire for the child ' +
|
||||
'before its parent includes it in onSetChildren().'
|
||||
);
|
||||
invariant(
|
||||
|
||||
@@ -302,7 +302,7 @@ var ReactMount = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Render a new component into the DOM. Hooked by devtools!
|
||||
* Render a new component into the DOM. Hooked by hooks!
|
||||
*
|
||||
* @param {ReactElement} nextElement element to render
|
||||
* @param {DOMElement} container container to render into
|
||||
|
||||
@@ -29,7 +29,7 @@ function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
|
||||
} catch (e) {
|
||||
warning(
|
||||
handlerDoesThrowForEvent[handlerFunctionName],
|
||||
'exception thrown by devtool while handling %s: %s',
|
||||
'exception thrown by hook while handling %s: %s',
|
||||
handlerFunctionName,
|
||||
e + '\n' + e.stack
|
||||
);
|
||||
@@ -39,14 +39,14 @@ function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
|
||||
}
|
||||
|
||||
var ReactDOMDebugTool = {
|
||||
addDevtool(devtool) {
|
||||
ReactDebugTool.addDevtool(devtool);
|
||||
eventHandlers.push(devtool);
|
||||
addHook(hook) {
|
||||
ReactDebugTool.addHook(hook);
|
||||
eventHandlers.push(hook);
|
||||
},
|
||||
removeDevtool(devtool) {
|
||||
ReactDebugTool.removeDevtool(devtool);
|
||||
removeHook(hook) {
|
||||
ReactDebugTool.removeHook(hook);
|
||||
for (var i = 0; i < eventHandlers.length; i++) {
|
||||
if (eventHandlers[i] === devtool) {
|
||||
if (eventHandlers[i] === hook) {
|
||||
eventHandlers.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ var ReactDOMDebugTool = {
|
||||
},
|
||||
};
|
||||
|
||||
ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyHook);
|
||||
ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropHook);
|
||||
ReactDOMDebugTool.addHook(ReactDOMUnknownPropertyHook);
|
||||
ReactDOMDebugTool.addHook(ReactDOMNullInputValuePropHook);
|
||||
|
||||
module.exports = ReactDOMDebugTool;
|
||||
@@ -19,13 +19,13 @@ describe('ReactDOMDebugTool', function() {
|
||||
ReactDOMDebugTool = require('ReactDOMDebugTool');
|
||||
});
|
||||
|
||||
it('should add and remove devtools', () => {
|
||||
it('should add and remove hooks', () => {
|
||||
var handler1 = jasmine.createSpy('spy');
|
||||
var handler2 = jasmine.createSpy('spy');
|
||||
var devtool1 = {onTestEvent: handler1};
|
||||
var devtool2 = {onTestEvent: handler2};
|
||||
var hook1 = {onTestEvent: handler1};
|
||||
var hook2 = {onTestEvent: handler2};
|
||||
|
||||
ReactDOMDebugTool.addDevtool(devtool1);
|
||||
ReactDOMDebugTool.addHook(hook1);
|
||||
ReactDOMDebugTool.onTestEvent();
|
||||
expect(handler1.calls.count()).toBe(1);
|
||||
expect(handler2.calls.count()).toBe(0);
|
||||
@@ -34,7 +34,7 @@ describe('ReactDOMDebugTool', function() {
|
||||
expect(handler1.calls.count()).toBe(2);
|
||||
expect(handler2.calls.count()).toBe(0);
|
||||
|
||||
ReactDOMDebugTool.addDevtool(devtool2);
|
||||
ReactDOMDebugTool.addHook(hook2);
|
||||
ReactDOMDebugTool.onTestEvent();
|
||||
expect(handler1.calls.count()).toBe(3);
|
||||
expect(handler2.calls.count()).toBe(1);
|
||||
@@ -43,20 +43,20 @@ describe('ReactDOMDebugTool', function() {
|
||||
expect(handler1.calls.count()).toBe(4);
|
||||
expect(handler2.calls.count()).toBe(2);
|
||||
|
||||
ReactDOMDebugTool.removeDevtool(devtool1);
|
||||
ReactDOMDebugTool.removeHook(hook1);
|
||||
ReactDOMDebugTool.onTestEvent();
|
||||
expect(handler1.calls.count()).toBe(4);
|
||||
expect(handler2.calls.count()).toBe(3);
|
||||
|
||||
ReactDOMDebugTool.removeDevtool(devtool2);
|
||||
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 devtool', () => {
|
||||
it('warns once when an error is thrown in hook', () => {
|
||||
spyOn(console, 'error');
|
||||
ReactDOMDebugTool.addDevtool({
|
||||
ReactDOMDebugTool.addHook({
|
||||
onTestEvent() {
|
||||
throw new Error('Hi.');
|
||||
},
|
||||
@@ -65,7 +65,7 @@ describe('ReactDOMDebugTool', function() {
|
||||
ReactDOMDebugTool.onTestEvent();
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain(
|
||||
'exception thrown by devtool while handling ' +
|
||||
'exception thrown by hook while handling ' +
|
||||
'onTestEvent: Error: Hi.'
|
||||
);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
|
||||
} catch (e) {
|
||||
warning(
|
||||
handlerDoesThrowForEvent[handlerFunctionName],
|
||||
'exception thrown by devtool while handling %s: %s',
|
||||
'exception thrown by hook while handling %s: %s',
|
||||
handlerFunctionName,
|
||||
e + '\n' + e.stack
|
||||
);
|
||||
@@ -182,12 +182,12 @@ function resumeCurrentLifeCycleTimer() {
|
||||
}
|
||||
|
||||
var ReactDebugTool = {
|
||||
addDevtool(devtool) {
|
||||
eventHandlers.push(devtool);
|
||||
addHook(hook) {
|
||||
eventHandlers.push(hook);
|
||||
},
|
||||
removeDevtool(devtool) {
|
||||
removeHook(hook) {
|
||||
for (var i = 0; i < eventHandlers.length; i++) {
|
||||
if (eventHandlers[i] === devtool) {
|
||||
if (eventHandlers[i] === hook) {
|
||||
eventHandlers.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
@@ -204,7 +204,7 @@ var ReactDebugTool = {
|
||||
isProfiling = true;
|
||||
flushHistory.length = 0;
|
||||
resetMeasurements();
|
||||
ReactDebugTool.addDevtool(ReactHostOperationHistoryHook);
|
||||
ReactDebugTool.addHook(ReactHostOperationHistoryHook);
|
||||
},
|
||||
endProfiling() {
|
||||
if (!isProfiling) {
|
||||
@@ -213,7 +213,7 @@ var ReactDebugTool = {
|
||||
|
||||
isProfiling = false;
|
||||
resetMeasurements();
|
||||
ReactDebugTool.removeDevtool(ReactHostOperationHistoryHook);
|
||||
ReactDebugTool.removeHook(ReactHostOperationHistoryHook);
|
||||
},
|
||||
getFlushHistory() {
|
||||
return flushHistory;
|
||||
@@ -325,9 +325,9 @@ var ReactDebugTool = {
|
||||
},
|
||||
};
|
||||
|
||||
ReactDebugTool.addDevtool(ReactInvalidSetStateWarningHook);
|
||||
ReactDebugTool.addDevtool(ReactComponentTreeHook);
|
||||
ReactDebugTool.addDevtool(ReactChildrenMutationWarningHook);
|
||||
ReactDebugTool.addHook(ReactInvalidSetStateWarningHook);
|
||||
ReactDebugTool.addHook(ReactComponentTreeHook);
|
||||
ReactDebugTool.addHook(ReactChildrenMutationWarningHook);
|
||||
var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
|
||||
if ((/[?&]react_perf\b/).test(url)) {
|
||||
ReactDebugTool.beginProfiling();
|
||||
|
||||
@@ -19,13 +19,13 @@ describe('ReactDebugTool', function() {
|
||||
ReactDebugTool = require('ReactDebugTool');
|
||||
});
|
||||
|
||||
it('should add and remove devtools', () => {
|
||||
it('should add and remove hooks', () => {
|
||||
var handler1 = jasmine.createSpy('spy');
|
||||
var handler2 = jasmine.createSpy('spy');
|
||||
var devtool1 = {onTestEvent: handler1};
|
||||
var devtool2 = {onTestEvent: handler2};
|
||||
var hook1 = {onTestEvent: handler1};
|
||||
var hook2 = {onTestEvent: handler2};
|
||||
|
||||
ReactDebugTool.addDevtool(devtool1);
|
||||
ReactDebugTool.addHook(hook1);
|
||||
ReactDebugTool.onTestEvent();
|
||||
expect(handler1.calls.count()).toBe(1);
|
||||
expect(handler2.calls.count()).toBe(0);
|
||||
@@ -34,7 +34,7 @@ describe('ReactDebugTool', function() {
|
||||
expect(handler1.calls.count()).toBe(2);
|
||||
expect(handler2.calls.count()).toBe(0);
|
||||
|
||||
ReactDebugTool.addDevtool(devtool2);
|
||||
ReactDebugTool.addHook(hook2);
|
||||
ReactDebugTool.onTestEvent();
|
||||
expect(handler1.calls.count()).toBe(3);
|
||||
expect(handler2.calls.count()).toBe(1);
|
||||
@@ -43,20 +43,20 @@ describe('ReactDebugTool', function() {
|
||||
expect(handler1.calls.count()).toBe(4);
|
||||
expect(handler2.calls.count()).toBe(2);
|
||||
|
||||
ReactDebugTool.removeDevtool(devtool1);
|
||||
ReactDebugTool.removeHook(hook1);
|
||||
ReactDebugTool.onTestEvent();
|
||||
expect(handler1.calls.count()).toBe(4);
|
||||
expect(handler2.calls.count()).toBe(3);
|
||||
|
||||
ReactDebugTool.removeDevtool(devtool2);
|
||||
ReactDebugTool.removeHook(hook2);
|
||||
ReactDebugTool.onTestEvent();
|
||||
expect(handler1.calls.count()).toBe(4);
|
||||
expect(handler2.calls.count()).toBe(3);
|
||||
});
|
||||
|
||||
it('warns once when an error is thrown in devtool', () => {
|
||||
it('warns once when an error is thrown in hook', () => {
|
||||
spyOn(console, 'error');
|
||||
ReactDebugTool.addDevtool({
|
||||
ReactDebugTool.addHook({
|
||||
onTestEvent() {
|
||||
throw new Error('Hi.');
|
||||
},
|
||||
@@ -65,7 +65,7 @@ describe('ReactDebugTool', function() {
|
||||
ReactDebugTool.onTestEvent();
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toContain(
|
||||
'exception thrown by devtool while handling ' +
|
||||
'exception thrown by hook while handling ' +
|
||||
'onTestEvent: Error: Hi.'
|
||||
);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ describe('ReactComponentTreeHook', () => {
|
||||
ReactDOMServer.renderToString(<Wrapper />);
|
||||
expectWrapperTreeToEqual(null);
|
||||
|
||||
// To test it, we tell the devtool to ignore next purge
|
||||
// To test it, we tell the hook to ignore next purge
|
||||
// so the cleanup request by ReactDebugTool is ignored.
|
||||
// This lets us make assertions on the actual tree.
|
||||
ReactComponentTreeHook._preventPurging = true;
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('ReactHostOperationHistoryHook', () => {
|
||||
ReactHostOperationHistoryHook._preventClearing = true;
|
||||
ReactDOM.render(<Foo />, node);
|
||||
|
||||
// Empty DOM components should be invisible to devtools.
|
||||
// Empty DOM components should be invisible to hooks.
|
||||
assertHistoryMatches([]);
|
||||
});
|
||||
|
||||
@@ -106,7 +106,7 @@ describe('ReactHostOperationHistoryHook', () => {
|
||||
ReactDOM.render(<Foo />, node);
|
||||
var inst = ReactDOMComponentTree.getInstanceFromNode(node.firstChild);
|
||||
|
||||
// Since empty components should be invisible to devtools,
|
||||
// Since empty components should be invisible to hooks,
|
||||
// we record a "mount" event rather than a "replace with".
|
||||
assertHistoryMatches([{
|
||||
instanceID: inst._debugID,
|
||||
|
||||
Reference in new issue
Block a user