-
Notifications
You must be signed in to change notification settings - Fork 45.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds `ReactInstrumentation` for the isomorphic package that uses the same approach as `ReactDOMInstrumentation`. Currently it is gated behind `__DEV__` but we will likely change this later to a runtime flag determined by whether there are any active listeners. The first few events we add here should be sufficient for React DevTools, as determined by the `hook.emit()` calls in https://github.com/facebook/react-devtools/blob/d90c43201617d5aef378669da926d79515b6a811/backend/attachRenderer.js. These events will also be useful for reconstructing the parent tree in the ReactPerf rewrite in #6046.
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* 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. | ||
* | ||
* @providesModule ReactDebugTool | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var warning = require('warning'); | ||
|
||
var eventHandlers = []; | ||
var handlerDoesThrowForEvent = {}; | ||
|
||
function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) { | ||
if (__DEV__) { | ||
eventHandlers.forEach(function(handler) { | ||
try { | ||
if (handler[handlerFunctionName]) { | ||
handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5); | ||
} | ||
} catch (e) { | ||
warning( | ||
!handlerDoesThrowForEvent[handlerFunctionName], | ||
'exception thrown by devtool while handling %s: %s', | ||
handlerFunctionName, | ||
e.message | ||
); | ||
handlerDoesThrowForEvent[handlerFunctionName] = true; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
var ReactDebugTool = { | ||
addDevtool(devtool) { | ||
eventHandlers.push(devtool); | ||
}, | ||
removeDevtool(devtool) { | ||
for (var i = 0; i < eventHandlers.length; i++) { | ||
if (eventHandlers[i] === devtool) { | ||
eventHandlers.splice(i, 1); | ||
i--; | ||
} | ||
} | ||
}, | ||
onMountRootComponent(internalInstance) { | ||
emitEvent('onMountRootComponent', internalInstance); | ||
}, | ||
onMountComponent(internalInstance) { | ||
emitEvent('onMountComponent', internalInstance); | ||
}, | ||
onUpdateComponent(internalInstance) { | ||
emitEvent('onUpdateComponent', internalInstance); | ||
}, | ||
onUnmountComponent(internalInstance) { | ||
emitEvent('onUnmountComponent', internalInstance); | ||
}, | ||
}; | ||
|
||
module.exports = ReactDebugTool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* 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. | ||
* | ||
* @providesModule ReactInstrumentation | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var ReactDebugTool = require('ReactDebugTool'); | ||
|
||
module.exports = {debugTool: ReactDebugTool}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters