mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactor for reduced nesting
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> Co-authored-by: Gabriel <gaccettola@mirantis.com>
This commit is contained in:
parent
3931c90d30
commit
f3ecdddcb5
@ -27,54 +27,54 @@ const telemetryDecoratorInjectable = getInjectable({
|
|||||||
(di: DiContainerForInjection, instantiationParameter: any) => {
|
(di: DiContainerForInjection, instantiationParameter: any) => {
|
||||||
const instance = instantiateToBeDecorated(di, instantiationParameter);
|
const instance = instantiateToBeDecorated(di, instantiationParameter);
|
||||||
|
|
||||||
if (isFunction(instance)) {
|
if (!isFunction(instance)) {
|
||||||
return (...args: any[]) => {
|
return instance;
|
||||||
const currentContext = di.context.at(-1);
|
|
||||||
|
|
||||||
assert(currentContext);
|
|
||||||
|
|
||||||
const emitTelemetry = diForDecorator.inject(
|
|
||||||
emitTelemetryInjectable,
|
|
||||||
);
|
|
||||||
|
|
||||||
const logError = diForDecorator.inject(logErrorInjectable);
|
|
||||||
|
|
||||||
const whiteList = diForDecorator.inject(
|
|
||||||
telemetryWhiteListForFunctionsInjectable,
|
|
||||||
);
|
|
||||||
|
|
||||||
const whiteListMap = getWhiteListMap(whiteList);
|
|
||||||
|
|
||||||
const whiteListed = whiteListMap.get(currentContext.injectable.id);
|
|
||||||
|
|
||||||
if (whiteListed) {
|
|
||||||
let params;
|
|
||||||
|
|
||||||
try {
|
|
||||||
params = whiteListed.getParams(...args);
|
|
||||||
} catch (e) {
|
|
||||||
params = {
|
|
||||||
error:
|
|
||||||
"Tried to produce params for telemetry, but getParams() threw an error",
|
|
||||||
};
|
|
||||||
|
|
||||||
logError(
|
|
||||||
`Tried to produce params for telemetry of "${currentContext.injectable.id}", but getParams() threw an error`,
|
|
||||||
e,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
emitTelemetry({
|
|
||||||
action: currentContext.injectable.id,
|
|
||||||
params,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance(...args);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return (...args: any[]) => {
|
||||||
|
const currentContext = di.context.at(-1);
|
||||||
|
|
||||||
|
assert(currentContext);
|
||||||
|
|
||||||
|
const emitTelemetry = diForDecorator.inject(
|
||||||
|
emitTelemetryInjectable
|
||||||
|
);
|
||||||
|
|
||||||
|
const logError = diForDecorator.inject(logErrorInjectable);
|
||||||
|
|
||||||
|
const whiteList = diForDecorator.inject(
|
||||||
|
telemetryWhiteListForFunctionsInjectable
|
||||||
|
);
|
||||||
|
|
||||||
|
const whiteListMap = getWhiteListMap(whiteList);
|
||||||
|
|
||||||
|
const whiteListed = whiteListMap.get(currentContext.injectable.id);
|
||||||
|
|
||||||
|
if (whiteListed) {
|
||||||
|
let params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
params = whiteListed.getParams(...args);
|
||||||
|
} catch (e) {
|
||||||
|
params = {
|
||||||
|
error:
|
||||||
|
"Tried to produce params for telemetry, but getParams() threw an error",
|
||||||
|
};
|
||||||
|
|
||||||
|
logError(
|
||||||
|
`Tried to produce params for telemetry of "${currentContext.injectable.id}", but getParams() threw an error`,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
emitTelemetry({
|
||||||
|
action: currentContext.injectable.id,
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance(...args);
|
||||||
|
};
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user