1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add stricter typing, and simplify code

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-09-02 14:59:44 +03:00
parent c058e89238
commit 95babe245c

View File

@ -2,7 +2,10 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* 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 type { DiContainerForInjection } from "@ogre-tools/injectable"; import type {
DiContainerForInjection,
Injectable,
} from "@ogre-tools/injectable";
import { import {
lifecycleEnum, lifecycleEnum,
@ -11,7 +14,6 @@ import {
} from "@ogre-tools/injectable"; } from "@ogre-tools/injectable";
import assert from "assert"; import assert from "assert";
import { isFunction } from "lodash/fp"; import { isFunction } from "lodash/fp";
import emitTelemetryInjectable from "./emit-telemetry.injectable"; import emitTelemetryInjectable from "./emit-telemetry.injectable";
import telemetryWhiteListForFunctionsInjectable from "./telemetry-white-list-for-functions.injectable"; import telemetryWhiteListForFunctionsInjectable from "./telemetry-white-list-for-functions.injectable";
@ -23,9 +25,11 @@ const telemetryDecoratorInjectable = getInjectable({
const emitTelemetry = diForDecorator.inject(emitTelemetryInjectable); const emitTelemetry = diForDecorator.inject(emitTelemetryInjectable);
const whiteList = diForDecorator.inject( const whiteList = diForDecorator.inject(
telemetryWhiteListForFunctionsInjectable, telemetryWhiteListForFunctionsInjectable
); );
const shouldEmitTelemetry = shouldEmitTelemetryFor(whiteList);
return { return {
decorate: decorate:
(instantiateToBeDecorated: any) => (instantiateToBeDecorated: any) =>
@ -38,7 +42,7 @@ const telemetryDecoratorInjectable = getInjectable({
assert(currentContext); assert(currentContext);
if (shouldEmitTelemetry(currentContext, whiteList)) { if (shouldEmitTelemetry(currentContext.injectable)) {
emitTelemetry({ action: currentContext.injectable.id, args }); emitTelemetry({ action: currentContext.injectable.id, args });
} }
@ -57,9 +61,10 @@ const telemetryDecoratorInjectable = getInjectable({
injectionToken: instantiationDecoratorToken, injectionToken: instantiationDecoratorToken,
}); });
const shouldEmitTelemetry = (currentContext: any, whiteList: any) => ( const shouldEmitTelemetryFor = (whiteList: string[]) => (
currentContext.injectable.tags?.includes("emit-telemetry") || injectable: Injectable<any, any, any>,
whiteList.includes(currentContext.injectable.id) ) =>
); injectable.tags?.includes("emit-telemetry") ||
whiteList.includes(injectable.id);
export default telemetryDecoratorInjectable; export default telemetryDecoratorInjectable;