1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Move message channels to changed signature too

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-10-12 09:19:24 -04:00
parent bcf1c1dbbe
commit 11a302fc75
9 changed files with 36 additions and 58 deletions

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { Injectable } from "@ogre-tools/injectable"; import type { DiContainerForInjection } from "@ogre-tools/injectable";
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable"; import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
export interface MessageChannel<Message> { export interface MessageChannel<Message> {
@ -29,8 +29,10 @@ export interface GetMessageChannelListenerInfo<
Channel extends MessageChannel<Message>, Channel extends MessageChannel<Message>,
Message, Message,
> { > {
id: string;
channel: Channel; channel: Channel;
handlerInjectable: Injectable<MessageChannelHandler<Channel>, unknown, void>; handler: (di: DiContainerForInjection) => MessageChannelHandler<Channel>;
causesSideEffects?: boolean;
} }
export function getMessageChannelListenerInjectable< export function getMessageChannelListenerInjectable<
@ -38,11 +40,12 @@ export function getMessageChannelListenerInjectable<
Message, Message,
>(info: GetMessageChannelListenerInfo<Channel, Message>) { >(info: GetMessageChannelListenerInfo<Channel, Message>) {
return getInjectable({ return getInjectable({
id: `${info.channel.id}-listener`, id: `${info.channel.id}-listener-${info.id}`,
instantiate: (di) => ({ instantiate: (di) => ({
channel: info.channel, channel: info.channel,
handler: di.inject(info.handlerInjectable), handler: info.handler(di),
}), }),
injectionToken: messageChannelListenerInjectionToken, injectionToken: messageChannelListenerInjectionToken,
causesSideEffects: info.causesSideEffects,
}); });
} }

View File

@ -4,11 +4,12 @@
*/ */
import { syncBoxChannel } from "./channels"; import { syncBoxChannel } from "./channels";
import { getMessageChannelListenerInjectable } from "../channel/message-channel-listener-injection-token"; import { getMessageChannelListenerInjectable } from "../channel/message-channel-listener-injection-token";
import syncBoxChannelHandlerInjectable from "./handler.injectable"; import syncBoxStateInjectable from "./sync-box-state.injectable";
const syncBoxChannelListenerInjectable = getMessageChannelListenerInjectable({ const syncBoxChannelListenerInjectable = getMessageChannelListenerInjectable({
id: "init",
channel: syncBoxChannel, channel: syncBoxChannel,
handlerInjectable: syncBoxChannelHandlerInjectable, handler: (di) => ({ id, value }) => di.inject(syncBoxStateInjectable, id).set(value),
}); });
export default syncBoxChannelListenerInjectable; export default syncBoxChannelListenerInjectable;

View File

@ -1,9 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override";
import reloadPageHandlerInjectable from "./handler.injectable";
export default getGlobalOverride(reloadPageHandlerInjectable, () => () => {});

View File

@ -1,18 +0,0 @@
/**
* 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 type { MessageChannelHandler } from "../../../../common/utils/channel/message-channel-listener-injection-token";
import type { ReloadPageChannel } from "../common/channel";
const reloadPageHandlerInjectable = getInjectable({
id: "reload-page-handler",
instantiate: (): MessageChannelHandler<ReloadPageChannel> => {
return () => location.reload();
},
causesSideEffects: true,
});
export default reloadPageHandlerInjectable;

View File

@ -0,0 +1,13 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override";
import { reloadPageChannel } from "../common/channel";
import reloadPageChannelListenerInjectable from "./register-listener.injectable";
export default getGlobalOverride(reloadPageChannelListenerInjectable, () => ({
channel: reloadPageChannel,
handler: () => {},
}));

View File

@ -4,11 +4,12 @@
*/ */
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
import { reloadPageChannel } from "../common/channel"; import { reloadPageChannel } from "../common/channel";
import reloadPageHandlerInjectable from "./handler.injectable";
const reloadPageChannelListenerInjectable = getMessageChannelListenerInjectable({ const reloadPageChannelListenerInjectable = getMessageChannelListenerInjectable({
id: "handler",
channel: reloadPageChannel, channel: reloadPageChannel,
handlerInjectable: reloadPageHandlerInjectable, handler: () => () => location.reload(),
causesSideEffects: true,
}); });
export default reloadPageChannelListenerInjectable; export default reloadPageChannelListenerInjectable;

View File

@ -7,8 +7,9 @@ import { getMessageChannelListenerInjectable } from "../../../common/utils/chann
import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable"; import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable";
const restartAndInstallUpdateListenerInjectable = getMessageChannelListenerInjectable({ const restartAndInstallUpdateListenerInjectable = getMessageChannelListenerInjectable({
id: "restart",
channel: restartAndInstallUpdateChannel, channel: restartAndInstallUpdateChannel,
handlerInjectable: quitAndInstallUpdateInjectable, handler: (di) => di.inject(quitAndInstallUpdateInjectable),
}); });
export default restartAndInstallUpdateListenerInjectable; export default restartAndInstallUpdateListenerInjectable;

View File

@ -4,11 +4,17 @@
*/ */
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
import { rootFrameHasRenderedChannel } from "../../../../common/root-frame/root-frame-rendered-channel"; import { rootFrameHasRenderedChannel } from "../../../../common/root-frame/root-frame-rendered-channel";
import rootFrameHasRenderedHandlerInjectable from "./handler.injectable"; import { runManyFor } from "../../../../common/runnable/run-many-for";
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/after-root-frame-is-ready-injection-token";
const rootFrameRenderedChannelListenerInjectable = getMessageChannelListenerInjectable({ const rootFrameRenderedChannelListenerInjectable = getMessageChannelListenerInjectable({
id: "action",
channel: rootFrameHasRenderedChannel, channel: rootFrameHasRenderedChannel,
handlerInjectable: rootFrameHasRenderedHandlerInjectable, handler: (di) => {
const runMany = runManyFor(di);
return runMany(afterRootFrameIsReadyInjectionToken);
},
}); });
export default rootFrameRenderedChannelListenerInjectable; export default rootFrameRenderedChannelListenerInjectable;

View File

@ -1,20 +0,0 @@
/**
* 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 type { RootFrameHasRenderedChannel } from "../../../../common/root-frame/root-frame-rendered-channel";
import { runManyFor } from "../../../../common/runnable/run-many-for";
import type { MessageChannelHandler } from "../../../../common/utils/channel/message-channel-listener-injection-token";
import { afterRootFrameIsReadyInjectionToken } from "../../runnable-tokens/after-root-frame-is-ready-injection-token";
const rootFrameHasRenderedHandlerInjectable = getInjectable({
id: "root-frame-has-rendered-handler",
instantiate: (di): MessageChannelHandler<RootFrameHasRenderedChannel> => {
const runMany = runManyFor(di);
return runMany(afterRootFrameIsReadyInjectionToken);
},
});
export default rootFrameHasRenderedHandlerInjectable;