Hi there,
I have the following task and am investigating ways to solve it. It’s about debugging. I have a value converter that is widely used across the entire app. I want it under certain conditions, for example:
toView(value) {
if (value?.foo === value?.bar) {
console.info('We have a match!');
//And here I want to know which component caused the invocation of this condition.
}
}
My aim is to get information about the place where the value converter is invoked, matching this condition.
Is that possible, and can you give me some hints on achieving such debug functionality?
How do you mean “Via the inspector”?
I need something like:
...
toView(value, ...args) {
_normalizeValue(value) {
switch (true) {
case typeof value === 'number':
case Number.isFinite(value):
// call the logger service and log the wrong payload passed
console.trace(value, 'is not a valid value');
return { amount: value, currency: this.defaultCurrency, amountSecondary: value?.amountSecondary ?? value };
case typeof value === 'string' && Number.isFinite(Number(value)):
return { amount: Number(value), currency: this.defaultCurrency, amountSecondary: value?.amountSecondary ?? value };
default:
return { amount: value?.amount, currency: this.defaultCurrency, amountSecondary: value.amountSecondary };
}
}
}
I need to call let say a LoggerService in the first case and write some useful information like the name of the file or the Callee, or the class invoking the value converter in this condition.
I mean if you’re debugging and trying to find where your value converter was called, go to your browsers’ web inspector sources tab, and set a conditional breakpoint with Number.isFinite(value) == true in the source code, in the toView() method. The script will stop when it meets your condition. Then look in the stack trace to check where it was called.
Hi Esger,
Thank you for the tip. Maybe I expressed myself incorrectly. The functionality I’m looking for is invoking a logging service, which will call an endpoint and write the call stack: no browser console, no dev-tools. Testing engenders and users will browse the system, and later, I can read the logs from the server and see the place of invocation of the value converter.