Separate concept of message and request channels

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-tursoandJanne Savolainen authored and Janne Savolainen committed 2022-06-03 07:49:43 +03:00
1 parent c01e935422
commit fdef6973e3
64 files changed
+685 -497

No files matched your search

@@ -3,11 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import type { AppPaths } from "./app-path-injection-token";
import type { RequestChannel } from "../channel/request-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
export type AppPathsChannel = Channel<AppPaths, AppPaths>;
export type AppPathsChannel = RequestChannel<void, AppPaths>;
const appPathsChannelInjectable = getInjectable({
id: "app-paths-channel",
@@ -16,7 +16,7 @@ const appPathsChannelInjectable = getInjectable({
id: "app-paths",
}),
injectionToken: channelInjectionToken,
injectionToken: messageChannelInjectionToken,
});
export default appPathsChannelInjectable;
@@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
export type ApplicationUpdateStatusEventId =
| "checking-for-updates"
@@ -13,7 +13,7 @@ export type ApplicationUpdateStatusEventId =
| "download-for-update-failed";
export interface ApplicationUpdateStatusChannelMessage { eventId: ApplicationUpdateStatusEventId; version?: string }
export type ApplicationUpdateStatusChannel = Channel<ApplicationUpdateStatusChannelMessage>;
export type ApplicationUpdateStatusChannel = MessageChannel<ApplicationUpdateStatusChannelMessage>;
const applicationUpdateStatusChannelInjectable = getInjectable({
id: "application-update-status-channel",
@@ -22,7 +22,7 @@ const applicationUpdateStatusChannelInjectable = getInjectable({
id: "application-update-status-channel",
}),
injectionToken: channelInjectionToken,
injectionToken: messageChannelInjectionToken,
});
export default applicationUpdateStatusChannelInjectable;
@@ -3,10 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
type AskBooleanAnswerChannel = Channel<{ id: string; value: boolean }>;
export type AskBooleanAnswerChannel = MessageChannel<{ id: string; value: boolean }>;
const askBooleanAnswerChannelInjectable = getInjectable({
id: "ask-boolean-answer-channel",
@@ -15,7 +15,7 @@ const askBooleanAnswerChannelInjectable = getInjectable({
id: "ask-boolean-answer",
}),
injectionToken: channelInjectionToken,
injectionToken: messageChannelInjectionToken,
});
export default askBooleanAnswerChannelInjectable;
@@ -3,11 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
export interface AskBooleanQuestionParameters { id: string; title: string; question: string }
export type AskBooleanQuestionChannel = Channel<AskBooleanQuestionParameters>;
export type AskBooleanQuestionChannel = MessageChannel<AskBooleanQuestionParameters>;
const askBooleanQuestionChannelInjectable = getInjectable({
id: "ask-boolean-question-channel",
@@ -16,7 +16,7 @@ const askBooleanQuestionChannelInjectable = getInjectable({
id: "ask-boolean-question",
}),
injectionToken: channelInjectionToken,
injectionToken: messageChannelInjectionToken,
});
export default askBooleanQuestionChannelInjectable;
@@ -3,7 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
export interface Channel<MessageTemplate = void, ReturnTemplate = void> {
id: string;
@@ -11,6 +10,3 @@ export interface Channel<MessageTemplate = void, ReturnTemplate = void> {
_returnTemplate?: ReturnTemplate;
}
export const channelInjectionToken = getInjectionToken<Channel<any, any>>({
id: "channel",
});
@@ -1,17 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Channel } from "./channel-injection-token";
export interface ChannelListener<TChannel extends Channel<any, any>> {
channel: TChannel;
handler: (value: TChannel["_messageTemplate"]) => TChannel["_returnTemplate"];
}
export const channelListenerInjectionToken = getInjectionToken<ChannelListener<Channel<any, any>>>(
{
id: "channel-listener",
},
);
+17 -17
View File
@@ -6,22 +6,22 @@ import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import type { LensWindow } from "../../main/start-main-application/lens-window/application-window/lens-window-injection-token";
import { lensWindowInjectionToken } from "../../main/start-main-application/lens-window/application-window/lens-window-injection-token";
import type { SendToChannel } from "./send-to-channel-injection-token";
import { sendToChannelInjectionToken } from "./send-to-channel-injection-token";
import type { MessageToChannel } from "./message-to-channel-injection-token";
import { messageToChannelInjectionToken } from "./message-to-channel-injection-token";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { channelListenerInjectionToken } from "./channel-listener-injection-token";
import createLensWindowInjectable from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
import type { Channel } from "./channel-injection-token";
import closeAllWindowsInjectable from "../../main/start-main-application/lens-window/hide-all-windows/close-all-windows.injectable";
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
import type { MessageChannel } from "./message-channel-injection-token";
type TestChannel = Channel<string>;
type TestChannel = MessageChannel<string>;
describe("channel", () => {
describe("messaging from main to renderer, given listener for channel in a window and application has started", () => {
let testChannel: TestChannel;
let testListenerInWindowMock: jest.Mock;
let mainDi: DiContainer;
let sendToChannel: SendToChannel;
let messageToChannel: MessageToChannel;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
@@ -40,7 +40,7 @@ describe("channel", () => {
handler: testListenerInWindowMock,
}),
injectionToken: channelListenerInjectionToken,
injectionToken: messageChannelListenerInjectionToken,
});
rendererDi.register(testChannelListenerInTestWindowInjectable);
@@ -51,8 +51,8 @@ describe("channel", () => {
testChannel = mainDi.inject(testChannelInjectable);
sendToChannel = mainDi.inject(
sendToChannelInjectionToken,
messageToChannel = mainDi.inject(
messageToChannelInjectionToken,
);
await applicationBuilder.render();
@@ -72,7 +72,7 @@ describe("channel", () => {
});
it("when sending message, triggers listener in window", () => {
sendToChannel(testChannel, "some-message");
messageToChannel(testChannel, "some-message");
expect(testListenerInWindowMock).toHaveBeenCalledWith("some-message");
});
@@ -80,7 +80,7 @@ describe("channel", () => {
it("given window is hidden, when sending message, does not trigger listener in window", () => {
someWindowFake.close();
sendToChannel(testChannel, "some-message");
messageToChannel(testChannel, "some-message");
expect(testListenerInWindowMock).not.toHaveBeenCalled();
});
@@ -93,7 +93,7 @@ describe("channel", () => {
await someWindowFake.show();
await someOtherWindowFake.show();
sendToChannel(testChannel, "some-message");
messageToChannel(testChannel, "some-message");
expect(testListenerInWindowMock.mock.calls).toEqual([
["some-message"],
@@ -107,7 +107,7 @@ describe("channel", () => {
let testListenerInMainMock: jest.Mock;
let rendererDi: DiContainer;
let mainDi: DiContainer;
let sendToChannel: SendToChannel;
let messageToChannel: MessageToChannel;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
@@ -126,7 +126,7 @@ describe("channel", () => {
handler: testListenerInMainMock,
}),
injectionToken: channelListenerInjectionToken,
injectionToken: messageChannelListenerInjectionToken,
});
mainDi.register(testChannelListenerInMainInjectable);
@@ -137,15 +137,15 @@ describe("channel", () => {
testChannel = rendererDi.inject(testChannelInjectable);
sendToChannel = rendererDi.inject(
sendToChannelInjectionToken,
messageToChannel = rendererDi.inject(
messageToChannelInjectionToken,
);
await applicationBuilder.render();
});
it("when sending message, triggers listener in main", () => {
sendToChannel(testChannel, "some-message");
messageToChannel(testChannel, "some-message");
expect(testListenerInMainMock).toHaveBeenCalledWith("some-message");
});
@@ -1,16 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Channel } from "./channel-injection-token";
export type EnlistChannelListener = <TChannel extends Channel<unknown, unknown>>(
channel: TChannel,
handler: (value: TChannel["_messageTemplate"]) => TChannel["_returnTemplate"]
) => () => void;
export const enlistChannelListenerInjectionToken =
getInjectionToken<EnlistChannelListener>({
id: "enlist-channel-listener",
});
@@ -0,0 +1,16 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { MessageChannel } from "./message-channel-injection-token";
import type { MessageChannelListener } from "./message-channel-listener-injection-token";
export type EnlistMessageChannelListener = <
TChannel extends MessageChannel<unknown>,
>(listener: MessageChannelListener<TChannel>) => () => void;
export const enlistMessageChannelListenerInjectionToken =
getInjectionToken<EnlistMessageChannelListener>({
id: "enlist-message-channel-listener",
});
@@ -0,0 +1,16 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { RequestChannel } from "./request-channel-injection-token";
import type { RequestChannelListener } from "./request-channel-listener-injection-token";
export type EnlistRequestChannelListener = <
TChannel extends RequestChannel<unknown, unknown>,
>(listener: RequestChannelListener<TChannel>) => () => void;
export const enlistRequestChannelListenerInjectionToken =
getInjectionToken<EnlistRequestChannelListener>({
id: "enlist-request-channel-listener",
});
@@ -4,23 +4,26 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../utils/get-startable-stoppable";
import { channelListenerInjectionToken } from "./channel-listener-injection-token";
import { enlistChannelListenerInjectionToken } from "./enlist-channel-listener-injection-token";
import { disposer } from "../utils";
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
import { requestChannelListenerInjectionToken } from "./request-channel-listener-injection-token";
import { enlistMessageChannelListenerInjectionToken } from "./enlist-message-channel-listener-injection-token";
import { enlistRequestChannelListenerInjectionToken } from "./enlist-request-channel-listener-injection-token";
const listeningOfChannelsInjectable = getInjectable({
id: "listening-of-channels",
instantiate: (di) => {
const enlistChannelListener = di.inject(enlistChannelListenerInjectionToken);
const channelListeners = di.injectMany(channelListenerInjectionToken);
const enlistMessageChannelListener = di.inject(enlistMessageChannelListenerInjectionToken);
const enlistRequestChannelListener = di.inject(enlistRequestChannelListenerInjectionToken);
const messageChannelListeners = di.injectMany(messageChannelListenerInjectionToken);
const requestChannelListeners = di.injectMany(requestChannelListenerInjectionToken);
return getStartableStoppable("listening-of-channels", () => {
const disposers = channelListeners.map(({ channel, handler }) =>
enlistChannelListener(channel, handler),
);
const messageChannelDisposers = messageChannelListeners.map(enlistMessageChannelListener);
const requestChannelDisposers = requestChannelListeners.map(enlistRequestChannelListener);
return disposer(...disposers);
return disposer(...messageChannelDisposers, ...requestChannelDisposers);
});
},
});
@@ -0,0 +1,15 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
export interface MessageChannel<Message = void> {
id: string;
_messageSignature?: Message;
}
export const messageChannelInjectionToken = getInjectionToken<MessageChannel<any>>({
id: "message-channel",
});
@@ -0,0 +1,18 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { SetRequired } from "type-fest";
import type { MessageChannel } from "./message-channel-injection-token";
export interface MessageChannelListener<TChannel extends MessageChannel<any>> {
channel: TChannel;
handler: (value: SetRequired<TChannel, "_messageSignature">["_messageSignature"]) => void;
}
export const messageChannelListenerInjectionToken = getInjectionToken<MessageChannelListener<MessageChannel<any>>>(
{
id: "message-channel-listener",
},
);
@@ -0,0 +1,22 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { MessageChannel } from "./message-channel-injection-token";
export interface MessageToChannel {
<TChannel extends MessageChannel<TMessage>, TMessage extends void>(
channel: TChannel,
): void;
<TChannel extends MessageChannel<TMessage>, TMessage>(
channel: TChannel,
message: TMessage
): void;
}
export const messageToChannelInjectionToken =
getInjectionToken<MessageToChannel>({
id: "message-to-message-channel",
});
@@ -0,0 +1,16 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
export interface RequestChannel<Request = void, Response = void> {
id: string;
_requestSignature?: Request;
_responseSignature?: Response;
}
export const requestChannelInjectionToken = getInjectionToken<RequestChannel<any, any>>({
id: "request-channel",
});
@@ -0,0 +1,17 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { RequestChannel } from "./request-channel-injection-token";
export interface RequestChannelListener<TChannel extends RequestChannel<any, any>> {
channel: TChannel;
handler: (request: TChannel["_requestSignature"]) => TChannel["_responseSignature"];
}
export const requestChannelListenerInjectionToken = getInjectionToken<RequestChannelListener<RequestChannel<any, any>>>(
{
id: "request-channel-listener",
},
);
@@ -0,0 +1,21 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { SetRequired } from "type-fest";
import type { RequestChannel } from "./request-channel-injection-token";
export type RequestFromChannel = <
TChannel extends RequestChannel<unknown, unknown>,
>(
channel: TChannel,
...request: TChannel["_requestSignature"] extends void
? []
: [TChannel["_requestSignature"]]
) => Promise<SetRequired<TChannel, "_responseSignature">["_responseSignature"]>;
export const requestFromChannelInjectionToken =
getInjectionToken<RequestFromChannel>({
id: "request-from-request-channel",
});
@@ -1,16 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { Channel } from "./channel-injection-token";
export type SendToChannel = <TChannel extends Channel<unknown, unknown>>(
channel: TChannel,
message?: TChannel["_messageTemplate"]
) => void;
export const sendToChannelInjectionToken =
getInjectionToken<SendToChannel>({
id: "send-to-channel",
});
@@ -3,11 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
export type AppNavigationChannel = Channel<string>;
export type AppNavigationChannel = MessageChannel<string>;
const appNavigationChannelInjectable = getInjectable({
id: "app-navigation-channel",
@@ -16,7 +16,7 @@ const appNavigationChannelInjectable = getInjectable({
id: IpcRendererNavigationEvents.NAVIGATE_IN_APP,
}),
injectionToken: channelInjectionToken,
injectionToken: messageChannelInjectionToken,
});
export default appNavigationChannelInjectable;
@@ -3,11 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
export type ClusterFrameNavigationChannel = Channel<string>;
export type ClusterFrameNavigationChannel = MessageChannel<string>;
const clusterFrameNavigationChannelInjectable = getInjectable({
id: "cluster-frame-navigation-channel",
@@ -16,7 +16,7 @@ const clusterFrameNavigationChannelInjectable = getInjectable({
id: IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER,
}),
injectionToken: channelInjectionToken,
injectionToken: messageChannelInjectionToken,
});
export default clusterFrameNavigationChannelInjectable;
@@ -3,10 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
export type RootFrameRenderedChannel = Channel;
export type RootFrameRenderedChannel = MessageChannel;
const rootFrameRenderedChannelInjectable = getInjectable({
id: "root-frame-rendered-channel",
@@ -15,7 +15,7 @@ const rootFrameRenderedChannelInjectable = getInjectable({
id: "root-frame-rendered",
}),
injectionToken: channelInjectionToken,
injectionToken: messageChannelInjectionToken,
});
export default rootFrameRenderedChannelInjectable;
@@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
import { sendToChannelInjectionToken } from "../channel/send-to-channel-injection-token";
import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token";
import syncBoxStateInjectable from "./sync-box-state.injectable";
import type { SyncBox } from "./sync-box-injection-token";
@@ -14,7 +14,7 @@ const createSyncBoxInjectable = getInjectable({
instantiate: (di) => {
const syncBoxChannel = di.inject(syncBoxChannelInjectable);
const sendToChannel = di.inject(sendToChannelInjectionToken);
const messageToChannel = di.inject(messageToChannelInjectionToken);
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
return <TData>(id: string, initialValue: TData): SyncBox<TData> => {
@@ -30,7 +30,7 @@ const createSyncBoxInjectable = getInjectable({
set: (value) => {
state.set(value);
sendToChannel(syncBoxChannel, { id, value });
messageToChannel(syncBoxChannel, { id, value });
},
};
};
@@ -3,14 +3,16 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { SyncBoxChannel } from "./sync-box-channel.injectable";
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
import { channelListenerInjectionToken } from "../channel/channel-listener-injection-token";
import syncBoxStateInjectable from "./sync-box-state.injectable";
import type { MessageChannelListener } from "../channel/message-channel-listener-injection-token";
import { messageChannelListenerInjectionToken } from "../channel/message-channel-listener-injection-token";
const syncBoxChannelListenerInjectable = getInjectable({
id: "sync-box-channel-listener",
instantiate: (di) => {
instantiate: (di): MessageChannelListener<SyncBoxChannel> => {
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
const channel = di.inject(syncBoxChannelInjectable);
@@ -27,7 +29,7 @@ const syncBoxChannelListenerInjectable = getInjectable({
};
},
injectionToken: channelListenerInjectionToken,
injectionToken: messageChannelListenerInjectionToken,
});
export default syncBoxChannelListenerInjectable;
@@ -3,10 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
export type SyncBoxChannel = Channel<{ id: string; value: unknown }>;
export type SyncBoxChannel = MessageChannel<{ id: string; value: any }>;
const syncBoxChannelInjectable = getInjectable({
id: "sync-box-channel",
@@ -15,7 +15,7 @@ const syncBoxChannelInjectable = getInjectable({
id: "sync-box-channel",
}),
injectionToken: channelInjectionToken,
injectionToken: messageChannelInjectionToken,
});
export default syncBoxChannelInjectable;
@@ -3,10 +3,13 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Channel } from "../channel/channel-injection-token";
import { channelInjectionToken } from "../channel/channel-injection-token";
import type { RequestChannel } from "../channel/request-channel-injection-token";
import { requestChannelInjectionToken } from "../channel/request-channel-injection-token";
export type SyncBoxInitialValueChannel = Channel<never, { id: string; value: unknown }[]>;
export type SyncBoxInitialValueChannel = RequestChannel<
void,
{ id: string; value: unknown }[]
>;
const syncBoxInitialValueChannelInjectable = getInjectable({
id: "sync-box-initial-value-channel",
@@ -15,7 +18,7 @@ const syncBoxInitialValueChannelInjectable = getInjectable({
id: "sync-box-initial-value-channel",
}),
injectionToken: channelInjectionToken,
injectionToken: requestChannelInjectionToken,
});
export default syncBoxInitialValueChannelInjectable;
@@ -4,8 +4,9 @@
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { IComputedValue } from "mobx";
import type { JsonValue } from "type-fest";
export interface SyncBox<TValue> {
export interface SyncBox<TValue extends JsonValue> {
id: string;
value: IComputedValue<TValue>;
set: (value: TValue) => void;