mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-02-07 15:10:45 +03:00
fix(extension): fix state persisting (#843)
This commit is contained in:
parent
515953a118
commit
370b5e6df3
|
@ -3,6 +3,8 @@ import {
|
||||||
UPDATE_STATE,
|
UPDATE_STATE,
|
||||||
REMOVE_INSTANCE,
|
REMOVE_INSTANCE,
|
||||||
LIFTED_ACTION,
|
LIFTED_ACTION,
|
||||||
|
TOGGLE_PERSIST,
|
||||||
|
SET_PERSIST,
|
||||||
} from '@redux-devtools/app/lib/constants/actionTypes';
|
} from '@redux-devtools/app/lib/constants/actionTypes';
|
||||||
import { nonReduxDispatch } from '@redux-devtools/app/lib/utils/monitorActions';
|
import { nonReduxDispatch } from '@redux-devtools/app/lib/utils/monitorActions';
|
||||||
import syncOptions, {
|
import syncOptions, {
|
||||||
|
@ -18,8 +20,9 @@ import {
|
||||||
CustomAction,
|
CustomAction,
|
||||||
DispatchAction as AppDispatchAction,
|
DispatchAction as AppDispatchAction,
|
||||||
LibConfig,
|
LibConfig,
|
||||||
|
SetPersistAction,
|
||||||
} from '@redux-devtools/app/lib/actions';
|
} from '@redux-devtools/app/lib/actions';
|
||||||
import { Action, Dispatch } from 'redux';
|
import { Action, Dispatch, MiddlewareAPI } from 'redux';
|
||||||
import {
|
import {
|
||||||
ContentScriptToBackgroundMessage,
|
ContentScriptToBackgroundMessage,
|
||||||
SplitMessage,
|
SplitMessage,
|
||||||
|
@ -35,6 +38,7 @@ import {
|
||||||
LiftedActionAction,
|
LiftedActionAction,
|
||||||
} from '../stores/backgroundStore';
|
} from '../stores/backgroundStore';
|
||||||
import { Position } from '../api/openWindow';
|
import { Position } from '../api/openWindow';
|
||||||
|
import { BackgroundState } from '../reducers/background';
|
||||||
|
|
||||||
interface TabMessageBase {
|
interface TabMessageBase {
|
||||||
readonly type: string;
|
readonly type: string;
|
||||||
|
@ -183,8 +187,13 @@ export type TabMessage =
|
||||||
export type PanelMessage<S, A extends Action<unknown>> =
|
export type PanelMessage<S, A extends Action<unknown>> =
|
||||||
| NAAction
|
| NAAction
|
||||||
| ErrorMessage
|
| ErrorMessage
|
||||||
| UpdateStateAction<S, A>;
|
| UpdateStateAction<S, A>
|
||||||
export type MonitorMessage = NAAction | ErrorMessage | EmptyUpdateStateAction;
|
| SetPersistAction;
|
||||||
|
export type MonitorMessage =
|
||||||
|
| NAAction
|
||||||
|
| ErrorMessage
|
||||||
|
| EmptyUpdateStateAction
|
||||||
|
| SetPersistAction;
|
||||||
|
|
||||||
type TabPort = Omit<chrome.runtime.Port, 'postMessage'> & {
|
type TabPort = Omit<chrome.runtime.Port, 'postMessage'> & {
|
||||||
postMessage: (message: TabMessage) => void;
|
postMessage: (message: TabMessage) => void;
|
||||||
|
@ -224,7 +233,8 @@ const getId = (sender: chrome.runtime.MessageSender, name?: string) =>
|
||||||
type MonitorAction<S, A extends Action<unknown>> =
|
type MonitorAction<S, A extends Action<unknown>> =
|
||||||
| NAAction
|
| NAAction
|
||||||
| ErrorMessage
|
| ErrorMessage
|
||||||
| UpdateStateAction<S, A>;
|
| UpdateStateAction<S, A>
|
||||||
|
| SetPersistAction;
|
||||||
|
|
||||||
function toMonitors<S, A extends Action<unknown>>(
|
function toMonitors<S, A extends Action<unknown>>(
|
||||||
action: MonitorAction<S, A>,
|
action: MonitorAction<S, A>,
|
||||||
|
@ -233,7 +243,9 @@ function toMonitors<S, A extends Action<unknown>>(
|
||||||
) {
|
) {
|
||||||
Object.keys(connections.monitor).forEach((id) => {
|
Object.keys(connections.monitor).forEach((id) => {
|
||||||
connections.monitor[id].postMessage(
|
connections.monitor[id].postMessage(
|
||||||
verbose || action.type === 'ERROR' ? action : { type: UPDATE_STATE }
|
verbose || action.type === 'ERROR' || action.type === SET_PERSIST
|
||||||
|
? action
|
||||||
|
: { type: UPDATE_STATE }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
Object.keys(connections.panel).forEach((id) => {
|
Object.keys(connections.panel).forEach((id) => {
|
||||||
|
@ -582,9 +594,18 @@ declare global {
|
||||||
|
|
||||||
window.syncOptions = syncOptions(toAllTabs); // Expose to the options page
|
window.syncOptions = syncOptions(toAllTabs); // Expose to the options page
|
||||||
|
|
||||||
export default function api() {
|
export default function api(
|
||||||
|
store: MiddlewareAPI<Dispatch<BackgroundAction>, BackgroundState>
|
||||||
|
) {
|
||||||
return (next: Dispatch<BackgroundAction>) => (action: BackgroundAction) => {
|
return (next: Dispatch<BackgroundAction>) => (action: BackgroundAction) => {
|
||||||
if (action.type === LIFTED_ACTION) toContentScript(action);
|
if (action.type === LIFTED_ACTION) toContentScript(action);
|
||||||
|
else if (action.type === TOGGLE_PERSIST) {
|
||||||
|
togglePersist();
|
||||||
|
toMonitors({
|
||||||
|
type: SET_PERSIST,
|
||||||
|
payload: !store.getState().instances.persisted,
|
||||||
|
});
|
||||||
|
}
|
||||||
return next(action);
|
return next(action);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {
|
||||||
LIFTED_ACTION,
|
LIFTED_ACTION,
|
||||||
UPDATE_STATE,
|
UPDATE_STATE,
|
||||||
SELECT_INSTANCE,
|
SELECT_INSTANCE,
|
||||||
|
TOGGLE_PERSIST,
|
||||||
} from '@redux-devtools/app/lib/constants/actionTypes';
|
} from '@redux-devtools/app/lib/constants/actionTypes';
|
||||||
import { getActiveInstance } from '@redux-devtools/app/lib/reducers/instances';
|
import { getActiveInstance } from '@redux-devtools/app/lib/reducers/instances';
|
||||||
import { Dispatch, MiddlewareAPI } from 'redux';
|
import { Dispatch, MiddlewareAPI } from 'redux';
|
||||||
|
@ -23,7 +24,7 @@ function panelDispatcher(bgConnection: chrome.runtime.Port) {
|
||||||
next({ type: SELECT_INSTANCE, selected: connections[0] });
|
next({ type: SELECT_INSTANCE, selected: connections[0] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (action.type === LIFTED_ACTION) {
|
if (action.type === LIFTED_ACTION || action.type === TOGGLE_PERSIST) {
|
||||||
const instances = store.getState().instances;
|
const instances = store.getState().instances;
|
||||||
const instanceId = getActiveInstance(instances);
|
const instanceId = getActiveInstance(instances);
|
||||||
const id = instances.options[instanceId].connectionId;
|
const id = instances.options[instanceId].connectionId;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
UPDATE_STATE,
|
UPDATE_STATE,
|
||||||
LIFTED_ACTION,
|
LIFTED_ACTION,
|
||||||
|
TOGGLE_PERSIST,
|
||||||
} from '@redux-devtools/app/lib/constants/actionTypes';
|
} from '@redux-devtools/app/lib/constants/actionTypes';
|
||||||
import { getActiveInstance } from '@redux-devtools/app/lib/reducers/instances';
|
import { getActiveInstance } from '@redux-devtools/app/lib/reducers/instances';
|
||||||
import { Dispatch, MiddlewareAPI, Store } from 'redux';
|
import { Dispatch, MiddlewareAPI, Store } from 'redux';
|
||||||
|
@ -21,7 +22,7 @@ const syncStores =
|
||||||
instances: baseStore.getState().instances,
|
instances: baseStore.getState().instances,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (action.type === LIFTED_ACTION) {
|
if (action.type === LIFTED_ACTION || action.type === TOGGLE_PERSIST) {
|
||||||
const instances = store.getState().instances;
|
const instances = store.getState().instances;
|
||||||
const instanceId = getActiveInstance(instances);
|
const instanceId = getActiveInstance(instances);
|
||||||
const id = instances.options[instanceId].connectionId;
|
const id = instances.options[instanceId].connectionId;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
UPDATE_STATE,
|
UPDATE_STATE,
|
||||||
SELECT_INSTANCE,
|
SELECT_INSTANCE,
|
||||||
LIFTED_ACTION,
|
LIFTED_ACTION,
|
||||||
|
SET_PERSIST,
|
||||||
} from '@redux-devtools/app/lib/constants/actionTypes';
|
} from '@redux-devtools/app/lib/constants/actionTypes';
|
||||||
import {
|
import {
|
||||||
ExpandedUpdateStateAction,
|
ExpandedUpdateStateAction,
|
||||||
|
@ -27,6 +28,8 @@ export default function instances(
|
||||||
return state;
|
return state;
|
||||||
case SELECT_INSTANCE:
|
case SELECT_INSTANCE:
|
||||||
return { ...state, selected: action.selected };
|
return { ...state, selected: action.selected };
|
||||||
|
case SET_PERSIST:
|
||||||
|
return { ...state, persisted: action.payload };
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import {
|
||||||
GET_REPORT_ERROR,
|
GET_REPORT_ERROR,
|
||||||
GET_REPORT_SUCCESS,
|
GET_REPORT_SUCCESS,
|
||||||
ERROR,
|
ERROR,
|
||||||
|
SET_PERSIST,
|
||||||
} from '../constants/actionTypes';
|
} from '../constants/actionTypes';
|
||||||
import {
|
import {
|
||||||
AUTH_ERROR,
|
AUTH_ERROR,
|
||||||
|
@ -302,6 +303,14 @@ export function togglePersist(): TogglePersistAction {
|
||||||
return { type: TOGGLE_PERSIST };
|
return { type: TOGGLE_PERSIST };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SetPersistAction {
|
||||||
|
type: typeof SET_PERSIST;
|
||||||
|
payload: boolean;
|
||||||
|
}
|
||||||
|
export function setPersist(persist: boolean): SetPersistAction {
|
||||||
|
return { type: SET_PERSIST, payload: persist };
|
||||||
|
}
|
||||||
|
|
||||||
export interface ToggleSyncAction {
|
export interface ToggleSyncAction {
|
||||||
type: typeof TOGGLE_SYNC;
|
type: typeof TOGGLE_SYNC;
|
||||||
}
|
}
|
||||||
|
@ -561,6 +570,7 @@ export type StoreActionWithoutUpdateStateOrLiftedAction =
|
||||||
| UpdateMonitorStateAction
|
| UpdateMonitorStateAction
|
||||||
| ExportAction
|
| ExportAction
|
||||||
| TogglePersistAction
|
| TogglePersistAction
|
||||||
|
| SetPersistAction
|
||||||
| ToggleSyncAction
|
| ToggleSyncAction
|
||||||
| ToggleSliderAction
|
| ToggleSliderAction
|
||||||
| ToggleDispatcherAction
|
| ToggleDispatcherAction
|
||||||
|
|
|
@ -26,8 +26,8 @@ class LockButton extends Component<Props> {
|
||||||
mark={this.props.persisted && 'base0D'}
|
mark={this.props.persisted && 'base0D'}
|
||||||
title={
|
title={
|
||||||
this.props.persisted
|
this.props.persisted
|
||||||
? 'Persist state history'
|
? 'Disable state persisting'
|
||||||
: 'Disable state persisting'
|
: 'Persist state history'
|
||||||
}
|
}
|
||||||
onClick={this.props.onClick}
|
onClick={this.props.onClick}
|
||||||
>
|
>
|
||||||
|
|
|
@ -9,6 +9,7 @@ export const LIFTED_ACTION = 'devTools/LIFTED_ACTION';
|
||||||
export const MONITOR_ACTION = 'devTools/MONITOR_ACTION';
|
export const MONITOR_ACTION = 'devTools/MONITOR_ACTION';
|
||||||
export const TOGGLE_SYNC = 'devTools/TOGGLE_SYNC';
|
export const TOGGLE_SYNC = 'devTools/TOGGLE_SYNC';
|
||||||
export const TOGGLE_PERSIST = 'devTools/TOGGLE_PERSIST';
|
export const TOGGLE_PERSIST = 'devTools/TOGGLE_PERSIST';
|
||||||
|
export const SET_PERSIST = 'devTools/SET_PERSIST';
|
||||||
export const SELECT_MONITOR = 'devTools/SELECT_MONITOR';
|
export const SELECT_MONITOR = 'devTools/SELECT_MONITOR';
|
||||||
export const UPDATE_MONITOR_STATE = 'devTools/UPDATE_MONITOR_STATE';
|
export const UPDATE_MONITOR_STATE = 'devTools/UPDATE_MONITOR_STATE';
|
||||||
export const TOGGLE_SLIDER = 'devTools/TOGGLE_SLIDER';
|
export const TOGGLE_SLIDER = 'devTools/TOGGLE_SLIDER';
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
REMOVE_INSTANCE,
|
REMOVE_INSTANCE,
|
||||||
TOGGLE_PERSIST,
|
TOGGLE_PERSIST,
|
||||||
TOGGLE_SYNC,
|
TOGGLE_SYNC,
|
||||||
|
SET_PERSIST,
|
||||||
} from '../constants/actionTypes';
|
} from '../constants/actionTypes';
|
||||||
import { DISCONNECTED } from '../constants/socketActionTypes';
|
import { DISCONNECTED } from '../constants/socketActionTypes';
|
||||||
import parseJSON from '../utils/parseJSON';
|
import parseJSON from '../utils/parseJSON';
|
||||||
|
@ -349,6 +350,8 @@ export default function instances(
|
||||||
};
|
};
|
||||||
case TOGGLE_PERSIST:
|
case TOGGLE_PERSIST:
|
||||||
return { ...state, persisted: !state.persisted };
|
return { ...state, persisted: !state.persisted };
|
||||||
|
case SET_PERSIST:
|
||||||
|
return { ...state, persisted: action.payload };
|
||||||
case TOGGLE_SYNC:
|
case TOGGLE_SYNC:
|
||||||
return { ...state, sync: !state.sync };
|
return { ...state, sync: !state.sync };
|
||||||
case SELECT_INSTANCE:
|
case SELECT_INSTANCE:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user