1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

observable.set > observable.map

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen 2021-10-05 16:48:34 +03:00
parent 74eb89c361
commit c8631346ca
No known key found for this signature in database
GPG Key ID: 54B44603D251B788

View File

@ -39,10 +39,7 @@ export class CatalogEntityRegistry {
protected filters = observable.set<EntityFilter>([], {
deep: false,
});
protected entityOnBeforeRun = observable.set<{
catalogEntityUid: CatalogEntityUid;
onBeforeRun: CatalogEntityOnBeforeRun
}>([], {
protected entityOnBeforeRun = observable.map<CatalogEntityUid, CatalogEntityOnBeforeRun>({}, {
deep: false,
});
@ -186,22 +183,16 @@ export class CatalogEntityRegistry {
* @returns A function to remove that hook
*/
addOnBeforeRun(catalogEntityUid: CatalogEntityUid, onBeforeRun: CatalogEntityOnBeforeRun): Disposer {
this.entityOnBeforeRun.add({
catalogEntityUid,
onBeforeRun,
});
this.entityOnBeforeRun.set(catalogEntityUid, onBeforeRun);
return once(() => void this.entityOnBeforeRun.delete({
catalogEntityUid,
onBeforeRun,
}));
return once(() => void this.entityOnBeforeRun.delete(catalogEntityUid));
}
/**
* Returns one catalog entity onBeforeRun by catalog entity uid
*/
getOnBeforeRun(_catalogEntityUid: CatalogEntityUid): CatalogEntityOnBeforeRun | undefined {
return Array.from(this.entityOnBeforeRun).find(({ catalogEntityUid }) => catalogEntityUid === _catalogEntityUid)?.onBeforeRun;
getOnBeforeRun(catalogEntityUid: CatalogEntityUid): CatalogEntityOnBeforeRun | undefined {
return this.entityOnBeforeRun.get(catalogEntityUid);
}
}