Fix main->renderer catalog entity sync issue (#2902)

* fix main->renderer catalog entity sync issue

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* refactor

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2021-05-31 08:09:16 +03:00
1 parent 2e0ff6c928
commit c8e2f7ca2d
3 files changed
+143 -13

No files matched your search

+8 -1
View File
@@ -24,10 +24,17 @@ import { broadcastMessage } from "../common/ipc";
import type { CatalogEntityRegistry } from "./catalog";
import "../common/catalog-entities/kubernetes-cluster";
import { toJS } from "../common/utils";
import { debounce } from "lodash";
import type { CatalogEntity } from "../common/catalog";
const broadcaster = debounce((items: CatalogEntity[]) => {
broadcastMessage("catalog:items", items);
}, 1_000, { trailing: true });
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
return reaction(() => toJS(catalog.items), (items) => {
broadcastMessage("catalog:items", items);
broadcaster(items);
}, {
fireImmediately: true,
});