[openstreetmap/openstreetmap-website] Make loadSidebarContent use promises (PR #7226)
Pablo Brasero
notifications at github.com
Wed Jul 15 15:19:00 UTC 2026
@pablobm commented on this pull request.
Sorry, late to the party! 😳
> .then(() => {
- OSM.loadSidebarContent(location.pathname, page.load);
+ OSM.loadSidebarContent(location.pathname)
+ .then(page.load);
})
How about this?
```js
.then(() => OSM.loadSidebarContent(location.pathname)
.then(page.load);
```
> @@ -252,7 +252,7 @@ export default function (map) {
if (sidebarReadyPromise) return sidebarReadyPromise;
- sidebarReadyPromise = new Promise(resolve => OSM.loadSidebarContent("/directions", resolve));
+ sidebarReadyPromise = OSM.loadSidebarContent("/directions");
How about returning just here? Or at the risk of making it too clever we can remove the previous `if` and do this:
```js
return sidebarReadyPromise || OSM.loadSidebarContent("/directions");
```
> @@ -42,9 +42,8 @@ export default function (map) {
});
})
.then(() => {
- OSM.loadSidebarContent(path, () => {
- initialize(path, id, false);
- });
+ OSM.loadSidebarContent(path)
+ .then(() => initialize(path, id, false));
How about moving the `then` out, like above?
>
map.setSidebarOverlaid(false);
$("#sidebar_loader").prop("hidden", false).addClass("delayed-fade-in");
// Prevent caching the XHR response as a full-page URL
// https://github.com/openstreetmap/openstreetmap-website/issues/5663
- if (content_path.indexOf("?") >= 0) {
- content_path += "&xhr=1";
- } else {
- content_path += "?xhr=1";
- }
+ const xhrPath = path + `${path.includes("?") ? "&" : "?"}xhr=1`;
A bit cryptic. How about this?
```js
const queryParamSeparator = path.includes("?") ? "&" : "?";
const xhrPath = `${path}${queryParamSeparator}xhr=1`;
```
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/7226#pullrequestreview-4705473208
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/7226/review/4705473208 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260715/2405a4cc/attachment-0001.htm>
More information about the rails-dev
mailing list