When I saw this line below, what it tells me straight away is that it’s something to do with no operation :
const noOp = () => {};
When you look at this, it’s doing nothing. I mean, it’s just an arrow function that returns an empty object So you might be wondering how is this used? So that’s what we will find out.
When I click on the no-op, these are the symbols I found on the right side and in the same file, I see that this variable is used at line 103.
When I click and jump to that line, you will see that this is inside a function called setLevel.
private setLevel() { const { levels } = this.internalLogger; for (const logLevel of LOG_LEVELS) { if (levels[logLevel] > levels[this.level]) { // numerically higher (less severe) log levels become no-op // to prevent overhead from `callsites` calls Object.defineProperty(this, logLevel, { value: noOp }); } } }
and then you get the levels from internalLogger. There’s LOG_LEVELS, obviously that’s a constant we are not looking into as we are only focusing on the noOp, So this noop is an arrow function that returns an empty object But obviously I would be more interested in the comment that is defined just above this line 103.
So what does this comment tell us?
// numerically higher (less severe) log levels become no-op
// to prevent overhead from callsites calls
Tbh, I don’t know how exactly no-op prevents overhead from callsites calls. I know for a fact that callsites is something you would use to get the trace in the v8 JavaScript engine that is used in the Google Chrome. for example, callsites provides you with API like get function name. You can also find out the function that’s calling this function there are bunch of other APIs too.
But again we are focusing on the no-op so obviously the value is an empty object and they have used defined property.
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
Configure features such as Changesets in your Next.js project usingThink Throo CLI.