99 * @module reducers/breakpoints
1010 */
1111
12- import * as I from "immutable" ;
13-
1412import { isGeneratedId } from "devtools-source-map" ;
1513import { isEqual } from "lodash" ;
1614
@@ -20,19 +18,19 @@ import type { XHRBreakpoint, Breakpoint, SourceLocation } from "../types";
2018import type { Action , DonePromiseAction } from "../actions/types" ;
2119
2220export type BreakpointsMap = { [ string ] : Breakpoint } ;
23- export type XHRBreakpointsList = I . List < XHRBreakpoint > ;
21+ export type XHRBreakpointsList = $ReadOnlyArray < XHRBreakpoint > ;
2422
2523export type BreakpointsState = {
2624 breakpoints : BreakpointsMap ,
2725 xhrBreakpoints : XHRBreakpointsList
2826} ;
2927
3028export 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
133133function 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
153147function 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
0 commit comments