mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Return Promise for Osmose string requests
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user