-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial outline for new devtools api
- Loading branch information
jim
committed
Nov 12, 2015
1 parent
fc24522
commit 0f114f5
Showing
2 changed files
with
55 additions
and
0 deletions.
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
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,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; |