Revert "Implement requesting from renderer in main"

This reverts commit d3e7899d7900516f3dbfacdb317a453202318305.

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen committed 2022-06-03 07:49:45 +03:00
1 parent 2427ee13e6
commit 5f8aaac6a6
7 files changed
-258

No files matched your search

-69
View File
@@ -227,75 +227,6 @@ describe("channel", () => {
});
});
});
describe("requesting from renderer in main, given listener for channel in a renderer and application has started", () => {
let testRequestChannel: TestRequestChannel;
let requestListenerInRendererMock: AsyncFnMock<(arg: string) => string>;
let rendererDi: DiContainer;
let mainDi: DiContainer;
let requestFromChannel: RequestFromChannel;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
mainDi = applicationBuilder.dis.mainDi;
rendererDi = applicationBuilder.dis.rendererDi;
requestListenerInRendererMock = asyncFn();
const testChannelListenerInRendererInjectable = getInjectable({
id: "test-channel-listener-in-renderer",
instantiate: (di) => ({
channel: di.inject(testRequestChannelInjectable),
handler: requestListenerInRendererMock,
}),
injectionToken: requestChannelListenerInjectionToken,
});
rendererDi.register(testChannelListenerInRendererInjectable);
// Notice how test channel has presence in both DIs, being from common
mainDi.register(testRequestChannelInjectable);
rendererDi.register(testRequestChannelInjectable);
testRequestChannel = mainDi.inject(testRequestChannelInjectable);
requestFromChannel = mainDi.inject(
requestFromChannelInjectionToken,
);
await applicationBuilder.render();
});
describe("when requesting from channel", () => {
let actualPromise: Promise<string>;
beforeEach(() => {
actualPromise = requestFromChannel(testRequestChannel, "some-request");
});
it("triggers listener in renderer", () => {
expect(requestListenerInRendererMock).toHaveBeenCalledWith("some-request");
});
it("does not resolve yet", async () => {
const promiseStatus = await getPromiseStatus(actualPromise);
expect(promiseStatus.fulfilled).toBe(false);
});
it("when renderer resolves with response, resolves with response", async () => {
await requestListenerInRendererMock.resolve("some-response");
const actual = await actualPromise;
expect(actual).toBe("some-response");
});
});
});
});
const testMessageChannelInjectable = getInjectable({
@@ -1,21 +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 { MessageChannel } from "../message-channel-injection-token";
import { messageChannelInjectionToken } from "../message-channel-injection-token";
export type RequestFromChannelForMainRequestChannel = MessageChannel<{ channelId: string; request: any }>;
const requestFromChannelForMainRequestChannelInjectable = getInjectable({
id: "request-from-channel-for-main-request-channel",
instantiate: (): RequestFromChannelForMainRequestChannel => ({
id: "request-from-channel-for-main-request-channel",
}),
injectionToken: messageChannelInjectionToken,
});
export default requestFromChannelForMainRequestChannelInjectable;
@@ -1,21 +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 { MessageChannel } from "../message-channel-injection-token";
import { messageChannelInjectionToken } from "../message-channel-injection-token";
export type RequestFromChannelForMainResponseChannel = MessageChannel<{ channelId: string; response: any }>;
const requestFromChannelForMainResponseChannelInjectable = getInjectable({
id: "request-from-channel-for-main-response-channel",
instantiate: (): RequestFromChannelForMainResponseChannel => ({
id: "request-from-channel-for-main-response-channel",
}),
injectionToken: messageChannelInjectionToken,
});
export default requestFromChannelForMainResponseChannelInjectable;