mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-21 21:49:55 +03:00
Changes
This commit is contained in:
parent
e9be680533
commit
720ab4fbfb
|
@ -63,17 +63,14 @@ export default function configureStore(
|
|||
}
|
||||
const store = createStore(rootReducer, preloadedState, enhancer);
|
||||
|
||||
chrome.storage.local.get(['s:hostname', 's:port', 's:secure'], (options) => {
|
||||
if (!options['s:hostname'] || !options['s:port']) return;
|
||||
if (
|
||||
store.getState().connection.options.hostname &&
|
||||
store.getState().connection.options.port
|
||||
) {
|
||||
store.dispatch({
|
||||
type: CONNECT_REQUEST,
|
||||
options: {
|
||||
hostname: options['s:hostname'],
|
||||
port: options['s:port'],
|
||||
secure: options['s:secure'],
|
||||
} as any,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return store;
|
||||
}
|
||||
|
|
|
@ -446,7 +446,6 @@ export interface RemoveInstanceAction {
|
|||
|
||||
export interface ConnectRequestAction {
|
||||
type: typeof CONNECT_REQUEST;
|
||||
options: ConnectionOptions;
|
||||
}
|
||||
|
||||
interface ConnectSuccessPayload {
|
||||
|
|
|
@ -16,15 +16,11 @@ class Root extends Component<Props> {
|
|||
store?: Store<StoreState, StoreAction>;
|
||||
|
||||
UNSAFE_componentWillMount() {
|
||||
configureStore((store, preloadedState) => {
|
||||
this.store = store;
|
||||
store.dispatch({
|
||||
type: CONNECT_REQUEST,
|
||||
options: (preloadedState!.connection ||
|
||||
this.props.socketOptions) as ConnectionOptions,
|
||||
});
|
||||
this.forceUpdate();
|
||||
this.store = configureStore();
|
||||
this.store.dispatch({
|
||||
type: CONNECT_REQUEST,
|
||||
});
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -1,66 +1,49 @@
|
|||
import { createStore, compose, applyMiddleware, Store } from 'redux';
|
||||
import { createStore, compose, applyMiddleware } from 'redux';
|
||||
import localForage from 'localforage';
|
||||
import {
|
||||
getStoredState,
|
||||
createPersistor,
|
||||
PersistorConfig,
|
||||
} from 'redux-persist';
|
||||
import { persistReducer, persistStore } from 'redux-persist';
|
||||
import api from '../middlewares/api';
|
||||
import exportState from '../middlewares/exportState';
|
||||
import rootReducer, { StoreState } from '../reducers';
|
||||
import { StoreAction } from '../actions';
|
||||
|
||||
export default function configureStore(
|
||||
callback: (
|
||||
store: Store<StoreState, StoreAction>,
|
||||
restoredState: Partial<StoreState> | undefined
|
||||
) => void,
|
||||
key?: string
|
||||
) {
|
||||
const persistConfig: PersistorConfig = {
|
||||
keyPrefix: `redux-devtools${key || ''}:`,
|
||||
blacklist: ['instances', 'socket'],
|
||||
storage: localForage,
|
||||
serialize: (data: unknown) => data,
|
||||
deserialize: (data: unknown) => data,
|
||||
} as unknown as PersistorConfig;
|
||||
const persistConfig = {
|
||||
key: 'redux-devtools',
|
||||
blacklist: ['instances', 'socket'],
|
||||
storage: localForage,
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
getStoredState<StoreState>(persistConfig, (err, restoredState) => {
|
||||
let composeEnhancers = compose;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (
|
||||
(
|
||||
window as unknown as {
|
||||
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
|
||||
}
|
||||
).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
||||
) {
|
||||
composeEnhancers = (
|
||||
window as unknown as {
|
||||
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: typeof compose;
|
||||
}
|
||||
).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
|
||||
}
|
||||
if (module.hot) {
|
||||
// Enable Webpack hot module replacement for reducers
|
||||
module.hot.accept('../reducers', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const nextReducer = require('../reducers'); // eslint-disable-line global-require
|
||||
store.replaceReducer(nextReducer);
|
||||
});
|
||||
}
|
||||
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
||||
|
||||
export default function configureStore() {
|
||||
let composeEnhancers = compose;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (
|
||||
(
|
||||
window as unknown as {
|
||||
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
|
||||
}
|
||||
).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
||||
) {
|
||||
composeEnhancers = (
|
||||
window as unknown as {
|
||||
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: typeof compose;
|
||||
}
|
||||
).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
|
||||
}
|
||||
if (module.hot) {
|
||||
// Enable Webpack hot module replacement for reducers
|
||||
module.hot.accept('../reducers', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const nextReducer = require('../reducers'); // eslint-disable-line global-require
|
||||
store.replaceReducer(nextReducer);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const store = createStore(
|
||||
rootReducer,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
restoredState,
|
||||
composeEnhancers(applyMiddleware(exportState, api))
|
||||
);
|
||||
const persistor = createPersistor(store, persistConfig);
|
||||
callback(store, restoredState);
|
||||
if (err) persistor.purge();
|
||||
});
|
||||
const store = createStore<StoreState, StoreAction, unknown, unknown>(
|
||||
persistedReducer as any,
|
||||
composeEnhancers(applyMiddleware(exportState, api))
|
||||
);
|
||||
persistStore(store);
|
||||
return store;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user