1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/before-frame-starts/runnables/setup-current-cluster-broadcast.injectable.ts
Sebastian Malton c68a1bfd04 Convert all renderer runnables to late-inject style
- To help fix issues around injection time

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-12-06 09:19:00 -05:00

33 lines
1.3 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { reaction } from "mobx";
import { currentClusterMessageChannel } from "../../../common/cluster/current-cluster-channel";
import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
import matchedClusterIdInjectable from "../../navigation/matched-cluster-id.injectable";
import { evenBeforeMainFrameStartsInjectionToken } from "../tokens";
const setupCurrentClusterBroadcastInjectable = getInjectable({
id: "setup-current-cluster-broadcast",
instantiate: (di) => ({
id: "setup-current-cluster-broadcast",
run: () => {
const matchedClusterId = di.inject(matchedClusterIdInjectable);
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
reaction(
() => matchedClusterId.get(),
clusterId => sendMessageToChannel(currentClusterMessageChannel, clusterId),
{
fireImmediately: true,
},
);
},
}),
injectionToken: evenBeforeMainFrameStartsInjectionToken,
});
export default setupCurrentClusterBroadcastInjectable;