@@ -190,6 +190,10 @@ export const appearStartedState = stateFunc(StateID.AppearStarted, "appear");
190
190
export const enterStartedState = stateFunc ( StateID . EnterStarted , "enter" ) ;
191
191
export const leaveStartedState = stateFunc ( StateID . LeaveStarted , "leave" ) ;
192
192
193
+ const invalidTransitionError = ( stateID : StateID , actionID : ActionID ) => {
194
+ return new Error ( `invalid state transition from ${ StateID [ stateID ] } with ${ ActionID [ actionID ] } ` ) ;
195
+ } ;
196
+
193
197
export type Reducer = ( stateID : StateID , action : Action ) =>
194
198
{ state : TransitionState , pending ?: ActionID , completed ?: boolean } ;
195
199
@@ -236,7 +240,7 @@ export const reducer: Reducer = (stateID, action) => {
236
240
nextState = appearInitState ( props ) ;
237
241
break ;
238
242
default :
239
- throw new Error ( `invalid state transition from ${ StateID [ stateID ] } ` ) ;
243
+ throw invalidTransitionError ( stateID , action . kind ) ;
240
244
} ;
241
245
return { state : nextState , pending : ActionID . TransitionPrepare } ;
242
246
case ActionID . TransitionPrepare :
@@ -254,7 +258,7 @@ export const reducer: Reducer = (stateID, action) => {
254
258
nextState = appearPrepareState ( props ) ;
255
259
break ;
256
260
default :
257
- throw new Error ( `invalid state transition from ${ StateID [ stateID ] } ` ) ;
261
+ throw invalidTransitionError ( stateID , action . kind ) ;
258
262
} ;
259
263
return { state : nextState , pending : ActionID . TransitionTrigger } ;
260
264
case ActionID . TransitionStart :
@@ -281,7 +285,7 @@ export const reducer: Reducer = (stateID, action) => {
281
285
case StateID . LeaveStarted :
282
286
return { state : defaultState ( props ) , completed : true } ;
283
287
default :
284
- throw new Error ( `invalid state transition from ${ StateID [ stateID ] } ` ) ;
288
+ throw invalidTransitionError ( stateID , action . kind ) ;
285
289
}
286
290
case ActionID . TransitionTrigger :
287
291
switch ( stateID ) {
@@ -318,7 +322,7 @@ export const reducer: Reducer = (stateID, action) => {
318
322
case StateID . LeaveStarted :
319
323
return { state : enterStartedState ( props ) } ;
320
324
default :
321
- throw new Error ( `invalid state transition from ${ StateID [ stateID as any ] } ` ) ;
325
+ throw invalidTransitionError ( stateID , action . kind ) ;
322
326
}
323
327
case ActionID . Timeout :
324
328
switch ( stateID ) {
@@ -331,7 +335,7 @@ export const reducer: Reducer = (stateID, action) => {
331
335
case StateID . LeaveStarted :
332
336
return { state : defaultState ( props ) , completed : true } ;
333
337
default :
334
- throw new Error ( `invalid state transition from ${ StateID [ stateID ] } ` ) ;
338
+ throw invalidTransitionError ( stateID , action . kind ) ;
335
339
}
336
340
default :
337
341
}
0 commit comments