forked from facebook/flipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
65 lines (58 loc) · 1.91 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* 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
*/
import {Provider} from 'react-redux';
import ReactDOM from 'react-dom';
import {ContextMenuProvider} from 'flipper';
import {precachedIcons} from './utils/icons.js';
import GK from './fb-stubs/GK.js';
import {init as initLogger} from './fb-stubs/Logger';
import App from './App.js';
import BugReporter from './fb-stubs/BugReporter.js';
import {createStore} from 'redux';
import {persistStore} from 'redux-persist';
import reducers from './reducers/index.js';
import dispatcher from './dispatcher/index.js';
import TooltipProvider from './ui/components/TooltipProvider.js';
import config from './utils/processConfig.js';
import {initLauncherHooks} from './utils/launcher.js';
const path = require('path');
const store = createStore(
reducers,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
);
persistStore(store);
const logger = initLogger(store);
const bugReporter = new BugReporter(logger, store);
dispatcher(store, logger);
GK.init();
const AppFrame = () => (
<TooltipProvider>
<ContextMenuProvider>
<Provider store={store}>
<App logger={logger} bugReporter={bugReporter} />
</Provider>
</ContextMenuProvider>
</TooltipProvider>
);
function init() {
// $FlowFixMe: this element exists!
ReactDOM.render(<AppFrame />, 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);
initLauncherHooks(config(), store);
}
// make init function callable from outside
window.Flipper.init = init;