diff --git a/Libraries/BatchedBridge/BatchedBridgedModules/RCTEventEmitter.js b/Libraries/BatchedBridge/BatchedBridgedModules/RCTEventEmitter.js index 2b8f578e7..76200db89 100644 --- a/Libraries/BatchedBridge/BatchedBridgedModules/RCTEventEmitter.js +++ b/Libraries/BatchedBridge/BatchedBridgedModules/RCTEventEmitter.js @@ -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; diff --git a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js index 2f48852d1..9f2bff3b2 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js +++ b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js @@ -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() { - // 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(); @@ -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'); -} diff --git a/package.json b/package.json index 7e111fbf6..ad0827486 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/packager/react-packager/src/Bundler/index.js b/packager/react-packager/src/Bundler/index.js index 197b24f3f..2d67fad90 100644 --- a/packager/react-packager/src/Bundler/index.js +++ b/packager/react-packager/src/Bundler/index.js @@ -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) {