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:
@@ -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): {
|
||||
|
||||
Reference in New Issue
Block a user