From 8bb2dc7fa6540a0b28ead9f91b998f0bb9e2f0fa Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Fri, 7 Feb 2020 11:21:33 +0000 Subject: [PATCH] Return Promise for Osmose string requests --- modules/services/osmose.js | 9 +++------ modules/svg/osmose.js | 17 ++++++++--------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/modules/services/osmose.js b/modules/services/osmose.js index d593f8eac..2c97852ed 100644 --- a/modules/services/osmose.js +++ b/modules/services/osmose.js @@ -174,15 +174,14 @@ export default { return jsonPromise(url, cacheDetails).then(() => issue); }, - loadStrings(callback, locale=currentLocale) { + loadStrings(locale=currentLocale) { const items = Object.keys(qaServices.osmose.icons); if ( locale in _cache.strings && Object.keys(_cache.strings[locale]).length === items.length ) { - if (callback) callback(null, _cache.strings[locale]); - return; + return Promise.resolve(_cache.strings[locale]); } // May be partially populated already if some requests were successful @@ -243,9 +242,7 @@ export default { return jsonPromise(url, cacheData); }); - Promise.all(allRequests) - .then(() => { if (callback) callback(null, _cache.strings[locale]); }) - .catch(err => { if (callback) callback(err); }); + return Promise.all(allRequests).then(() => _cache.strings[locale]); }, getStrings(itemType, locale=currentLocale) { diff --git a/modules/svg/osmose.js b/modules/svg/osmose.js index e3e7d6617..1dc482424 100644 --- a/modules/svg/osmose.js +++ b/modules/svg/osmose.js @@ -59,20 +59,14 @@ export function svgOsmose(projection, context, dispatch) { // Enable the layer. This shows the markers and transitions them to visible. function layerOn() { - // Strings supplied by Osmose fetched before showing layer for first time - // NOTE: Currently no way to change locale in iD at runtime, would need to re-call this method if that's ever implemented - // FIXME: If layer is toggled quickly multiple requests are sent - // FIXME: No error handling in place - getService().loadStrings(editOn); + editOn(); drawLayer .style('opacity', 0) .transition() .duration(250) .style('opacity', 1) - .on('end interrupt', () => { - dispatch.call('change'); - }); + .on('end interrupt', () => dispatch.call('change')); } // Disable the layer. This transitions the layer invisible and then hides the markers. @@ -223,7 +217,12 @@ export function svgOsmose(projection, context, dispatch) { _layerEnabled = val; if (_layerEnabled) { - layerOn(); + // Strings supplied by Osmose fetched before showing layer for first time + // NOTE: Currently no way to change locale in iD at runtime, would need to re-call this method if that's ever implemented + // FIXME: If layer is toggled quickly multiple requests are sent + getService().loadStrings() + .then(layerOn) + .catch(err => {}); // FIXME: Handle failed json request gracefully in some way } else { layerOff(); if (context.selectedErrorID()) {