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
This commit is contained in:
Pascal Hartig
2018-09-17 08:50:01 -07:00
committed by Facebook Github Bot
parent 7dd4a83c9a
commit 175ba7f331
5 changed files with 34 additions and 16 deletions

10
src/__mocks__/init.js Normal file
View File

@@ -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
}

View File

@@ -14,9 +14,8 @@ export {SonarBasePlugin, SonarPlugin, SonarDevicePlugin} from './plugin.js';
export {createTablePlugin} from './createTablePlugin.js'; export {createTablePlugin} from './createTablePlugin.js';
export {default as SonarSidebar} from './chrome/SonarSidebar.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 AndroidDevice} from './devices/AndroidDevice.js';
export {default as Device} from './devices/BaseDevice.js'; export {default as Device} from './devices/BaseDevice.js';
export {default as IOSDevice} from './devices/IOSDevice.js'; export {default as IOSDevice} from './devices/IOSDevice.js';
export {default as init} from './init.js';

View File

@@ -62,16 +62,18 @@ const AppFrame = () => (
</TooltipProvider> </TooltipProvider>
); );
// $FlowFixMe: this element exists! export default function init() {
ReactDOM.render(<AppFrame />, document.getElementById('root')); // $FlowFixMe: this element exists!
// $FlowFixMe: service workers exist! ReactDOM.render(<AppFrame />, document.getElementById('root'));
navigator.serviceWorker // $FlowFixMe: service workers exist!
.register( navigator.serviceWorker
process.env.NODE_ENV === 'production' .register(
? path.join(__dirname, 'serviceWorker.js') process.env.NODE_ENV === 'production'
: './serviceWorker.js', ? path.join(__dirname, 'serviceWorker.js')
) : './serviceWorker.js',
.then(r => { )
(r.installing || r.active).postMessage({precachedIcons}); .then(r => {
}) (r.installing || r.active).postMessage({precachedIcons});
.catch(console.error); })
.catch(console.error);
}

View File

@@ -85,6 +85,10 @@
openError('Script failure. Check Chrome console for more info.'); openError('Script failure. Check Chrome console for more info.');
}; };
script.onload = () => {
global.Sonar.init();
};
document.body.appendChild(script); document.body.appendChild(script);
} }

View File

@@ -14,5 +14,8 @@
global.electronRequire = window.require; global.electronRequire = window.require;
</script> </script>
<script src="bundle.js"></script> <script src="bundle.js"></script>
<script>
global.Sonar.init();
</script>
</body> </body>
</html> </html>