@@ -80,6 +80,12 @@ function update(
8080 return newState ;
8181 }
8282
83+ case "SYNC_BREAKPOINT" : {
84+ const newState = syncBreakpoint ( state , action ) ;
85+ setPendingBreakpoints ( newState ) ;
86+ return newState ;
87+ }
88+
8389 case "ENABLE_BREAKPOINT" : {
8490 const newState = enableBreakpoint ( state , action ) ;
8591 setPendingBreakpoints ( newState ) ;
@@ -118,6 +124,57 @@ function update(
118124 return state ;
119125}
120126
127+ function _optimisticlyAddBreakpoint ( state , breakpoint ) {
128+ const id = makeLocationId ( breakpoint . location ) ;
129+ const updateOpts = {
130+ loading : true
131+ } ;
132+
133+ return state . setIn ( [ "breakpoints" , id ] , updateObj ( breakpoint , updateOpts ) ) ;
134+ }
135+
136+ function _commitBreakpoint ( state , breakpoint , overrides = { } ) {
137+ const location = overrides . location || breakpoint . location ;
138+ const id = makeLocationId ( location ) ;
139+ const updatedOpts = Object . assign ( { } , { loading : false } , overrides ) ;
140+
141+ return state . setIn ( [ "breakpoints" , id ] , updateObj ( breakpoint , updatedOpts ) ) ;
142+ }
143+
144+ function _correctBreakpoint ( state , breakpoint , actualLocation ) {
145+ const intermState = deleteBreakpoint ( state , breakpoint . location ) ;
146+ const location = actualLocation ;
147+ const newLocationId = makeLocationId ( actualLocation ) ;
148+ const overrides = { location, id : newLocationId } ;
149+
150+ return _commitBreakpoint ( intermState , breakpoint , overrides ) ;
151+ }
152+
153+ function syncBreakpoint ( state , action ) {
154+ if ( action . status === "start" ) {
155+ return _optimisticlyAddBreakpoint ( state , action . breakpoint ) ;
156+ }
157+
158+ if ( action . status === "done" ) {
159+ const { breakpoint, value : { actualLocation } } = action ;
160+ const sameLocation = ! locationMoved ( breakpoint . location , actualLocation ) ;
161+
162+ if ( sameLocation ) {
163+ return _commitBreakpoint ( state , breakpoint , action . value ) ;
164+ }
165+
166+ const updatedState = _correctBreakpoint ( state , breakpoint , actualLocation ) ;
167+ const id = makeLocationId ( actualLocation ) ;
168+ const correctBreakpoint = updatedState . breakpoints . get ( id ) ;
169+ return updatePendingBreakpoint ( updatedState , correctBreakpoint ) ;
170+ }
171+
172+ if ( action . status === "error" ) {
173+ // Remove the optimistic update and pending breakpoint
174+ return deleteBreakpoint ( state , action . breakpoint . location ) ;
175+ }
176+ }
177+
121178function addBreakpoint ( state , action ) {
122179 const id = makeLocationId ( action . breakpoint . location ) ;
123180 if ( action . status === "start" ) {
@@ -197,7 +254,10 @@ function disableBreakpoint(state, action) {
197254 return updatePendingBreakpoint ( updatedState , breakpoint ) ;
198255}
199256
200- function deleteBreakpoint ( state , id , pendingId ) {
257+ function deleteBreakpoint ( state , location ) {
258+ const id = makeLocationId ( location ) ;
259+ const pendingId = makePendingLocationId ( location ) ;
260+
201261 return state
202262 . deleteIn ( [ "breakpoints" , id ] )
203263 . deleteIn ( [ "pendingBreakpoints" , pendingId ] ) ;
@@ -208,10 +268,7 @@ function removeBreakpoint(state, action) {
208268 return state ;
209269 }
210270
211- const id = makeLocationId ( action . breakpoint . location ) ;
212- const pendingId = makePendingLocationId ( action . breakpoint . location ) ;
213-
214- const updatedState = deleteBreakpoint ( state , id , pendingId ) ;
271+ const updatedState = deleteBreakpoint ( state , action . breakpoint . location ) ;
215272
216273 return updatedState . set (
217274 "breakpointsDisabled" ,
0 commit comments