activeWS.onmessage = ({data}) => { // Moving to top gives errors due to NativeModules not being initialized const HMRLoadingView = require('HMRLoadingView'); data = JSON.parse(data); switch (data.type) { case 'update-start': { HMRLoadingView.showMessage('Hot Loading...'); break; } case 'update': { const { modules, sourceMappingURLs, sourceURLs, } = data.body; if (Platform.OS === 'ios') { const RCTRedBox = require('NativeModules').RedBox; RCTRedBox && RCTRedBox.dismiss && RCTRedBox.dismiss(); } else { const RCTExceptionsManager = require('NativeModules').ExceptionsManager; RCTExceptionsManager && RCTExceptionsManager.dismissRedbox && RCTExceptionsManager.dismissRedbox(); } modules.forEach(({id, code}, i) => { code = code + '\n\n' + sourceMappingURLs[i]; // on JSC we need to inject from native for sourcemaps to work // (Safari doesn't support `sourceMappingURL` nor any variant when // evaluating code) but on Chrome we can simply use eval const injectFunction = typeof global.nativeInjectHMRUpdate === 'function' ? global.nativeInjectHMRUpdate : eval; injectFunction(code, sourceURLs[i]); }); HMRLoadingView.hide(); break; } case 'update-done': { HMRLoadingView.hide(); break; } case 'error': { HMRLoadingView.hide(); throw new Error(data.body.type + ' ' + data.body.description); } default: { throw new Error(`Unexpected message: ${data}`); } } };
activeWS.onmessage=function(_ref){var data=_ref.data; var HMRLoadingView=require('HMRLoadingView'); data=JSON.parse(data); switch(data.type){ case'update-start':{ HMRLoadingView.showMessage('Hot Loading...'); break; } case'update':{var _ret=function(){var _data$body= data.body,modules=_data$body.modules,sourceMappingURLs=_data$body.sourceMappingURLs,sourceURLs=_data$body.sourceURLs,inverseDependencies=_data$body.inverseDependencies; if(Platform.OS==='ios'){ var RCTRedBox=require('NativeModules').RedBox; RCTRedBox&&RCTRedBox.dismiss&&RCTRedBox.dismiss(); }else{ var RCTExceptionsManager=require('NativeModules').ExceptionsManager; RCTExceptionsManager&&RCTExceptionsManager.dismissRedbox&&RCTExceptionsManager.dismissRedbox(); } modules.forEach(function(_ref2,i){var id=_ref2.id,code=_ref2.code; code=code+'\n\n'+sourceMappingURLs[i]; var injectFunction=typeof global.nativeInjectHMRUpdate==='function'? global.nativeInjectHMRUpdate: eval; code=[ '__accept(', id+',', 'function(global,require,module,exports){',''+ code, '\n},',''+ JSON.stringify(inverseDependencies), ');']. join(''); injectFunction(code,sourceURLs[i]); }); HMRLoadingView.hide(); return'break';}();if(_ret==='break')break; } case'update-done':{ HMRLoadingView.hide(); break; } case'error':{ HMRLoadingView.hide(); throw new Error(data.body.type+' '+data.body.description); } default:{ throw new Error('Unexpected message: '+data); }} };
activeWS.onmessage = ({data}) => { // Moving to top gives errors due to NativeModules not being initialized const HMRLoadingView = require('HMRLoadingView'); data = JSON.parse(data); switch (data.type) { case 'update-start': { HMRLoadingView.showMessage('Hot Loading...'); break; } case 'update': { const { modules, sourceMappingURLs, sourceURLs, inverseDependencies, } = data.body; if (Platform.OS === 'ios' || Platform.OS === 'osx') { const RCTRedBox = require('NativeModules').RedBox; RCTRedBox && RCTRedBox.dismiss && RCTRedBox.dismiss(); } else { const RCTExceptionsManager = require('NativeModules').ExceptionsManager; RCTExceptionsManager && RCTExceptionsManager.dismissRedbox && RCTExceptionsManager.dismissRedbox(); } modules.forEach(({name, code}, i) => { code = code + '\n\n' + sourceMappingURLs[i]; require('SourceMapsCache').fetch({ text: code, url: sourceURLs[i], sourceMappingURL: sourceMappingURLs[i], }); // on JSC we need to inject from native for sourcemaps to work // (Safari doesn't support `sourceMappingURL` nor any variant when // evaluating code) but on Chrome we can simply use eval const injectFunction = typeof global.nativeInjectHMRUpdate === 'function' ? global.nativeInjectHMRUpdate : eval; // TODO: (martinb) yellow box if cannot accept module code = ` __accept( ${name}, function(global, require, module, exports) { ${code} }, ${JSON.stringify(inverseDependencies)} );`; injectFunction(code, sourceURLs[i]); }); HMRLoadingView.hide(); break; } case 'update-done': { HMRLoadingView.hide(); break; } case 'error': { HMRLoadingView.hide(); throw new Error(data.body.type + ' ' + data.body.description); } default: { throw new Error(`Unexpected message: ${data}`); } } };
hmrClient.on('update-start', () => { HMRLoadingView.showMessage('Hot Loading...'); });
activeWS.onmessage = ({data}) => { // Moving to top gives errors due to NativeModules not being initialized const HMRLoadingView = require('HMRLoadingView'); data = JSON.parse(data); switch (data.type) { case 'update-start': { HMRLoadingView.showMessage('Hot Loading...'); break; } case 'update': { const { modules, sourceMappingURLs, sourceURLs, inverseDependencies, } = data.body; if (Platform.OS === 'ios') { const RCTRedBox = require('NativeModules').RedBox; RCTRedBox && RCTRedBox.dismiss && RCTRedBox.dismiss(); } else { const RCTExceptionsManager = require('NativeModules').ExceptionsManager; RCTExceptionsManager && RCTExceptionsManager.dismissRedbox && RCTExceptionsManager.dismissRedbox(); } let serverHost; if (Platform.OS === 'android') { serverHost = require('NativeModules').AndroidConstants.ServerHost; } else { serverHost = port ? `${host}:${port}` : host; } modules.forEach(({id, code}, i) => { code = code + '\n\n' + sourceMappingURLs[i]; require('SourceMapsCache').fetch({ text: code, url: `http://${serverHost}${sourceURLs[i]}`, sourceMappingURL: sourceMappingURLs[i], }); // on JSC we need to inject from native for sourcemaps to work // (Safari doesn't support `sourceMappingURL` nor any variant when // evaluating code) but on Chrome we can simply use eval const injectFunction = typeof global.nativeInjectHMRUpdate === 'function' ? global.nativeInjectHMRUpdate : eval; code = [ `__accept(`, `${id},`, `function(global,require,module,exports){`, `${code}`, '\n},', `${JSON.stringify(inverseDependencies)}`, `);`, ].join(''); injectFunction(code, sourceURLs[i]); }); HMRLoadingView.hide(); break; } case 'update-done': { HMRLoadingView.hide(); break; } case 'error': { HMRLoadingView.hide(); throw new Error(data.body.type + ' ' + data.body.description); } default: { throw new Error(`Unexpected message: ${data}`); } } };