@@ -30,7 +30,7 @@ export interface OverlayState {
30
30
routerType : 'pages' | 'app'
31
31
isErrorOverlayOpen : boolean
32
32
}
33
- export type OverlayDispatch = React . Dispatch < BusEvent >
33
+ export type OverlayDispatch = React . Dispatch < DispatcherEvent >
34
34
35
35
export const ACTION_STATIC_INDICATOR = 'static-indicator'
36
36
export const ACTION_BUILD_OK = 'build-ok'
@@ -121,7 +121,7 @@ export interface RenderingIndicatorHideAction {
121
121
type : typeof ACTION_RENDERING_INDICATOR_HIDE
122
122
}
123
123
124
- export type BusEvent =
124
+ export type DispatcherEvent =
125
125
| BuildOkAction
126
126
| BuildErrorAction
127
127
| BeforeFastRefreshAction
@@ -235,107 +235,110 @@ export function useErrorOverlayReducer(
235
235
return pendingEvents
236
236
}
237
237
238
- return useReducer ( ( state : OverlayState , action : BusEvent ) : OverlayState => {
239
- switch ( action . type ) {
240
- case ACTION_DEBUG_INFO : {
241
- return { ...state , debugInfo : action . debugInfo }
242
- }
243
- case ACTION_STATIC_INDICATOR : {
244
- return { ...state , staticIndicator : action . staticIndicator }
245
- }
246
- case ACTION_BUILD_OK : {
247
- return { ...state , buildError : null }
248
- }
249
- case ACTION_BUILD_ERROR : {
250
- return { ...state , buildError : action . message }
251
- }
252
- case ACTION_BEFORE_REFRESH : {
253
- return { ...state , refreshState : { type : 'pending' , errors : [ ] } }
254
- }
255
- case ACTION_REFRESH : {
256
- return {
257
- ...state ,
258
- buildError : null ,
259
- errors :
260
- // Errors can come in during updates. In this case, UNHANDLED_ERROR
261
- // and UNHANDLED_REJECTION events might be dispatched between the
262
- // BEFORE_REFRESH and the REFRESH event. We want to keep those errors
263
- // around until the next refresh. Otherwise we run into a race
264
- // condition where those errors would be cleared on refresh completion
265
- // before they can be displayed.
266
- state . refreshState . type === 'pending'
267
- ? state . refreshState . errors
268
- : [ ] ,
269
- refreshState : { type : 'idle' } ,
238
+ return useReducer (
239
+ ( state : OverlayState , action : DispatcherEvent ) : OverlayState => {
240
+ switch ( action . type ) {
241
+ case ACTION_DEBUG_INFO : {
242
+ return { ...state , debugInfo : action . debugInfo }
270
243
}
271
- }
272
- case ACTION_UNHANDLED_ERROR :
273
- case ACTION_UNHANDLED_REJECTION : {
274
- switch ( state . refreshState . type ) {
275
- case 'idle' : {
276
- return {
277
- ...state ,
278
- nextId : state . nextId + 1 ,
279
- errors : pushErrorFilterDuplicates (
280
- state . errors ,
281
- state . nextId ,
282
- action . reason
283
- ) ,
284
- }
244
+ case ACTION_STATIC_INDICATOR : {
245
+ return { ...state , staticIndicator : action . staticIndicator }
246
+ }
247
+ case ACTION_BUILD_OK : {
248
+ return { ...state , buildError : null }
249
+ }
250
+ case ACTION_BUILD_ERROR : {
251
+ return { ...state , buildError : action . message }
252
+ }
253
+ case ACTION_BEFORE_REFRESH : {
254
+ return { ...state , refreshState : { type : 'pending' , errors : [ ] } }
255
+ }
256
+ case ACTION_REFRESH : {
257
+ return {
258
+ ...state ,
259
+ buildError : null ,
260
+ errors :
261
+ // Errors can come in during updates. In this case, UNHANDLED_ERROR
262
+ // and UNHANDLED_REJECTION events might be dispatched between the
263
+ // BEFORE_REFRESH and the REFRESH event. We want to keep those errors
264
+ // around until the next refresh. Otherwise we run into a race
265
+ // condition where those errors would be cleared on refresh completion
266
+ // before they can be displayed.
267
+ state . refreshState . type === 'pending'
268
+ ? state . refreshState . errors
269
+ : [ ] ,
270
+ refreshState : { type : 'idle' } ,
285
271
}
286
- case 'pending' : {
287
- return {
288
- ...state ,
289
- nextId : state . nextId + 1 ,
290
- refreshState : {
291
- ...state . refreshState ,
272
+ }
273
+ case ACTION_UNHANDLED_ERROR :
274
+ case ACTION_UNHANDLED_REJECTION : {
275
+ switch ( state . refreshState . type ) {
276
+ case 'idle' : {
277
+ return {
278
+ ...state ,
279
+ nextId : state . nextId + 1 ,
292
280
errors : pushErrorFilterDuplicates (
293
281
state . errors ,
294
282
state . nextId ,
295
283
action . reason
296
284
) ,
297
- } ,
285
+ }
286
+ }
287
+ case 'pending' : {
288
+ return {
289
+ ...state ,
290
+ nextId : state . nextId + 1 ,
291
+ refreshState : {
292
+ ...state . refreshState ,
293
+ errors : pushErrorFilterDuplicates (
294
+ state . errors ,
295
+ state . nextId ,
296
+ action . reason
297
+ ) ,
298
+ } ,
299
+ }
298
300
}
301
+ default :
302
+ return state
299
303
}
300
- default :
301
- return state
302
304
}
303
- }
304
- case ACTION_VERSION_INFO : {
305
- return { ...state , versionInfo : action . versionInfo }
306
- }
307
- case ACTION_DEV_INDICATOR : {
308
- return {
309
- ...state ,
310
- showIndicator : true ,
311
- disableDevIndicator :
312
- shouldDisableDevIndicator || ! ! action . devIndicator . disabledUntil ,
305
+ case ACTION_VERSION_INFO : {
306
+ return { ...state , versionInfo : action . versionInfo }
307
+ }
308
+ case ACTION_DEV_INDICATOR : {
309
+ return {
310
+ ...state ,
311
+ showIndicator : true ,
312
+ disableDevIndicator :
313
+ shouldDisableDevIndicator || ! ! action . devIndicator . disabledUntil ,
314
+ }
315
+ }
316
+ case ACTION_ERROR_OVERLAY_OPEN : {
317
+ return { ...state , isErrorOverlayOpen : true }
318
+ }
319
+ case ACTION_ERROR_OVERLAY_CLOSE : {
320
+ return { ...state , isErrorOverlayOpen : false }
321
+ }
322
+ case ACTION_ERROR_OVERLAY_TOGGLE : {
323
+ return { ...state , isErrorOverlayOpen : ! state . isErrorOverlayOpen }
324
+ }
325
+ case ACTION_BUILDING_INDICATOR_SHOW : {
326
+ return { ...state , buildingIndicator : true }
327
+ }
328
+ case ACTION_BUILDING_INDICATOR_HIDE : {
329
+ return { ...state , buildingIndicator : false }
330
+ }
331
+ case ACTION_RENDERING_INDICATOR_SHOW : {
332
+ return { ...state , renderingIndicator : true }
333
+ }
334
+ case ACTION_RENDERING_INDICATOR_HIDE : {
335
+ return { ...state , renderingIndicator : false }
336
+ }
337
+ default : {
338
+ return state
313
339
}
314
340
}
315
- case ACTION_ERROR_OVERLAY_OPEN : {
316
- return { ...state , isErrorOverlayOpen : true }
317
- }
318
- case ACTION_ERROR_OVERLAY_CLOSE : {
319
- return { ...state , isErrorOverlayOpen : false }
320
- }
321
- case ACTION_ERROR_OVERLAY_TOGGLE : {
322
- return { ...state , isErrorOverlayOpen : ! state . isErrorOverlayOpen }
323
- }
324
- case ACTION_BUILDING_INDICATOR_SHOW : {
325
- return { ...state , buildingIndicator : true }
326
- }
327
- case ACTION_BUILDING_INDICATOR_HIDE : {
328
- return { ...state , buildingIndicator : false }
329
- }
330
- case ACTION_RENDERING_INDICATOR_SHOW : {
331
- return { ...state , renderingIndicator : true }
332
- }
333
- case ACTION_RENDERING_INDICATOR_HIDE : {
334
- return { ...state , renderingIndicator : false }
335
- }
336
- default : {
337
- return state
338
- }
339
- }
340
- } , getInitialState ( routerType ) )
341
+ } ,
342
+ getInitialState ( routerType )
343
+ )
341
344
}
0 commit comments