From 175ba7f33189361dc41883f6eefefa339991ecbf Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Mon, 17 Sep 2018 08:50:01 -0700 Subject: [PATCH] Remove import-sideffect call to init() Summary: Back out "Back out "[flipper] Export init function"" Original commit changeset: 93b916d472b7 The import side effect seems to cause some issues with shadowing, so let's pull this all the way to the top and call this from HTML as Sonar.init(). Reviewed By: danielbuechele Differential Revision: D9849869 fbshipit-source-id: b62772ecddc59eab00251ebf19816f470d76ba82 --- src/__mocks__/init.js | 10 ++++++++++ src/index.js | 5 ++--- src/init.js | 28 +++++++++++++++------------- static/index.dev.html | 4 ++++ static/index.html | 3 +++ 5 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 src/__mocks__/init.js diff --git a/src/__mocks__/init.js b/src/__mocks__/init.js new file mode 100644 index 000000000..9c5f81382 --- /dev/null +++ b/src/__mocks__/init.js @@ -0,0 +1,10 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +export default function init() { + // no-op +} diff --git a/src/index.js b/src/index.js index a96b95e75..d2c337503 100644 --- a/src/index.js +++ b/src/index.js @@ -14,9 +14,8 @@ export {SonarBasePlugin, SonarPlugin, SonarDevicePlugin} from './plugin.js'; export {createTablePlugin} from './createTablePlugin.js'; export {default as SonarSidebar} from './chrome/SonarSidebar.js'; -export * from './init.js'; -export {default} from './init.js'; - export {default as AndroidDevice} from './devices/AndroidDevice.js'; export {default as Device} from './devices/BaseDevice.js'; export {default as IOSDevice} from './devices/IOSDevice.js'; + +export {default as init} from './init.js'; diff --git a/src/init.js b/src/init.js index 96a47ff8c..657489b21 100644 --- a/src/init.js +++ b/src/init.js @@ -62,16 +62,18 @@ const AppFrame = () => ( ); -// $FlowFixMe: this element exists! -ReactDOM.render(, document.getElementById('root')); -// $FlowFixMe: service workers exist! -navigator.serviceWorker - .register( - process.env.NODE_ENV === 'production' - ? path.join(__dirname, 'serviceWorker.js') - : './serviceWorker.js', - ) - .then(r => { - (r.installing || r.active).postMessage({precachedIcons}); - }) - .catch(console.error); +export default function init() { + // $FlowFixMe: this element exists! + ReactDOM.render(, document.getElementById('root')); + // $FlowFixMe: service workers exist! + navigator.serviceWorker + .register( + process.env.NODE_ENV === 'production' + ? path.join(__dirname, 'serviceWorker.js') + : './serviceWorker.js', + ) + .then(r => { + (r.installing || r.active).postMessage({precachedIcons}); + }) + .catch(console.error); +} diff --git a/static/index.dev.html b/static/index.dev.html index c50347685..fecdbcfc4 100644 --- a/static/index.dev.html +++ b/static/index.dev.html @@ -85,6 +85,10 @@ openError('Script failure. Check Chrome console for more info.'); }; + script.onload = () => { + global.Sonar.init(); + }; + document.body.appendChild(script); } diff --git a/static/index.html b/static/index.html index a2e80969a..499dfa068 100644 --- a/static/index.html +++ b/static/index.html @@ -14,5 +14,8 @@ global.electronRequire = window.require; +