Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suppress deprecation warnings to once per unique args #6875

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/api/time/TimeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down