Refactored won.getEvent to use async-await syntax.
@@ -1509,8 +1509,9 @@ import won from './won.js';
};
//aliases (formerly functions that were just pass-throughs)
- won.getEvent = (uri, fetchParams) => won.getNode(uri, fetchParams)
- .then(event => {
+ won.getEvent = async (eventUri, fetchParams) => {
+ const event = await won.getNode(eventUri, fetchParams);
+
// framing will find multiple timestamps (one from each node and owner) -> only use latest for the client
if(is('Array', event.hasReceivedTimestamp)) {
const latestFirst = event.hasReceivedTimestamp.sort((x,y) => new Date(y) - new Date(x));
@@ -1533,18 +1534,15 @@ import won from './won.js';
* we fetch it here.
*/
fetchParams.doNotFetch = true;
- return won
- .getNode(event.hasCorrespondingRemoteMessage, fetchParams)
- .then(correspondingEvent => {
+ const correspondingEvent = await won.getNode(event.hasCorrespondingRemoteMessage, fetchParams);
if (correspondingEvent.type) {
//if we have at least a type attribute, we add the remote event to the
//local event. if not, it is just an URI.
event.hasCorrespondingRemoteMessage = correspondingEvent;
}
return event;
- })
}
- });
+ }
/**
* Fetches the triples where URI is subject and add objects of those triples to the
