MCPcopy Create free account
hub / github.com/ember-learn/ember-api-docs / setupHashSupport

Function setupHashSupport

app/utils/url-hash-polyfill.js:72–122  ·  view source on GitHub ↗
(router)

Source from the content-addressed store, hash-verified

70}
71
72async function setupHashSupport(router) {
73 let initialURL;
74 let owner = getOwner(router);
75
76 if (owner.lookup('service:prerender').isPrerendering) {
77 return;
78 }
79
80 await new Promise((resolve) => {
81 let interval = setInterval(() => {
82 let { currentURL, currentRouteName } = router; /* Private API */
83
84 if (currentURL && !isLoadingRoute(currentRouteName)) {
85 clearInterval(interval);
86 initialURL = currentURL;
87 resolve(null);
88 }
89 }, 100);
90 });
91
92 if (isDestroyed(owner) || isDestroying(owner)) {
93 return;
94 }
95
96 /**
97 * This handles the initial Page Load, which is not imperceptible through
98 * route{Did,Will}Change
99 *
100 */
101 requestAnimationFrame(() => {
102 eventuallyTryScrollingTo(owner, initialURL);
103 });
104
105 let routerService = owner.lookup('service:router');
106
107 function handleHashIntent(transition) {
108 let { url } = transition.intent || {};
109
110 if (!url) {
111 return;
112 }
113
114 eventuallyTryScrollingTo(owner, url);
115 }
116
117 routerService.on('routeDidChange', handleHashIntent);
118
119 registerDestructor(router, () => {
120 routerService.off('routeDidChange', handleHashIntent);
121 });
122}
123
124const CACHE = new WeakMap();
125

Callers 1

constructorMethod · 0.85

Calls 2

isLoadingRouteFunction · 0.85
eventuallyTryScrollingToFunction · 0.85

Tested by

no test coverage detected