React Native: run Relay DevTools runtime
Reviewed By: fkgozali Differential Revision: D5589121 fbshipit-source-id: 8324e123c0786a7864aaa5ebaa7134ca6afa5c18
This commit is contained in:
Родитель
1df198da02
Коммит
4510760447
|
@ -11,30 +11,54 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
type DevToolsPluginConnection = {
|
||||
isAppActive: () => boolean,
|
||||
host: string,
|
||||
port: number,
|
||||
};
|
||||
|
||||
type DevToolsPlugin = {
|
||||
connectToDevTools: (connection: DevToolsPluginConnection) => void,
|
||||
};
|
||||
|
||||
let register = function () {
|
||||
// noop
|
||||
};
|
||||
|
||||
if (__DEV__) {
|
||||
const AppState = require('AppState');
|
||||
const WebSocket = require('WebSocket');
|
||||
const {PlatformConstants} = require('NativeModules');
|
||||
const {connectToDevTools} = require('react-devtools-core');
|
||||
const reactDevTools = require('react-devtools-core');
|
||||
|
||||
register = function (plugin: DevToolsPlugin) {
|
||||
// Initialize dev tools only if the native module for WebSocket is available
|
||||
if (WebSocket.isAvailable) {
|
||||
// Don't steal the DevTools from currently active app.
|
||||
// Note: if you add any AppState subscriptions to this file,
|
||||
// you will also need to guard against `AppState.isAvailable`,
|
||||
// or the code will throw for bundles that don't have it.
|
||||
const isAppActive = () => AppState.currentState !== 'background';
|
||||
|
||||
// Initialize dev tools only if the native module for WebSocket is available
|
||||
if (WebSocket.isAvailable) {
|
||||
connectToDevTools({
|
||||
isAppActive() {
|
||||
// Don't steal the DevTools from currently active app.
|
||||
// Note: if you add any AppState subscriptions to this file,
|
||||
// you will also need to guard against `AppState.isAvailable`,
|
||||
// or the code will throw for bundles that don't have it.
|
||||
return AppState.currentState !== 'background';
|
||||
},
|
||||
// Special case: Genymotion is running on a different host.
|
||||
host: PlatformConstants && PlatformConstants.ServerHost ?
|
||||
const host = PlatformConstants && PlatformConstants.ServerHost ?
|
||||
PlatformConstants.ServerHost.split(':')[0] :
|
||||
'localhost',
|
||||
// Read the optional global variable for backward compatibility.
|
||||
// It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
|
||||
port: window.__REACT_DEVTOOLS_PORT__,
|
||||
resolveRNStyle: require('flattenStyle'),
|
||||
});
|
||||
}
|
||||
'localhost';
|
||||
|
||||
plugin.connectToDevTools({
|
||||
isAppActive,
|
||||
host,
|
||||
// Read the optional global variable for backward compatibility.
|
||||
// It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
|
||||
port: window.__REACT_DEVTOOLS_PORT__,
|
||||
resolveRNStyle: require('flattenStyle'),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
register(reactDevTools);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
register,
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче