()
| 147 | } |
| 148 | |
| 149 | function performAppChanges() { |
| 150 | return Promise.resolve().then(() => { |
| 151 | // https://github.com/single-spa/single-spa/issues/545 |
| 152 | fireSingleSpaEvent( |
| 153 | appsThatChanged.length === 0 |
| 154 | ? "before-no-app-change" |
| 155 | : "before-app-change", |
| 156 | getCustomEventDetail(true) |
| 157 | ); |
| 158 | |
| 159 | fireSingleSpaEvent( |
| 160 | "before-routing-event", |
| 161 | getCustomEventDetail(true, { cancelNavigation }) |
| 162 | ); |
| 163 | |
| 164 | return Promise.all(cancelPromises).then((cancelValues) => { |
| 165 | const navigationIsCanceled = cancelValues.some((v) => v); |
| 166 | |
| 167 | if (navigationIsCanceled) { |
| 168 | // Change url back to old url, without triggering the normal single-spa reroute |
| 169 | originalReplaceState.call( |
| 170 | window.history, |
| 171 | history.state, |
| 172 | "", |
| 173 | oldUrl.substring(location.origin.length) |
| 174 | ); |
| 175 | |
| 176 | // Single-spa's internal tracking of current url needs to be updated after the url change above |
| 177 | currentUrl = location.href; |
| 178 | |
| 179 | // necessary for the reroute function to know that the current reroute is finished |
| 180 | appChangeUnderway = false; |
| 181 | |
| 182 | if (__PROFILE__) { |
| 183 | addProfileEntry( |
| 184 | "routing", |
| 185 | "navigationCanceled", |
| 186 | profilerKind, |
| 187 | startTime, |
| 188 | performance.now(), |
| 189 | true |
| 190 | ); |
| 191 | } |
| 192 | |
| 193 | // Tell single-spa to reroute again, this time with the url set to the old URL |
| 194 | return reroute(pendingPromises, eventArguments, true); |
| 195 | } |
| 196 | |
| 197 | const unloadPromises = appsToUnload.map(toUnloadPromise); |
| 198 | |
| 199 | const unmountUnloadPromises = appsToUnmount |
| 200 | .map(toUnmountPromise) |
| 201 | .map((unmountPromise) => unmountPromise.then(toUnloadPromise)); |
| 202 | |
| 203 | const allUnmountPromises = unmountUnloadPromises.concat(unloadPromises); |
| 204 | |
| 205 | const unmountAllPromise = Promise.all(allUnmountPromises); |
| 206 |
no test coverage detected
searching dependent graphs…