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:
parent
bcf1c1dbbe
commit
11a302fc75
@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* 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";
|
||||
|
||||
export interface MessageChannel<Message> {
|
||||
@ -29,8 +29,10 @@ export interface GetMessageChannelListenerInfo<
|
||||
Channel extends MessageChannel<Message>,
|
||||
Message,
|
||||
> {
|
||||
id: string;
|
||||
channel: Channel;
|
||||
handlerInjectable: Injectable<MessageChannelHandler<Channel>, unknown, void>;
|
||||
handler: (di: DiContainerForInjection) => MessageChannelHandler<Channel>;
|
||||
causesSideEffects?: boolean;
|
||||
}
|
||||
|
||||
export function getMessageChannelListenerInjectable<
|
||||
@ -38,11 +40,12 @@ export function getMessageChannelListenerInjectable<
|
||||
Message,
|
||||
>(info: GetMessageChannelListenerInfo<Channel, Message>) {
|
||||
return getInjectable({
|
||||
id: `${info.channel.id}-listener`,
|
||||
id: `${info.channel.id}-listener-${info.id}`,
|
||||
instantiate: (di) => ({
|
||||
channel: info.channel,
|
||||
handler: di.inject(info.handlerInjectable),
|
||||
handler: info.handler(di),
|
||||
}),
|
||||
injectionToken: messageChannelListenerInjectionToken,
|
||||
causesSideEffects: info.causesSideEffects,
|
||||
});
|
||||
}
|
||||
|
||||
@ -4,11 +4,12 @@
|
||||
*/
|
||||
import { syncBoxChannel } from "./channels";
|
||||
import { getMessageChannelListenerInjectable } from "../channel/message-channel-listener-injection-token";
|
||||
import syncBoxChannelHandlerInjectable from "./handler.injectable";
|
||||
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
||||
|
||||
const syncBoxChannelListenerInjectable = getMessageChannelListenerInjectable({
|
||||
id: "init",
|
||||
channel: syncBoxChannel,
|
||||
handlerInjectable: syncBoxChannelHandlerInjectable,
|
||||
handler: (di) => ({ id, value }) => di.inject(syncBoxStateInjectable, id).set(value),
|
||||
});
|
||||
|
||||
export default syncBoxChannelListenerInjectable;
|
||||
|
||||
@ -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, () => () => {});
|
||||
@ -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;
|
||||
@ -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: () => {},
|
||||
}));
|
||||
@ -4,11 +4,12 @@
|
||||
*/
|
||||
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import { reloadPageChannel } from "../common/channel";
|
||||
import reloadPageHandlerInjectable from "./handler.injectable";
|
||||
|
||||
const reloadPageChannelListenerInjectable = getMessageChannelListenerInjectable({
|
||||
id: "handler",
|
||||
channel: reloadPageChannel,
|
||||
handlerInjectable: reloadPageHandlerInjectable,
|
||||
handler: () => () => location.reload(),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default reloadPageChannelListenerInjectable;
|
||||
|
||||
@ -7,8 +7,9 @@ import { getMessageChannelListenerInjectable } from "../../../common/utils/chann
|
||||
import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable";
|
||||
|
||||
const restartAndInstallUpdateListenerInjectable = getMessageChannelListenerInjectable({
|
||||
id: "restart",
|
||||
channel: restartAndInstallUpdateChannel,
|
||||
handlerInjectable: quitAndInstallUpdateInjectable,
|
||||
handler: (di) => di.inject(quitAndInstallUpdateInjectable),
|
||||
});
|
||||
|
||||
export default restartAndInstallUpdateListenerInjectable;
|
||||
|
||||
@ -4,11 +4,17 @@
|
||||
*/
|
||||
import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token";
|
||||
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({
|
||||
id: "action",
|
||||
channel: rootFrameHasRenderedChannel,
|
||||
handlerInjectable: rootFrameHasRenderedHandlerInjectable,
|
||||
handler: (di) => {
|
||||
const runMany = runManyFor(di);
|
||||
|
||||
return runMany(afterRootFrameIsReadyInjectionToken);
|
||||
},
|
||||
});
|
||||
|
||||
export default rootFrameRenderedChannelListenerInjectable;
|
||||
|
||||
@ -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;
|
||||
Loading…
Reference in New Issue
Block a user