Skip to content

Commit

Permalink
Cleanup InitializeJavascriptAppEngine
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D3235141

fb-gh-sync-id: 86fc844c5e9d9ea57d504696bac30671c2079e7a
fbshipit-source-id: 86fc844c5e9d9ea57d504696bac30671c2079e7a
  • Loading branch information
javache authored and Facebook Github Bot 2 committed May 4, 2016
1 parent 2310494 commit 2760df7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 61 deletions.
18 changes: 10 additions & 8 deletions Libraries/BatchedBridge/BatchedBridgedModules/RCTEventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
*/
'use strict';

var BatchedBridge = require('BatchedBridge');
var ReactNativeEventEmitter = require('ReactNativeEventEmitter');
const BatchedBridge = require('BatchedBridge');

BatchedBridge.registerCallableModule(
'RCTEventEmitter',
ReactNativeEventEmitter
);
const RCTEventEmitter = {
register(eventEmitter: any) {
BatchedBridge.registerCallableModule(
'RCTEventEmitter',
eventEmitter
);
}
};

// Completely locally implemented - no native hooks.
module.exports = ReactNativeEventEmitter;
module.exports = RCTEventEmitter;
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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.
Expand All @@ -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]});
}

Expand Down Expand Up @@ -115,7 +132,7 @@ function setUpErrorHandler() {
}
}

var ErrorUtils = require('ErrorUtils');
const ErrorUtils = require('ErrorUtils');
ErrorUtils.setGlobalHandler(handleError);
}

Expand Down Expand Up @@ -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() {
Expand All @@ -174,6 +193,8 @@ function setUpGeolocation() {
enumerable: true,
configurable: true,
});
Object.defineProperty(global.navigator, 'product', {value: 'ReactNative'});

polyfillLazyGlobal('geolocation', () => require('Geolocation'), global.navigator);
}

Expand All @@ -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() {
// not when debugging in chrome
if (__DEV__) { // TODO(9123099) Strip `__DEV__ &&`
if (__DEV__) {
// not when debugging in chrome
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();
Expand All @@ -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');
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
10 changes: 0 additions & 10 deletions packager/react-packager/src/Bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2760df7

Please sign in to comment.