mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Jim Ehrismann <jehrismann@mirantis.com>
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import { reaction } from "mobx";
|
|
import { broadcastMessage, ipcMainOn } from "../common/ipc";
|
|
import type { CatalogEntityRegistry } from "./catalog";
|
|
import "../common/catalog-entities/kubernetes-cluster";
|
|
import { disposer, toJS } from "../common/utils";
|
|
import { debounce } from "lodash";
|
|
import type { CatalogEntity } from "../common/catalog";
|
|
import { catalogInitChannel, catalogItemsChannel } from "../common/ipc/catalog";
|
|
|
|
const broadcaster = debounce((items: CatalogEntity[]) => {
|
|
broadcastMessage(catalogItemsChannel, items);
|
|
}, 1_000, { leading: true, trailing: true });
|
|
|
|
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
|
|
return disposer(
|
|
ipcMainOn(catalogInitChannel, () => broadcaster(toJS(catalog.items))),
|
|
reaction(() => toJS(catalog.items), (items) => {
|
|
broadcaster(items);
|
|
}, {
|
|
fireImmediately: true,
|
|
}),
|
|
);
|
|
}
|