From 9528b7385b0178d7458737b0de5387d7b6853fab Mon Sep 17 00:00:00 2001 From: Florian Dreier Date: Mon, 13 Apr 2020 19:43:09 +0200 Subject: [PATCH] Some more deprecations --- closure/goog/array/array.js | 4 ++++ closure/goog/base.js | 8 ++++++++ closure/goog/dom/dom.js | 3 +++ 3 files changed, 15 insertions(+) diff --git a/closure/goog/array/array.js b/closure/goog/array/array.js index 918e211720..f98c2e43a0 100644 --- a/closure/goog/array/array.js +++ b/closure/goog/array/array.js @@ -365,6 +365,7 @@ goog.array.count = function(arr, f, opt_obj) { * @return {T|null} The first array element that passes the test, or null if no * element is found. * @template T,S + * @deprecated Use arr.find(f) instead */ goog.array.find = function(arr, f, opt_obj) { var i = goog.array.findIndex(arr, f, opt_obj); @@ -385,6 +386,7 @@ goog.array.find = function(arr, f, opt_obj) { * @return {number} The index of the first array element that passes the test, * or -1 if no element is found. * @template T,S + * @deprecated Use arr.findIndex(f) instead */ goog.array.findIndex = function(arr, f, opt_obj) { var l = arr.length; // must be fixed during loop... see docs @@ -450,6 +452,7 @@ goog.array.findIndexRight = function(arr, f, opt_obj) { * element. * @param {*} obj The object for which to test. * @return {boolean} true if obj is present. + * @deprecated Use arr.includes(obj) instead */ goog.array.contains = function(arr, obj) { return goog.array.indexOf(arr, obj) >= 0; @@ -993,6 +996,7 @@ goog.array.binarySearch_ = function( * negative number, zero, or a positive number depending on whether the * first argument is less than, equal to, or greater than the second. * @template T + * @deprecated Use arr.sort(opt_compareFn) instead */ goog.array.sort = function(arr, opt_compareFn) { // TODO(arv): Update type annotation since null is not accepted. diff --git a/closure/goog/base.js b/closure/goog/base.js index aaaa8807ae..c4f32bf719 100644 --- a/closure/goog/base.js +++ b/closure/goog/base.js @@ -680,6 +680,14 @@ goog.isNull = function(val) { * Returns true if the specified value is defined and not null. * @param {?} val Variable to test. * @return {boolean} Whether variable is defined and not null. + * @deprecated Try to avoid having a variable use null and + * undefined at the same time by: + * - Using default parameter values + * - Nullish coalescing operator + * - Optional chaining + * + * If none of the above is appicable use `!= null` to check for + * null and undefined */ goog.isDefAndNotNull = function(val) { // Note that undefined == null. diff --git a/closure/goog/dom/dom.js b/closure/goog/dom/dom.js index 471c0ea3b3..34d65e2556 100644 --- a/closure/goog/dom/dom.js +++ b/closure/goog/dom/dom.js @@ -250,6 +250,7 @@ goog.dom.getElementByTagNameAndClass = function(opt_tag, opt_class, opt_el) { * @param {string} className the name of the class to look for. * @param {(Document|Element)=} opt_el Optional element to look in. * @return {!IArrayLike} The items found with the class name provided. + * @deprecated Use document.querySelectorAll('.classname') or element.querySelectorAll('.classname') instead */ goog.dom.getElementsByClass = function(className, opt_el) { var parent = opt_el || document; @@ -267,6 +268,7 @@ goog.dom.getElementsByClass = function(className, opt_el) { * @param {string} className the name of the class to look for. * @param {Element|Document=} opt_el Optional element to look in. * @return {Element} The first item with the class name provided. + * @deprecated Use document.querySelector('.classname') or element.querySelector('.classname') instead */ goog.dom.getElementByClass = function(className, opt_el) { var parent = opt_el || document; @@ -1270,6 +1272,7 @@ goog.dom.insertChildAt = function(parent, child, index) { * Removes a node from its parent. * @param {Node} node The node to remove. * @return {Node} The node removed if removed; else, null. + * @deprecated Use node.parentNode?.removeChild(node) instead */ goog.dom.removeNode = function(node) { return node && node.parentNode ? node.parentNode.removeChild(node) : null;