From 0f5d3afc4a0e747aa261f0652711670acb03188a Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Wed, 2 Aug 2023 09:50:29 -0700 Subject: [PATCH] cherry pick (#6875) suppress deprecation warnings to once per unique args (#6881) fix: suppress deprecation warnings to once per unique args (#6875) Co-authored-by: Jesse Mazzella --- src/api/time/TimeContext.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/api/time/TimeContext.js b/src/api/time/TimeContext.js index 8ff1657696..e18530331f 100644 --- a/src/api/time/TimeContext.js +++ b/src/api/time/TimeContext.js @@ -42,6 +42,7 @@ class TimeContext extends EventEmitter { this.activeClock = undefined; this.offsets = undefined; this.mode = undefined; + this.warnCounts = {}; this.tick = this.tick.bind(this); } @@ -648,6 +649,17 @@ class TimeContext extends EventEmitter { } #warnMethodDeprecated(method, newMethod) { + const MAX_CALLS = 1; // Only warn once per unique method and newMethod combination + + const key = `${method}.${newMethod}`; + const currentWarnCount = this.warnCounts[key] || 0; + + if (currentWarnCount >= MAX_CALLS) { + return; // Don't warn if already warned once + } + + this.warnCounts[key] = currentWarnCount + 1; + let message = `[DEPRECATION WARNING]: The ${method} API method is deprecated and will be removed in a future version of Open MCT.`; if (newMethod) {