1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/ask-boolean/ask-boolean.injectable.ts
Janne Savolainen 82e268eff3
Move another utility function under directory
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-06-03 07:49:47 +03:00

40 lines
1.3 KiB
TypeScript

/**
* 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 { messageToChannelInjectionToken } from "../../common/utils/channel/message-to-channel-injection-token";
import askBooleanQuestionChannelInjectable from "../../common/ask-boolean/ask-boolean-question-channel.injectable";
import askBooleanPromiseInjectable from "./ask-boolean-promise.injectable";
import getRandomIdInjectable from "../../common/utils/get-random-id.injectable";
export type AskBoolean = ({
title,
question,
}: {
title: string;
question: string;
}) => Promise<boolean>;
const askBooleanInjectable = getInjectable({
id: "ask-boolean",
instantiate: (di): AskBoolean => {
const messageToChannel = di.inject(messageToChannelInjectionToken);
const askBooleanChannel = di.inject(askBooleanQuestionChannelInjectable);
const getRandomId = di.inject(getRandomIdInjectable);
return async ({ title, question }) => {
const id = getRandomId();
const returnValuePromise = di.inject(askBooleanPromiseInjectable, id);
await messageToChannel(askBooleanChannel, { id, title, question });
return await returnValuePromise.promise;
};
},
});
export default askBooleanInjectable;