mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce injection token for channels to allow injecting all of them at once
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
09a499ea74
commit
975109b75c
@ -3,7 +3,13 @@
|
|||||||
* 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 { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
export interface Channel<TInstance> {
|
export interface Channel<TInstance> {
|
||||||
id: string;
|
id: string;
|
||||||
_template?: TInstance;
|
_template?: TInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const channelInjectionToken = getInjectionToken<Channel<any>>({
|
||||||
|
id: "channel",
|
||||||
|
});
|
||||||
@ -3,14 +3,14 @@
|
|||||||
* 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 { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type { Channel } from "./channel";
|
import type { Channel } from "./channel-injection-token";
|
||||||
|
|
||||||
export interface ChannelListener<TChannel extends Channel<unknown>> {
|
export interface ChannelListener<TChannel extends Channel<any>> {
|
||||||
channel: TChannel;
|
channel: TChannel;
|
||||||
handler: (value: TChannel["_template"]) => void;
|
handler: (value: TChannel["_template"]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const channelListenerInjectionToken = getInjectionToken<ChannelListener<Channel<unknown>>>(
|
export const channelListenerInjectionToken = getInjectionToken<ChannelListener<Channel<any>>>(
|
||||||
{
|
{
|
||||||
id: "channel-listener",
|
id: "channel-listener",
|
||||||
},
|
},
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { sendToAgnosticChannelInjectionToken } from "./send-to-agnostic-channel-
|
|||||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||||
import { channelListenerInjectionToken } from "./channel-listener-injection-token";
|
import { channelListenerInjectionToken } from "./channel-listener-injection-token";
|
||||||
import createLensWindowInjectable from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
import createLensWindowInjectable from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
||||||
import type { Channel } from "./channel";
|
import type { Channel } from "./channel-injection-token";
|
||||||
|
|
||||||
type TestChannel = Channel<string>;
|
type TestChannel = Channel<string>;
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* 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 { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type { Channel } from "./channel";
|
import type { Channel } from "./channel-injection-token";
|
||||||
|
|
||||||
export type EnlistChannelListener = <TChannel extends Channel<unknown>>(
|
export type EnlistChannelListener = <TChannel extends Channel<unknown>>(
|
||||||
channel: TChannel,
|
channel: TChannel,
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* 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 { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type { Channel } from "./channel";
|
import type { Channel } from "./channel-injection-token";
|
||||||
|
|
||||||
export type SendToAgnosticChannel = <TChannel extends Channel<unknown>>(
|
export type SendToAgnosticChannel = <TChannel extends Channel<unknown>>(
|
||||||
channel: TChannel,
|
channel: TChannel,
|
||||||
|
|||||||
@ -3,20 +3,19 @@
|
|||||||
* 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 { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { SyncBoxChannel } from "./sync-box-channel.injectable";
|
|
||||||
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
|
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
|
||||||
import type { ChannelListener } from "../channel/channel-listener-injection-token";
|
|
||||||
import { channelListenerInjectionToken } from "../channel/channel-listener-injection-token";
|
import { channelListenerInjectionToken } from "../channel/channel-listener-injection-token";
|
||||||
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
||||||
|
|
||||||
const syncBoxChannelListenerInjectable = getInjectable({
|
const syncBoxChannelListenerInjectable = getInjectable({
|
||||||
id: "sync-box-channel-listener",
|
id: "sync-box-channel-listener",
|
||||||
|
|
||||||
instantiate: (di): ChannelListener<SyncBoxChannel> => {
|
instantiate: (di) => {
|
||||||
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
||||||
|
const channel = di.inject(syncBoxChannelInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
channel: di.inject(syncBoxChannelInjectable),
|
channel,
|
||||||
|
|
||||||
handler: ({ id, value }) => {
|
handler: ({ id, value }) => {
|
||||||
const target = getSyncBoxState(id);
|
const target = getSyncBoxState(id);
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
* 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 { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { Channel } from "../channel/channel";
|
import type { Channel } from "../channel/channel-injection-token";
|
||||||
|
import { channelInjectionToken } from "../channel/channel-injection-token";
|
||||||
|
|
||||||
export type SyncBoxChannel = Channel<{ id: string; value: unknown }>;
|
export type SyncBoxChannel = Channel<{ id: string; value: unknown }>;
|
||||||
|
|
||||||
@ -13,6 +14,8 @@ const syncBoxChannelInjectable = getInjectable({
|
|||||||
instantiate: (): SyncBoxChannel => ({
|
instantiate: (): SyncBoxChannel => ({
|
||||||
id: "sync-box-channel",
|
id: "sync-box-channel",
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
injectionToken: channelInjectionToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default syncBoxChannelInjectable;
|
export default syncBoxChannelInjectable;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user