redux-devtools/packages/redux-devtools-app/src/index.tsx

58 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-01-03 17:14:25 +03:00
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { Store } from 'redux';
import { Persistor } from 'redux-persist';
import { PersistGate } from 'redux-persist/integration/react';
2019-01-03 17:14:25 +03:00
import configureStore from './store/configureStore';
import { CONNECT_REQUEST } from './constants/socketActionTypes';
import App from './containers/App';
import { StoreState } from './reducers';
import { StoreAction, applyMediaFeaturesPreferences } from './actions';
class Root extends Component {
store?: Store<StoreState, StoreAction>;
persistor?: Persistor;
2019-01-03 17:14:25 +03:00
UNSAFE_componentWillMount() {
const { store, persistor } = configureStore(
(store: Store<StoreState, StoreAction>) => {
if (store.getState().connection.type !== 'disabled') {
store.dispatch({
type: CONNECT_REQUEST,
});
}
}
);
this.store = store;
this.persistor = persistor;
2019-01-03 17:14:25 +03:00
}
/**
* @hidden
* @private
*/
private _checkMediaFeaturesPreferences = () => {
if (this.store) {
this.store.dispatch(applyMediaFeaturesPreferences());
}
};
2019-01-03 17:14:25 +03:00
render() {
if (!this.store) return null;
2019-01-03 17:14:25 +03:00
return (
<Provider store={this.store}>
<PersistGate
loading={null}
persistor={this.persistor!}
onBeforeLift={this._checkMediaFeaturesPreferences}
>
<App />
</PersistGate>
2019-01-03 17:14:25 +03:00
</Provider>
);
}
}
export default Root;