Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 90x 90x 90x 90x 90x 65x 48x 48x 48x 48x 48x 1x 1x 47x 47x 47x 47x 53x 53x 53x 53x 53x 53x 47x 47x 47x 47x 47x 47x 47x 65x 17x 17x 17x 17x 65x 90x 1x | import { reaction } from "mobx";
import { getMessageChannelListenerInjectable } from "@k8slens/messaging";
import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
import { computedChannelObserverInjectionToken } from "./computed-channel.injectable";
import { getMessageChannel } from "@k8slens/messaging";
export type ComputedChannelAdminMessage = {
channelId: string;
status: "became-observed" | "became-unobserved";
};
export const computedChannelAdministrationChannel = getMessageChannel<ComputedChannelAdminMessage>(
"computed-channel-administration-channel",
);
export const computedChannelAdministrationListenerInjectable = getMessageChannelListenerInjectable({
id: "computed-channel-administration",
channel: computedChannelAdministrationChannel,
getHandler: (di) => {
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
const disposersByChannelId = new Map<string, () => void>();
return (message) => {
if (message.status === "became-observed") {
const result = di
.injectMany(computedChannelObserverInjectionToken)
.find((channelObserver) => channelObserver.channel.id === message.channelId);
if (result === undefined) {
return;
}
const disposer = reaction(
() => result.observer.get(),
(observed) =>
sendMessageToChannel(
{
id: message.channelId,
},
observed,
),
{
fireImmediately: true,
},
);
disposersByChannelId.set(message.channelId, disposer);
} else {
const disposer = disposersByChannelId.get(message.channelId);
disposer?.();
}
};
},
});
|