mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Convert request catalog entity reg state to injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
a1592ce2a5
commit
b0e2660dfa
6 files changed
+58
-28
No files matched your search
+6
-18
@@ -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,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user