Convert request catalog entity reg state to injectable

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2023-03-01 13:34:46 -05:00
1 parent a1592ce2a5
commit b0e2660dfa
6 files changed
+58 -28

No files matched your search

@@ -4,9 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { reaction } from "mobx";
import ipcMainInjectionToken from "../../common/ipc/ipc-main-injection-token";
import { catalogInitChannel } from "../../common/ipc/catalog";
import { disposer, toJS } from "../../common/utils";
import { toJS } from "../../common/utils";
import { getStartableStoppable } from "../../common/utils/get-startable-stoppable";
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
import broadcastCurrentCatalogEntityRegistryStateInjectable from "../../features/catalog/entities-sync/main/broadcast.injectable";
@@ -16,25 +14,15 @@ const catalogSyncToRendererInjectable = getInjectable({
instantiate: (di) => {
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
const ipcMain = di.inject(ipcMainInjectionToken);
const broadcastCurrentCatalogEntityRegistryState = di.inject(broadcastCurrentCatalogEntityRegistryStateInjectable);
return getStartableStoppable(
"catalog-sync",
() => {
const initChannelHandler = () => broadcastCurrentCatalogEntityRegistryState(toJS(catalogEntityRegistry.items));
ipcMain.on(catalogInitChannel, initChannelHandler);
return disposer(
() => ipcMain.off(catalogInitChannel, initChannelHandler),
reaction(() => toJS(catalogEntityRegistry.items), (items) => {
broadcastCurrentCatalogEntityRegistryState(items);
}, {
fireImmediately: true,
}),
);
},
() => reaction(() => toJS(catalogEntityRegistry.items), (items) => {
broadcastCurrentCatalogEntityRegistryState(items);
}, {
fireImmediately: true,
}),
);
},
});