Make Store initialization independent of module order
Summary: Changed some imports, and again the Flipper initialisation broke. Refactored the store initialization to create nowhere module local constants, which prevents generally against module loading issues, making it possible to load all code first, and then intialise things through the `init()` method, which should make Flipper initialisation a lot more robust to changes Reviewed By: passy Differential Revision: D29233603 fbshipit-source-id: 322cb87cba23228b1d7a88634b7b3995e27cc277
This commit is contained in:
committed by
Facebook GitHub Bot
parent
806dd63f68
commit
6fb28df855
@@ -24,7 +24,7 @@ import {initLauncherHooks} from './utils/launcher';
|
||||
import {setPersistor} from './utils/persistor';
|
||||
import React from 'react';
|
||||
import path from 'path';
|
||||
import {store} from './store';
|
||||
import {getStore} from './store';
|
||||
import {cache} from '@emotion/css';
|
||||
import {CacheProvider} from '@emotion/react';
|
||||
import {enableMapSet} from 'immer';
|
||||
@@ -59,8 +59,6 @@ if (process.env.NODE_ENV === 'development' && os.platform() === 'darwin') {
|
||||
global.electronRequire('mac-ca');
|
||||
}
|
||||
|
||||
const logger = initLogger(store);
|
||||
|
||||
enableMapSet();
|
||||
|
||||
GK.init();
|
||||
@@ -127,7 +125,7 @@ class AppFrame extends React.Component<
|
||||
</Layout.Container>
|
||||
) : (
|
||||
<_LoggerContext.Provider value={logger}>
|
||||
<Provider store={store}>
|
||||
<Provider store={getStore()}>
|
||||
<CacheProvider value={cache}>
|
||||
<TooltipProvider>
|
||||
<PopoverProvider>
|
||||
@@ -181,6 +179,18 @@ function setProcessState(store: Store) {
|
||||
}
|
||||
|
||||
function init() {
|
||||
const store = getStore();
|
||||
const logger = initLogger(store);
|
||||
|
||||
// rehydrate app state before exposing init
|
||||
const persistor = persistStore(store, undefined, () => {
|
||||
// Make sure process state is set before dispatchers run
|
||||
setProcessState(store);
|
||||
dispatcher(store, logger);
|
||||
});
|
||||
|
||||
setPersistor(persistor);
|
||||
|
||||
initializeFlipperLibImplementation(store, logger);
|
||||
_setGlobalInteractionReporter((r) => {
|
||||
logger.track('usage', 'interaction', r);
|
||||
@@ -213,18 +223,13 @@ function init() {
|
||||
);
|
||||
}
|
||||
|
||||
// rehydrate app state before exposing init
|
||||
const persistor = persistStore(store, undefined, () => {
|
||||
// Make sure process state is set before dispatchers run
|
||||
setProcessState(store);
|
||||
dispatcher(store, logger);
|
||||
// make init function callable from outside
|
||||
window.Flipper.init = init;
|
||||
setImmediate(() => {
|
||||
// make sure all modules are loaded
|
||||
// @ts-ignore
|
||||
window.flipperInit = init;
|
||||
window.dispatchEvent(new Event('flipper-store-ready'));
|
||||
});
|
||||
|
||||
setPersistor(persistor);
|
||||
|
||||
const CodeBlock = styled(Input.TextArea)({
|
||||
...theme.monospace,
|
||||
color: theme.textColorSecondary,
|
||||
|
||||
Reference in New Issue
Block a user