Cleanup InitializeJavascriptAppEngine
Reviewed By: davidaurelio Differential Revision: D3235141 fb-gh-sync-id: 86fc844c5e9d9ea57d504696bac30671c2079e7a fbshipit-source-id: 86fc844c5e9d9ea57d504696bac30671c2079e7a
This commit is contained in:
parent
2310494f32
commit
2760df761d
|
@ -11,13 +11,15 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
var BatchedBridge = require('BatchedBridge');
|
||||
var ReactNativeEventEmitter = require('ReactNativeEventEmitter');
|
||||
const BatchedBridge = require('BatchedBridge');
|
||||
|
||||
BatchedBridge.registerCallableModule(
|
||||
const RCTEventEmitter = {
|
||||
register(eventEmitter: any) {
|
||||
BatchedBridge.registerCallableModule(
|
||||
'RCTEventEmitter',
|
||||
ReactNativeEventEmitter
|
||||
);
|
||||
eventEmitter
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Completely locally implemented - no native hooks.
|
||||
module.exports = ReactNativeEventEmitter;
|
||||
module.exports = RCTEventEmitter;
|
||||
|
|
|
@ -32,10 +32,27 @@ if (typeof window === 'undefined') {
|
|||
global.window = global;
|
||||
}
|
||||
|
||||
function setUpProfile() {
|
||||
if (__DEV__) {
|
||||
const Systrace = require('Systrace');
|
||||
Systrace.swizzleReactPerf();
|
||||
}
|
||||
}
|
||||
|
||||
function setUpProcess() {
|
||||
GLOBAL.process = GLOBAL.process || {};
|
||||
GLOBAL.process.env = GLOBAL.process.env || {};
|
||||
if (!GLOBAL.process.env.NODE_ENV) {
|
||||
GLOBAL.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';
|
||||
}
|
||||
}
|
||||
|
||||
function setUpConsole() {
|
||||
// ExceptionsManager transitively requires Promise so we install it after
|
||||
var ExceptionsManager = require('ExceptionsManager');
|
||||
const ExceptionsManager = require('ExceptionsManager');
|
||||
ExceptionsManager.installConsoleErrorReporter();
|
||||
|
||||
require('RCTLog');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +71,7 @@ function setUpConsole() {
|
|||
* https://github.com/facebook/react-native/issues/934
|
||||
*/
|
||||
function polyfillGlobal(name, newValue, scope = global) {
|
||||
var descriptor = Object.getOwnPropertyDescriptor(scope, name) || {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(scope, name) || {
|
||||
// jest for some bad reasons runs the polyfill code multiple times. In jest
|
||||
// environment, XmlHttpRequest doesn't exist so getOwnPropertyDescriptor
|
||||
// returns undefined and defineProperty default for writable is false.
|
||||
|
@ -63,7 +80,7 @@ function polyfillGlobal(name, newValue, scope = global) {
|
|||
};
|
||||
|
||||
if (scope[name] !== undefined) {
|
||||
var backupName = `original${name[0].toUpperCase()}${name.substr(1)}`;
|
||||
const backupName = `original${name[0].toUpperCase()}${name.substr(1)}`;
|
||||
Object.defineProperty(scope, backupName, {...descriptor, value: scope[name]});
|
||||
}
|
||||
|
||||
|
@ -115,7 +132,7 @@ function setUpErrorHandler() {
|
|||
}
|
||||
}
|
||||
|
||||
var ErrorUtils = require('ErrorUtils');
|
||||
const ErrorUtils = require('ErrorUtils');
|
||||
ErrorUtils.setGlobalHandler(handleError);
|
||||
}
|
||||
|
||||
|
@ -166,6 +183,8 @@ function setUpXHR() {
|
|||
polyfillLazyGlobal('Headers', () => require('fetch').Headers);
|
||||
polyfillLazyGlobal('Request', () => require('fetch').Request);
|
||||
polyfillLazyGlobal('Response', () => require('fetch').Response);
|
||||
|
||||
polyfillLazyGlobal('WebSocket', () => require('WebSocket'));
|
||||
}
|
||||
|
||||
function setUpGeolocation() {
|
||||
|
@ -174,6 +193,8 @@ function setUpGeolocation() {
|
|||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
Object.defineProperty(global.navigator, 'product', {value: 'ReactNative'});
|
||||
|
||||
polyfillLazyGlobal('geolocation', () => require('Geolocation'), global.navigator);
|
||||
}
|
||||
|
||||
|
@ -184,39 +205,20 @@ function setUpMapAndSet() {
|
|||
polyfillGlobal('Set', require('Set'));
|
||||
}
|
||||
|
||||
function setUpProduct() {
|
||||
Object.defineProperty(global.navigator, 'product', {value: 'ReactNative'});
|
||||
}
|
||||
|
||||
function setUpWebSockets() {
|
||||
polyfillLazyGlobal('WebSocket', () => require('WebSocket'));
|
||||
}
|
||||
|
||||
function setUpProfile() {
|
||||
if (__DEV__) {
|
||||
var Systrace = require('Systrace');
|
||||
Systrace.swizzleReactPerf();
|
||||
}
|
||||
}
|
||||
|
||||
function setUpProcess() {
|
||||
global.process = global.process || {};
|
||||
global.process.env = global.process.env || {};
|
||||
if (!global.process.env.NODE_ENV) {
|
||||
global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';
|
||||
}
|
||||
}
|
||||
|
||||
function setUpDevTools() {
|
||||
if (__DEV__) {
|
||||
// not when debugging in chrome
|
||||
if (__DEV__) { // TODO(9123099) Strip `__DEV__ &&`
|
||||
if (!window.document && require('Platform').OS === 'ios') {
|
||||
var setupDevtools = require('setupDevtools');
|
||||
const setupDevtools = require('setupDevtools');
|
||||
setupDevtools();
|
||||
}
|
||||
|
||||
require('RCTDebugComponentOwnership');
|
||||
require('react-transform-hmr');
|
||||
}
|
||||
}
|
||||
|
||||
setUpProfile();
|
||||
setUpProcess();
|
||||
setUpConsole();
|
||||
setUpTimers();
|
||||
|
@ -226,21 +228,10 @@ setUpErrorHandler();
|
|||
setUpXHR();
|
||||
setUpGeolocation();
|
||||
setUpMapAndSet();
|
||||
setUpProduct();
|
||||
setUpWebSockets();
|
||||
setUpProfile();
|
||||
setUpDevTools();
|
||||
|
||||
// Just to make sure the JS gets packaged up. Wait until the JS environment has
|
||||
// been initialized before requiring them.
|
||||
if (__DEV__) {
|
||||
require('RCTDebugComponentOwnership');
|
||||
}
|
||||
require('RCTDeviceEventEmitter');
|
||||
require('RCTNativeAppEventEmitter');
|
||||
require('PerformanceLogger');
|
||||
|
||||
if (__DEV__) {
|
||||
// include this transform and it's dependencies on the bundle on dev mode
|
||||
require('react-transform-hmr');
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@
|
|||
"react-native": "local-cli/wrong-react-native.js"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "15.0.2"
|
||||
"react": "15.0.3-alpha.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"absolute-path": "^0.0.0",
|
||||
|
@ -187,7 +187,7 @@
|
|||
"flow-bin": "0.24.0",
|
||||
"jest-cli": "11.0.2",
|
||||
"portfinder": "0.4.0",
|
||||
"react": "15.0.2",
|
||||
"react": "15.0.3-alpha.1",
|
||||
"shelljs": "0.6.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,16 +248,6 @@ class Bundler {
|
|||
entryModuleOnly,
|
||||
resolutionResponse,
|
||||
}) {
|
||||
if (dev && runBeforeMainModule) { // no runBeforeMainModule for hmr bundles
|
||||
// `require` calls in the require polyfill itself are not extracted and
|
||||
// replaced with numeric module IDs, but the require polyfill
|
||||
// needs Systrace.
|
||||
// Therefore, we include the Systrace module before the main module, and
|
||||
// it will set itself as property on the require function.
|
||||
// TODO(davidaurelio) Scan polyfills for dependencies, too (t9759686)
|
||||
runBeforeMainModule = runBeforeMainModule.concat(['Systrace']);
|
||||
}
|
||||
|
||||
const onResolutionResponse = response => {
|
||||
bundle.setMainModuleId(this._getModuleId(getMainModule(response)));
|
||||
if (bundle.setNumPrependedModules) {
|
||||
|
|
Loading…
Reference in New Issue