Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Initial outline for new devtools api #5462

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/renderers/dom/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'use strict';

var ReactDOMComponentTree = require('ReactDOMComponentTree');
var ReactDOMDevtools = require('ReactDOMDevtools');
var ReactDefaultInjection = require('ReactDefaultInjection');
var ReactMount = require('ReactMount');
var ReactPerf = require('ReactPerf');
Expand All @@ -35,6 +36,8 @@ var React = {
render: render,
unmountComponentAtNode: ReactMount.unmountComponentAtNode,
version: ReactVersion,
addDevtool: ReactDOMDevtools.addDevtool,
removeDevtool: ReactDOMDevtools.removeDevtool,

/* eslint-disable camelcase */
unstable_batchedUpdates: ReactUpdates.batchedUpdates,
Expand Down
52 changes: 52 additions & 0 deletions src/renderers/dom/shared/ReactDOMDevtools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2013-2015, 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 ReactDOMDevtools
*/

'use strict';

var warning = require('warning');

var eventHandlers = [];
var handlerDoesThrowForEvent = {};

var ReactDOMDevtools = {
addDevtool(devtool) {
eventHandlers.push(devtool);
},

removeDevtool(devtool) {
for (var i = 0; i < eventHandlers.length; i++) {
if (eventHandlers[i] === devtool) {
eventHandlers.splice(i, 1);
i--;
}
}
},

emitEvent(eventName, eventData) {
if (__DEV__) {
eventHandlers.forEach(function(handler) {
try {
handler.handleEvent(eventName, eventData);
} catch (e) {
warning(
!handlerDoesThrowForEvent[eventName],
'exception thrown by devtool while handling %s: %s',
eventName,
e.message
);
handlerDoesThrowForEvent[eventName] = true;
}
});
}
},
};

module.exports = ReactDOMDevtools;