mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
fix: prevent console logging duplicate deprecation warnings (#7733)
* (feat): added Set to prevent console logging multiple deprecation warnings #7719 * feat!: added Set to prevent console logging multiple deprecation warnings #7719 * refactor: renamed variable and rewrote comment Edited By Cpcallen Co-authored-by: Christopher Allen <cpcallen+github@gmail.com> * refactor: added guard clause and rewrote comment Edited By Cpcallen Co-authored-by: Christopher Allen <cpcallen+github@gmail.com> * refactor: removed checkMsg Variable name and replaced it with previousWarnings * refactor: removed checkMsg Variable name and replaced it with previousWarnings --------- Co-authored-by: Christopher Allen <cpcallen+github@gmail.com>
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
|
||||
// Former goog.module ID: Blockly.utils.deprecation
|
||||
|
||||
// Set of previously-emitted warnings.
|
||||
const previousWarnings = new Set();
|
||||
|
||||
/**
|
||||
* Warn developers that a function or property is deprecated.
|
||||
*
|
||||
@@ -33,5 +36,12 @@ export function warn(
|
||||
if (opt_use) {
|
||||
msg += '\nUse ' + opt_use + ' instead.';
|
||||
}
|
||||
|
||||
// Don't log deprecation warnings multiple times.
|
||||
if (previousWarnings.has(msg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
previousWarnings.add(msg);
|
||||
console.warn(msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user