Skip to content

Commit 38660b5

Browse files
kenjiOdarkwing
authored andcommitted
[Breakpoints] remove immutable.js from xhrBreakpoint reducer (firefox-devtools#7487)
1 parent 9845435 commit 38660b5

5 files changed

Lines changed: 29 additions & 30 deletions

File tree

src/actions/breakpoints/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export function toggleDisabledBreakpoint(line: number, column?: number) {
377377
export function enableXHRBreakpoint(index: number, bp: XHRBreakpoint) {
378378
return ({ dispatch, getState, client }: ThunkArgs) => {
379379
const xhrBreakpoints = getXHRBreakpoints(getState());
380-
const breakpoint = bp || xhrBreakpoints.get(index);
380+
const breakpoint = bp || xhrBreakpoints[index];
381381
const enabledBreakpoint = {
382382
...breakpoint,
383383
disabled: false
@@ -395,7 +395,7 @@ export function enableXHRBreakpoint(index: number, bp: XHRBreakpoint) {
395395
export function disableXHRBreakpoint(index: number, bp: XHRBreakpoint) {
396396
return ({ dispatch, getState, client }: ThunkArgs) => {
397397
const xhrBreakpoints = getXHRBreakpoints(getState());
398-
const breakpoint = bp || xhrBreakpoints.get(index);
398+
const breakpoint = bp || xhrBreakpoints[index];
399399
const disabledBreakpoint = {
400400
...breakpoint,
401401
disabled: true
@@ -417,7 +417,7 @@ export function updateXHRBreakpoint(
417417
) {
418418
return ({ dispatch, getState, client }: ThunkArgs) => {
419419
const xhrBreakpoints = getXHRBreakpoints(getState());
420-
const breakpoint = xhrBreakpoints.get(index);
420+
const breakpoint = xhrBreakpoints[index];
421421

422422
const updatedBreakpoint = {
423423
...breakpoint,
@@ -445,7 +445,7 @@ export function togglePauseOnAny() {
445445
return dispatch(setXHRBreakpoint("", "ANY"));
446446
}
447447

448-
const bp = xhrBreakpoints.get(index);
448+
const bp = xhrBreakpoints[index];
449449
if (bp.disabled) {
450450
return dispatch(enableXHRBreakpoint(index, bp));
451451
}
@@ -469,7 +469,7 @@ export function setXHRBreakpoint(path: string, method: string) {
469469
export function removeXHRBreakpoint(index: number) {
470470
return ({ dispatch, getState, client }: ThunkArgs) => {
471471
const xhrBreakpoints = getXHRBreakpoints(getState());
472-
const breakpoint = xhrBreakpoints.get(index);
472+
const breakpoint = xhrBreakpoints[index];
473473
return dispatch({
474474
type: "REMOVE_XHR_BREAKPOINT",
475475
breakpoint,

src/components/SecondaryPanes/XHRBreakpoints.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class XHRBreakpoints extends Component<Props, State> {
8989

9090
const { editIndex, inputValue, inputMethod } = this.state;
9191
const { xhrBreakpoints } = this.props;
92-
const { path, method } = xhrBreakpoints.get(editIndex);
92+
const { path, method } = xhrBreakpoints[editIndex];
9393

9494
if (path !== inputValue || method != inputMethod) {
9595
this.props.updateXHRBreakpoint(editIndex, inputValue, inputMethod);
@@ -120,7 +120,7 @@ class XHRBreakpoints extends Component<Props, State> {
120120

121121
editExpression = index => {
122122
const { xhrBreakpoints } = this.props;
123-
const { path, method } = xhrBreakpoints.get(index);
123+
const { path, method } = xhrBreakpoints[index];
124124
this.setState({
125125
inputValue: path,
126126
inputMethod: method,
@@ -162,7 +162,7 @@ class XHRBreakpoints extends Component<Props, State> {
162162
enableXHRBreakpoint,
163163
disableXHRBreakpoint
164164
} = this.props;
165-
const breakpoint = xhrBreakpoints.get(index);
165+
const breakpoint = xhrBreakpoints[index];
166166
if (breakpoint.disabled) {
167167
enableXHRBreakpoint(index);
168168
} else {
@@ -218,7 +218,7 @@ class XHRBreakpoints extends Component<Props, State> {
218218
return (
219219
<ul className="pane expressions-list">
220220
{explicitXhrBreakpoints.map(this.renderBreakpoint)}
221-
{(showInput || explicitXhrBreakpoints.size === 0) &&
221+
{(showInput || explicitXhrBreakpoints.length === 0) &&
222222
this.renderXHRInput(this.handleNewSubmit)}
223223
</ul>
224224
);
@@ -231,7 +231,7 @@ class XHRBreakpoints extends Component<Props, State> {
231231
return (
232232
<div
233233
className={classnames("breakpoints-exceptions-options", {
234-
empty: explicitXhrBreakpoints.size === 0
234+
empty: explicitXhrBreakpoints.length === 0
235235
})}
236236
>
237237
<ExceptionOption

src/reducers/breakpoints.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* @module reducers/breakpoints
1010
*/
1111

12-
import * as I from "immutable";
13-
1412
import { isGeneratedId } from "devtools-source-map";
1513
import { isEqual } from "lodash";
1614

@@ -20,19 +18,19 @@ import type { XHRBreakpoint, Breakpoint, SourceLocation } from "../types";
2018
import type { Action, DonePromiseAction } from "../actions/types";
2119

2220
export type BreakpointsMap = { [string]: Breakpoint };
23-
export type XHRBreakpointsList = I.List<XHRBreakpoint>;
21+
export type XHRBreakpointsList = $ReadOnlyArray<XHRBreakpoint>;
2422

2523
export type BreakpointsState = {
2624
breakpoints: BreakpointsMap,
2725
xhrBreakpoints: XHRBreakpointsList
2826
};
2927

3028
export function initialBreakpointsState(
31-
xhrBreakpoints?: any[] = []
29+
xhrBreakpoints?: XHRBreakpointsList = []
3230
): BreakpointsState {
3331
return {
3432
breakpoints: {},
35-
xhrBreakpoints: I.List(xhrBreakpoints),
33+
xhrBreakpoints: xhrBreakpoints,
3634
breakpointsDisabled: false
3735
};
3836
}
@@ -118,44 +116,42 @@ function addXHRBreakpoint(state, action) {
118116
if (existingBreakpointIndex === -1) {
119117
return {
120118
...state,
121-
xhrBreakpoints: xhrBreakpoints.push(breakpoint)
119+
xhrBreakpoints: [...xhrBreakpoints, breakpoint]
122120
};
123-
} else if (xhrBreakpoints.get(existingBreakpointIndex) !== breakpoint) {
121+
} else if (xhrBreakpoints[existingBreakpointIndex] !== breakpoint) {
122+
const newXhrBreakpoints = [...xhrBreakpoints];
123+
newXhrBreakpoints[existingBreakpointIndex] = breakpoint;
124124
return {
125125
...state,
126-
xhrBreakpoints: xhrBreakpoints.set(existingBreakpointIndex, breakpoint)
126+
xhrBreakpoints: newXhrBreakpoints
127127
};
128128
}
129129

130130
return state;
131131
}
132132

133133
function removeXHRBreakpoint(state, action) {
134-
const {
135-
breakpoint: { path, method }
136-
} = action;
134+
const { breakpoint } = action;
137135
const { xhrBreakpoints } = state;
138136

139137
if (action.status === "start") {
140138
return state;
141139
}
142140

143-
const index = xhrBreakpoints.findIndex(
144-
bp => bp.path === path && bp.method === method
145-
);
146-
147141
return {
148142
...state,
149-
xhrBreakpoints: xhrBreakpoints.delete(index)
143+
xhrBreakpoints: xhrBreakpoints.filter(bp => !isEqual(bp, breakpoint))
150144
};
151145
}
152146

153147
function updateXHRBreakpoint(state, action) {
154148
const { breakpoint, index } = action;
155149
const { xhrBreakpoints } = state;
150+
const newXhrBreakpoints = [...xhrBreakpoints];
151+
newXhrBreakpoints[index] = breakpoint;
156152
return {
157153
...state,
158-
xhrBreakpoints: xhrBreakpoints.set(index, breakpoint)
154+
xhrBreakpoints: newXhrBreakpoints
159155
};
160156
}
161157

src/selectors/breakpoints.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
import { createSelector } from "reselect";
88

9-
import type { BreakpointsState } from "../reducers/breakpoints";
9+
import type {
10+
BreakpointsState,
11+
XHRBreakpointsList
12+
} from "../reducers/breakpoints";
1013

1114
type OuterState = { breakpoints: BreakpointsState };
1215

13-
export function getXHRBreakpoints(state: OuterState) {
16+
export function getXHRBreakpoints(state: OuterState): XHRBreakpointsList {
1417
return state.breakpoints.xhrBreakpoints;
1518
}
1619

src/utils/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,6 @@ function updatePrefs(state: any) {
116116
}
117117

118118
if (currentXHRBreakpoints !== previousXHRBreakpoints) {
119-
asyncStore.xhrBreakpoints = currentXHRBreakpoints.toJS();
119+
asyncStore.xhrBreakpoints = currentXHRBreakpoints;
120120
}
121121
}

0 commit comments

Comments
 (0)