( oldState: string, newState: string, )
| 52 | * @return {!Array<string>} |
| 53 | */ |
| 54 | const getLegalStateTransitionPath = ( |
| 55 | oldState: string, |
| 56 | newState: string, |
| 57 | ): string[] => { |
| 58 | // We're intentionally not using for...of here so when we transpile to ES5 |
| 59 | // we don't need to include the Symbol polyfills. |
| 60 | for ( |
| 61 | let order: Record<string, number>, i = 0; |
| 62 | i < LEGAL_STATE_TRANSITIONS.length; |
| 63 | i += 1 |
| 64 | ) { |
| 65 | order = LEGAL_STATE_TRANSITIONS[i]; |
| 66 | const oldIndex = order[oldState]; |
| 67 | const newIndex = order[newState]; |
| 68 | |
| 69 | if (oldIndex >= 0 && newIndex >= 0 && newIndex > oldIndex) { |
| 70 | // Differences greater than one should be reported |
| 71 | // because it means a state was skipped. |
| 72 | return Object.keys(order).slice(oldIndex, newIndex + 1); |
| 73 | } |
| 74 | } |
| 75 | return []; |
| 76 | // TODO(philipwalton): it shouldn't be possible to get here, but |
| 77 | // consider some kind of warning or call to action if it happens. |
| 78 | // console.warn(`Invalid state change detected: ${oldState} > ${newState}`); |
| 79 | }; |
| 80 | |
| 81 | let wasActive = false; |
| 82 |
no outgoing calls
no test coverage detected