(
originalEvent: Event,
newState: string,
)
| 130 | } |
| 131 | |
| 132 | const dispatchChangesIfNeeded = ( |
| 133 | originalEvent: Event, |
| 134 | newState: string, |
| 135 | ): void => { |
| 136 | if (newState === PASSIVE && wasActive) { |
| 137 | // eslint-disable-next-line no-param-reassign |
| 138 | newState = ACTIVE; |
| 139 | } |
| 140 | if (newState !== state) { |
| 141 | const oldState = state; |
| 142 | const path = getLegalStateTransitionPath(oldState, newState); |
| 143 | |
| 144 | for (let i = 0; i < path.length - 1; i += 1) { |
| 145 | const oldPathState = path[i]; |
| 146 | const newPathState = path[i + 1]; |
| 147 | |
| 148 | state = newState; |
| 149 | if (state === ACTIVE) { |
| 150 | wasActive = true; |
| 151 | } |
| 152 | |
| 153 | window.dispatchEvent( |
| 154 | new CustomEvent('statechange', { |
| 155 | bubbles: true, |
| 156 | detail: { |
| 157 | oldState: oldPathState, |
| 158 | newState: newPathState, |
| 159 | originalEvent, |
| 160 | }, |
| 161 | }), |
| 162 | ); |
| 163 | } |
| 164 | } |
| 165 | }; |
| 166 | |
| 167 | const handleEvents = (evt: Event): void => { |
| 168 | if (IS_SAFARI) { |
no test coverage detected