Skip to content

Commit

Permalink
Use await instead of promise chain
Browse files Browse the repository at this point in the history
  • Loading branch information
jkissel committed Oct 4, 2023
1 parent 2b81469 commit b6c5981
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
6 changes: 2 additions & 4 deletions sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@
});
},
fetchData ({ embeddingTargetId, mediaType }) {
cadenzaClient.fetchData(embeddingTargetId, mediaType)
.then(response => response.text())
.then(text => alert(text))
.catch(exception => alert(exception));
console.log('Inspect the fetchData() request in the devtools.');
cadenzaClient.fetchData(embeddingTargetId, mediaType);
},
downloadData ({ embeddingTargetId, mediaType, fileName }) {
cadenzaClient.downloadData(embeddingTargetId, mediaType, {
Expand Down
33 changes: 16 additions & 17 deletions src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class CadenzaClient {
* @return {Promise<void>} A Promise for when the iframe is loaded
* @throws For an invalid workbook view source or geometry type
*/
showMap(
async showMap(
mapView,
{
geometry,
Expand All @@ -235,9 +235,8 @@ export class CadenzaClient {
useMapSrs,
webApplication: this.#webApplication,
});
return this.#show(resolvePath(mapView), params, signal).then(() =>
this.#postEvent('setGeometry', { geometry }),
);
await this.#show(resolvePath(mapView), params, signal);
this.#postEvent('setGeometry', { geometry });
}

/**
Expand Down Expand Up @@ -295,7 +294,7 @@ export class CadenzaClient {
* @fires `editGeometry:ok` - When the user completed the geometry editing. The event includes the edited geometry.
* @fires `editGeometry:cancel` - When the user cancelled the geometry editing in Cadenza.
*/
editGeometry(
async editGeometry(
backgroundMapView,
geometry,
{ locationFinder, mapExtent, minScale, useMapSrs, signal } = {},
Expand All @@ -310,9 +309,8 @@ export class CadenzaClient {
useMapSrs,
webApplication: this.#webApplication,
});
return this.#show(resolvePath(backgroundMapView), params, signal).then(() =>
this.#postEvent('setGeometry', { geometry }),
);
await this.#show(resolvePath(backgroundMapView), params, signal);
this.#postEvent('setGeometry', { geometry });
}

#show(
Expand Down Expand Up @@ -357,16 +355,17 @@ export class CadenzaClient {
];
});

promise.then(
() => this.#log('Iframe loaded'),
(error) => this.#log('Iframe loading failed', error),
);
promise
.then(
() => this.#log('Iframe loaded'),
(error) => this.#log('Iframe loading failed', error),
)
.finally(() => {
iframe.removeEventListener('error', onerror);
signal?.removeEventListener('abort', onabort);
unsubscribes.forEach((unsubscribe) => unsubscribe());
});

promise.finally(() => {
iframe.removeEventListener('error', onerror);
signal?.removeEventListener('abort', onabort);
unsubscribes.forEach((unsubscribe) => unsubscribe());
});
return promise;
}

Expand Down

0 comments on commit b6c5981

Please sign in to comment.