Skip to content

Commit 91b8982

Browse files
authored
feat(extension): use persist from app (#821)
* feat(extension): use persist from app * Fix imports
1 parent a640e73 commit 91b8982

File tree

9 files changed

+24
-57
lines changed

9 files changed

+24
-57
lines changed

extension/src/app/middlewares/api.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function getReducerError() {
355355

356356
function togglePersist() {
357357
const state = window.store.getState();
358-
if (state.persistStates) {
358+
if (state.instances.persisted) {
359359
Object.keys(state.instances.connections).forEach((id) => {
360360
if (connections.tab[id]) return;
361361
window.store.dispatch({ type: REMOVE_INSTANCE, id });
@@ -492,7 +492,7 @@ function disconnect(
492492
if (p) p.onDisconnect.removeListener(disconnectListener);
493493
delete connections[type][id];
494494
if (type === 'tab') {
495-
if (!window.store.getState().persistStates) {
495+
if (!window.store.getState().instances.persisted) {
496496
window.store.dispatch({ type: REMOVE_INSTANCE, id });
497497
toMonitors({ type: 'NA', id });
498498
}
@@ -522,7 +522,7 @@ function onConnect<S, A extends Action<unknown>>(port: chrome.runtime.Port) {
522522
if (isMonitored) port.postMessage({ type: 'START' });
523523

524524
const state = window.store.getState();
525-
if (state.persistStates) {
525+
if (state.instances.persisted) {
526526
const instanceId = `${id}/${msg.instanceId}`;
527527
const persistedState = state.instances.states[instanceId];
528528
if (!persistedState) return;
@@ -585,7 +585,6 @@ window.syncOptions = syncOptions(toAllTabs); // Expose to the options page
585585
export default function api() {
586586
return (next: Dispatch<BackgroundAction>) => (action: BackgroundAction) => {
587587
if (action.type === LIFTED_ACTION) toContentScript(action);
588-
else if (action.type === 'TOGGLE_PERSIST') togglePersist();
589588
return next(action);
590589
};
591590
}

extension/src/app/middlewares/panelSync.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ import {
66
import { getActiveInstance } from '@redux-devtools/app/lib/reducers/instances';
77
import { Dispatch, MiddlewareAPI } from 'redux';
88
import { StoreState } from '@redux-devtools/app/lib/reducers';
9-
import { StoreActionWithTogglePersist } from '../stores/windowStore';
9+
import { StoreAction } from '@redux-devtools/app/lib/actions';
1010

1111
function panelDispatcher(bgConnection: chrome.runtime.Port) {
1212
let autoselected = false;
1313
const tabId = chrome.devtools.inspectedWindow.tabId;
1414

15-
return (
16-
store: MiddlewareAPI<Dispatch<StoreActionWithTogglePersist>, StoreState>
17-
) =>
18-
(next: Dispatch<StoreActionWithTogglePersist>) =>
19-
(action: StoreActionWithTogglePersist) => {
15+
return (store: MiddlewareAPI<Dispatch<StoreAction>, StoreState>) =>
16+
(next: Dispatch<StoreAction>) =>
17+
(action: StoreAction) => {
2018
const result = next(action);
2119
if (!autoselected && action.type === UPDATE_STATE && tabId) {
2220
autoselected = true;
@@ -25,7 +23,7 @@ function panelDispatcher(bgConnection: chrome.runtime.Port) {
2523
next({ type: SELECT_INSTANCE, selected: connections[0] });
2624
}
2725
}
28-
if (action.type === LIFTED_ACTION || action.type === 'TOGGLE_PERSIST') {
26+
if (action.type === LIFTED_ACTION) {
2927
const instances = store.getState().instances;
3028
const instanceId = getActiveInstance(instances);
3129
const id = instances.options[instanceId].connectionId;

extension/src/app/middlewares/windowSync.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,22 @@ import { getActiveInstance } from '@redux-devtools/app/lib/reducers/instances';
66
import { Dispatch, MiddlewareAPI, Store } from 'redux';
77
import { BackgroundState } from '../reducers/background';
88
import { StoreAction } from '@redux-devtools/app/lib/actions';
9-
import {
10-
WindowStoreAction,
11-
StoreActionWithTogglePersist,
12-
} from '../stores/windowStore';
9+
import { WindowStoreAction } from '../stores/windowStore';
1310
import { StoreState } from '@redux-devtools/app/lib/reducers';
1411
import { BackgroundAction } from '../stores/backgroundStore';
1512

1613
const syncStores =
1714
(baseStore: Store<BackgroundState, BackgroundAction>) =>
1815
(store: MiddlewareAPI<Dispatch<StoreAction>, StoreState>) =>
1916
(next: Dispatch<WindowStoreAction>) =>
20-
(action: StoreActionWithTogglePersist) => {
17+
(action: StoreAction) => {
2118
if (action.type === UPDATE_STATE) {
2219
return next({
2320
...action,
2421
instances: baseStore.getState().instances,
2522
});
2623
}
27-
if (action.type === LIFTED_ACTION || action.type === 'TOGGLE_PERSIST') {
24+
if (action.type === LIFTED_ACTION) {
2825
const instances = store.getState().instances;
2926
const instanceId = getActiveInstance(instances);
3027
const id = instances.options[instanceId].connectionId;

extension/src/app/reducers/background/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ import { combineReducers, Reducer } from 'redux';
22
import instances, {
33
InstancesState,
44
} from '@redux-devtools/app/lib/reducers/instances';
5-
import persistStates from './persistStates';
65
import { BackgroundAction } from '../../stores/backgroundStore';
76

87
export interface BackgroundState {
98
readonly instances: InstancesState;
10-
readonly persistStates: boolean;
119
}
1210

1311
const rootReducer: Reducer<BackgroundState, BackgroundAction> =
1412
combineReducers<BackgroundState>({
1513
instances,
16-
persistStates,
1714
});
1815

1916
export default rootReducer;

extension/src/app/reducers/background/persistStates.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

extension/src/app/reducers/panel/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import theme, { ThemeState } from '@redux-devtools/app/lib/reducers/theme';
1818
import connection, {
1919
ConnectionState,
2020
} from '@redux-devtools/app/lib/reducers/connection';
21-
import { StoreActionWithTogglePersist } from '../../stores/windowStore';
21+
import { StoreAction } from '@redux-devtools/app/lib/actions';
2222

2323
export interface StoreStateWithoutSocket {
2424
readonly section: SectionState;
@@ -30,17 +30,15 @@ export interface StoreStateWithoutSocket {
3030
readonly notification: NotificationState;
3131
}
3232

33-
const rootReducer: Reducer<
34-
StoreStateWithoutSocket,
35-
StoreActionWithTogglePersist
36-
> = combineReducers<StoreStateWithoutSocket>({
37-
instances,
38-
monitor,
39-
reports,
40-
notification,
41-
section,
42-
theme,
43-
connection,
44-
});
33+
const rootReducer: Reducer<StoreStateWithoutSocket, StoreAction> =
34+
combineReducers<StoreStateWithoutSocket>({
35+
instances,
36+
monitor,
37+
reports,
38+
notification,
39+
section,
40+
theme,
41+
connection,
42+
});
4543

4644
export default rootReducer;

extension/src/app/stores/backgroundStore.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ export type LiftedActionAction =
4545
| LiftedActionActionAction
4646
| LiftedActionExportAction;
4747

48-
interface TogglePersistAction {
49-
readonly type: 'TOGGLE_PERSIST';
50-
readonly instanceId: string | number;
51-
readonly id: string | number | undefined;
52-
}
53-
5448
interface ConnectedAction {
5549
readonly type: typeof CONNECTED;
5650
}
@@ -62,7 +56,6 @@ interface DisconnectedAction {
6256
export type BackgroundAction =
6357
| StoreActionWithoutLiftedAction
6458
| LiftedActionAction
65-
| TogglePersistAction
6659
| ConnectedAction
6760
| DisconnectedAction;
6861

extension/src/app/stores/windowStore.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,12 @@ import { BackgroundState } from '../reducers/background';
2323
import { BackgroundAction } from './backgroundStore';
2424
import { EmptyUpdateStateAction, NAAction } from '../middlewares/api';
2525

26-
export interface TogglePersistAction {
27-
readonly type: 'TOGGLE_PERSIST';
28-
}
29-
30-
export type StoreActionWithTogglePersist = StoreAction | TogglePersistAction;
31-
3226
export interface ExpandedUpdateStateAction extends UpdateStateAction {
3327
readonly instances: InstancesState;
3428
}
3529

3630
export type WindowStoreAction =
3731
| StoreActionWithoutUpdateState
38-
| TogglePersistAction
3932
| ExpandedUpdateStateAction
4033
| NAAction
4134
| EmptyUpdateStateAction;

extension/src/browser/extension/devpanel/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import getPreloadedState from '../background/getPreloadedState';
99
import '../../views/devpanel.pug';
1010
import { Action, PreloadedState, Store } from 'redux';
1111
import { StoreState } from '@redux-devtools/app/lib/reducers';
12+
import { StoreAction } from '@redux-devtools/app/lib/actions';
1213
import { PanelMessage } from '../../../app/middlewares/api';
13-
import { StoreActionWithTogglePersist } from '../../../app/stores/windowStore';
1414
import { StoreStateWithoutSocket } from '../../../app/reducers/panel';
1515

1616
const position = location.hash;
@@ -21,9 +21,7 @@ const messageStyle: CSSProperties = {
2121
};
2222

2323
let rendered: boolean | undefined;
24-
let store:
25-
| Store<StoreStateWithoutSocket, StoreActionWithTogglePersist>
26-
| undefined;
24+
let store: Store<StoreStateWithoutSocket, StoreAction> | undefined;
2725
let bgConnection: chrome.runtime.Port;
2826
let naTimeout: NodeJS.Timeout;
2927
let preloadedState: PreloadedState<StoreState>;

0 commit comments

Comments
 (0)