mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
Add deprecation helper + 2 uses
This commit is contained in:
@@ -25,6 +25,7 @@ goog.require('Blockly.fieldRegistry');
|
||||
goog.require('Blockly.Input');
|
||||
goog.require('Blockly.navigation');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.deprecation');
|
||||
goog.require('Blockly.utils.Coordinate');
|
||||
goog.require('Blockly.utils.object');
|
||||
goog.require('Blockly.utils.string');
|
||||
@@ -1242,8 +1243,11 @@ Blockly.Block.prototype.getOutputShape = function() {
|
||||
* @deprecated May 2019
|
||||
*/
|
||||
Blockly.Block.prototype.setDisabled = function(disabled) {
|
||||
console.warn('Deprecated call to Blockly.Block.prototype.setDisabled, ' +
|
||||
'use Blockly.Block.prototype.setEnabled instead.');
|
||||
Blockly.utils.deprecation.warn(
|
||||
'Blockly.Block.prototype.setDisabled',
|
||||
'May 2019',
|
||||
'May 2020',
|
||||
'Blockly.Block.prototype.setEnabled');
|
||||
this.setEnabled(!disabled);
|
||||
};
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ goog.require('Blockly.TabNavigateCursor');
|
||||
goog.require('Blockly.Tooltip');
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.deprecation');
|
||||
goog.require('Blockly.utils.Coordinate');
|
||||
goog.require('Blockly.utils.dom');
|
||||
goog.require('Blockly.utils.object');
|
||||
@@ -1066,7 +1067,7 @@ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
|
||||
collapsedParent.setWarningText(Blockly.Msg['COLLAPSED_WARNINGS_WARNING'],
|
||||
Blockly.BlockSvg.COLLAPSED_WARNING_ID);
|
||||
}
|
||||
|
||||
|
||||
if (!this.warning) {
|
||||
this.warning = new Blockly.Warning(this);
|
||||
changedState = true;
|
||||
@@ -1120,8 +1121,11 @@ Blockly.BlockSvg.prototype.setMutator = function(mutator) {
|
||||
* @deprecated May 2019
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.setDisabled = function(disabled) {
|
||||
console.warn('Deprecated call to Blockly.BlockSvg.prototype.setDisabled, ' +
|
||||
'use Blockly.BlockSvg.prototype.setEnabled instead.');
|
||||
Blockly.utils.deprecation.warn(
|
||||
'Blockly.BlockSvg.prototype.setDisabled',
|
||||
'May 2019',
|
||||
'May 2020',
|
||||
'Blockly.BlockSvg.prototype.setEnabled');
|
||||
this.setEnabled(!disabled);
|
||||
};
|
||||
|
||||
|
||||
34
core/utils/deprecation.js
Normal file
34
core/utils/deprecation.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Helper function for warning developers about deprecations.
|
||||
* This method is not specific to Blockly.
|
||||
* @author fenichel@google.com (Rachel Fenichel);
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.utils.deprecation');
|
||||
|
||||
/**
|
||||
* Warn developers that a function is deprecated.
|
||||
* @param {string} functionName The name of the function.
|
||||
* @param {string} deprecationDate The date when the function was deprecated.
|
||||
* Prefer 'month yyyy' or 'quarter yyyy' format.
|
||||
* @param {string} deletionDate The date when the function will be deleted, in
|
||||
* the same format as the deprecation date.
|
||||
* @param {?string} opt_use The name of a function to use instead, if any.
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.deprecation.warn = function(
|
||||
functionName, deprecationDate, deletionDate, opt_use) {
|
||||
var msg = functionName + ' was deprecated on ' + deprecationDate +
|
||||
' and will be deleted on ' + deletionDate + '.';
|
||||
if (opt_use) {
|
||||
msg += '\nUse ' + opt_use + ' instead.';
|
||||
}
|
||||
console.warn(msg);
|
||||
};
|
||||
Reference in New Issue
Block a user