MCPcopy
hub / github.com/single-spa/single-spa / finishUpAndReturn

Function finishUpAndReturn

src/navigation/reroute.js:313–349  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

311 }
312
313 function finishUpAndReturn() {
314 const returnValue = getMountedApps();
315 pendingPromises.forEach((promise) => promise.resolve(returnValue));
316
317 try {
318 const appChangeEventName =
319 appsThatChanged.length === 0 ? "no-app-change" : "app-change";
320 fireSingleSpaEvent(appChangeEventName, getCustomEventDetail());
321 fireSingleSpaEvent("routing-event", getCustomEventDetail());
322 } catch (err) {
323 /* We use a setTimeout because if someone else's event handler throws an error, single-spa
324 * needs to carry on. If a listener to the event throws an error, it's their own fault, not
325 * single-spa's.
326 */
327 setTimeout(() => {
328 throw err;
329 });
330 }
331
332 /* Setting this allows for subsequent calls to reroute() to actually perform
333 * a reroute instead of just getting queued behind the current reroute call.
334 * We want to do this after the mounting/unmounting is done but before we
335 * resolve the promise for the `reroute` function.
336 */
337 appChangeUnderway = false;
338
339 if (peopleWaitingOnAppChange.length > 0) {
340 /* While we were rerouting, someone else triggered another reroute that got queued.
341 * So we need reroute again.
342 */
343 const nextPendingPromises = peopleWaitingOnAppChange;
344 peopleWaitingOnAppChange = [];
345 reroute(nextPendingPromises);
346 }
347
348 return returnValue;
349 }
350
351 /* We need to call all event listeners that have been delayed because they were
352 * waiting on single-spa. This includes haschange and popstate events for both

Callers

nothing calls this directly

Calls 4

getMountedAppsFunction · 0.90
fireSingleSpaEventFunction · 0.85
getCustomEventDetailFunction · 0.85
rerouteFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…