feat: allow promise in EntityPresentationApi for all the asynchronous processes working under the hood

Signed-off-by: NIKUNJ LALITKUMAR HUDKA <nikunjhudka123@gmail.com>
This commit is contained in:
NIKUNJ LALITKUMAR HUDKA
2024-04-20 12:03:21 -03:00
parent 1992df3934
commit ff03fd55de
2 changed files with 33 additions and 1 deletions
@@ -109,6 +109,11 @@ export interface EntityRefPresentation {
* elsewhere.
*/
update$?: Observable<EntityRefPresentationSnapshot>;
/* The `promise` property in the `EntityRefPresentation` interface is defining a property named
`promise` that holds a promise. This promise resolves to an array of
`EntityRefPresentationSnapshot` objects. */
promise: Promise<EntityRefPresentationSnapshot[]>;
}
/**
@@ -298,10 +298,37 @@ export class DefaultEntityPresentationApi implements EntityPresentationApi {
};
});
return {
const entityRefPresentation: EntityRefPresentation = {
snapshot: initialSnapshot,
update$: observable,
get promise() {
return new Promise<EntityRefPresentationSnapshot[]>(
(resolve, reject) => {
if (!observable) {
resolve([initialSnapshot]);
} else {
const res: EntityRefPresentationSnapshot[] = [];
const subscription = observable.subscribe({
next: snapshot => {
res.push(snapshot);
},
error: error => {
initialSnapshot = {
primaryTitle: entityRef,
entityRef: entityRef,
};
},
complete() {
subscription.unsubscribe();
resolve(res);
},
});
}
},
);
},
};
return entityRefPresentation;
}
#getEntityForInitialRender(entityOrRef: Entity | string): {