From fe79c022c829846294e379b01e3e437a998e2d40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 19:55:38 +0000 Subject: [PATCH 01/23] build(deps): bump follow-redirects from 1.14.7 to 1.14.8 Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.7 to 1.14.8. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.14.7...v1.14.8) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 2eadf31c8..825d536ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4140,9 +4140,9 @@ flush-write-stream@^1.0.0: readable-stream "^2.3.6" follow-redirects@^1.0.0: - version "1.14.7" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685" - integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ== + version "1.14.8" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc" + integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA== for-in@^1.0.2: version "1.0.2" From 14a2f8d07f81372ed54e0dc8be6520145724b59e Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 10 Feb 2022 11:19:01 -0700 Subject: [PATCH 02/23] feat(goog): remove goog.window --- src/os/ui/columnactions/actions/urlcolumnaction.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/os/ui/columnactions/actions/urlcolumnaction.js b/src/os/ui/columnactions/actions/urlcolumnaction.js index 7ff24f374..10d84978a 100644 --- a/src/os/ui/columnactions/actions/urlcolumnaction.js +++ b/src/os/ui/columnactions/actions/urlcolumnaction.js @@ -3,7 +3,6 @@ goog.declareModuleId('os.ui.columnactions.actions.UrlColumnAction'); import AbstractColumnAction from '../abstractcolumnaction.js'; const {buildString} = goog.require('goog.string'); -const {open} = goog.require('goog.window'); /** @@ -33,7 +32,7 @@ export default class UrlColumnAction extends AbstractColumnAction { * @inheritDoc */ execute(value) { - open(this.processValue_(value), {'target': '_blank'}); + window.open(this.processValue_(value), '_blank'); } /** From 20c9ad03067f22ed817b15a115eefa05a42e2380 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 10 Feb 2022 13:11:21 -0700 Subject: [PATCH 03/23] feat(goog): remove goog.ui.ColorPicker --- src/os/color.js | 13 +++++++++++++ src/os/ui/color/colorpalette.js | 7 +++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/os/color.js b/src/os/color.js index dbfaac99f..d5c7a3bec 100644 --- a/src/os/color.js +++ b/src/os/color.js @@ -38,6 +38,19 @@ export const RGBA_REGEX = /rgba\s*\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*\d?(\.\d+) */ export const RGBA_MATCH_REGEX = /\s*rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d?(\.\d+)?)\s*)?\)/i; +export const SIMPLE_COLORS = [ + '#ffffff', '#cccccc', '#c0c0c0', '#999999', '#666666', '#333333', '#000000', + '#ffcccc', '#ff6666', '#ff0000', '#cc0000', '#990000', '#660000', '#330000', + '#ffcc99', '#ff9966', '#ff9900', '#ff6600', '#cc6600', '#993300', '#663300', + '#ffff99', '#ffff66', '#ffcc66', '#ffcc33', '#cc9933', '#996633', '#663333', + '#ffffcc', '#ffff33', '#ffff00', '#ffcc00', '#999900', '#666600', '#333300', + '#99ff99', '#66ff99', '#33ff33', '#33cc00', '#009900', '#006600', '#003300', + '#99ffff', '#33ffff', '#66cccc', '#00cccc', '#339999', '#336666', '#003333', + '#ccffff', '#66ffff', '#33ccff', '#3366ff', '#3333ff', '#000099', '#000066', + '#ccccff', '#9999ff', '#6666cc', '#6633ff', '#6600cc', '#333399', '#330099', + '#ffccff', '#ff99ff', '#cc66cc', '#cc33cc', '#993399', '#663366', '#330033' +]; + /** * @type {Array} */ diff --git a/src/os/ui/color/colorpalette.js b/src/os/ui/color/colorpalette.js index 559b8fb02..409b33792 100644 --- a/src/os/ui/color/colorpalette.js +++ b/src/os/ui/color/colorpalette.js @@ -1,12 +1,11 @@ goog.declareModuleId('os.ui.color.ColorPaletteUI'); -import {toHexString} from '../../color.js'; +import * as Color from '../../color.js'; import {ROOT} from '../../os.js'; import Module from '../module.js'; import ColorPaletteEventType from './colorpaletteeventtype.js'; const {getViewportSize} = goog.require('goog.dom'); -const ColorPicker = goog.require('goog.ui.ColorPicker'); /** @@ -71,7 +70,7 @@ export class Controller { */ this['showReset'] = $scope['showReset'] === 'true'; - var colors = $scope['colors'] || ColorPicker.SIMPLE_GRID_COLORS; + var colors = $scope['colors'] || Color.SIMPLE_COLORS; var columns = $scope['columns'] || 7; var rows = []; for (var i = 0, ii = colors.length; i < ii; i++) { @@ -139,7 +138,7 @@ export class Controller { * @export */ getTitle(color) { - return toHexString(color); + return Color.toHexString(color); } /** From fd0990842710e4125959809808711609dcf18968 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Fri, 11 Feb 2022 10:46:12 -0700 Subject: [PATCH 04/23] feat(goog): remove goog.typeOf --- src/os/config/settings.js | 4 ++-- src/os/data/configdescriptor.js | 2 +- src/os/implements.js | 4 ++-- src/os/mixin/closuremixin.js | 22 +++++++++++--------- src/os/object/object.js | 36 +++++++++++++++++---------------- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/os/config/settings.js b/src/os/config/settings.js index 1af637ac9..5a7db1b13 100644 --- a/src/os/config/settings.js +++ b/src/os/config/settings.js @@ -750,7 +750,7 @@ export default class Settings extends EventTarget { var namespacedKeys = osConfigNamespace.getPrefixedKeys(keys); osObject.deleteValue(this.actualConfig_[ConfigType.PREFERENCE], namespacedKeys); - if (goog.typeOf(oldVal) === 'object') { + if (oldVal !== null && !Array.isArray(oldVal) && typeof oldVal === 'object') { // delete elements of a deeply nested object this.markKeysForDelete_(keys, undefined, oldVal); } else { @@ -812,7 +812,7 @@ export default class Settings extends EventTarget { * @private */ markKeysForDelete_(keys, newVal, oldVal) { - if (goog.typeOf(oldVal) === 'object') { + if (oldVal !== null && !Array.isArray(oldVal) && typeof oldVal === 'object') { var oldObjKeys = Object.keys(osObject.reduce(oldVal)); var newObjKeys = newVal != null ? Object.keys(osObject.reduce(newVal)) : []; var keysAsStr = keys.join('.'); diff --git a/src/os/data/configdescriptor.js b/src/os/data/configdescriptor.js index f43c6b6c6..502b4f482 100644 --- a/src/os/data/configdescriptor.js +++ b/src/os/data/configdescriptor.js @@ -304,7 +304,7 @@ export default class ConfigDescriptor extends LayerSyncDescriptor { for (var key in obj) { var thing = obj[key]; - if (goog.typeOf(thing) !== 'object' || thing.constructor === Object) { + if (thing === null || Array.isArray(thing) || typeof thing !== 'object' || thing.constructor === Object) { base[key] = thing; } } diff --git a/src/os/implements.js b/src/os/implements.js index 63610be8f..0cf0a2481 100644 --- a/src/os/implements.js +++ b/src/os/implements.js @@ -33,11 +33,11 @@ goog.declareModuleId('os.implements'); */ const implementsFn = function(value, interfaceId) { if (value != null) { - var type = goog.typeOf(value); + var type = typeof value; if (type === 'function') { implementsFn.addImplements(/** @type {!Function} */ (value), interfaceId); return true; - } else if (type === 'object') { + } else if (type === 'object' && !Array.isArray(value)) { return implementsFn.getImplements(/** @type {!Object} */ (value), interfaceId); } } diff --git a/src/os/mixin/closuremixin.js b/src/os/mixin/closuremixin.js index 203869cb0..186e5d6b4 100644 --- a/src/os/mixin/closuremixin.js +++ b/src/os/mixin/closuremixin.js @@ -174,18 +174,20 @@ export const init = () => { * @suppress {duplicate} */ googObject.unsafeClone = function(obj) { - var type = goog.typeOf(obj); - if (type == 'object' || type == 'array') { - if (obj.clone) { - return obj.clone(); - } - var clone = type == 'array' ? [] : {}; - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - clone[key] = googObject.unsafeClone(obj[key]); + if (obj !== null) { + var type = typeof obj; + if (type == 'object') { + if (obj.clone) { + return obj.clone(); + } + var clone = Array.isArray(obj) ? [] : {}; + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + clone[key] = googObject.unsafeClone(obj[key]); + } } + return clone; } - return clone; } return obj; diff --git a/src/os/object/object.js b/src/os/object/object.js index 9dc0757b5..ae77ffd18 100644 --- a/src/os/object/object.js +++ b/src/os/object/object.js @@ -103,13 +103,13 @@ export const merge = function(from, to, opt_overwrite, opt_nullOverwrite) { * Determines if the provided value is a primitive. * * @param {?} value The value to check. - * @param {string=} opt_type The type from `goog.typeOf`, to avoid multiple calls. + * @param {string=} opt_type The type, to avoid multiple calls. * @return {boolean} Whether or not the value is a primitive. */ export const isPrimitive = function(value, opt_type) { if (value) { - var type = opt_type || goog.typeOf(value); - if (type == 'object') { + var type = opt_type || typeof value; + if (type == 'object' && !Array.isArray(value)) { // if an object has multiple prototypes in its chain, it extends Object and will be considered a primitive. the // first prototype should never be null here, so that test is primarily a sanity check. var proto = Object.getPrototypeOf(value); @@ -199,7 +199,7 @@ export const expand = function(obj, opt_delim) { * @param {!Array|!string} keys */ export const deleteValue = function(obj, keys) { - if (goog.typeOf(keys) === 'string') { + if (typeof keys === 'string') { keys = keys.split('.'); } @@ -207,7 +207,7 @@ export const deleteValue = function(obj, keys) { var lastKey = keys[keys.length - 1]; var oneLessKeys = keys.slice(0, keys.length - 1); var oneLessObject = getValueByKeys(obj, oneLessKeys); - if (goog.typeOf(oneLessObject) == 'object') { + if (oneLessObject !== null && typeof oneLessObject == 'object' && !Array.isArray(oneLessObject)) { delete oneLessObject[lastKey]; if (getCount(/** @type {Object} */ (oneLessObject)) === 0) { // no more keys, delete parents @@ -338,20 +338,22 @@ export const getCompareFieldValue = function(field, o) { * @template T */ export const unsafeClone = function(obj) { - var type = goog.typeOf(obj); - if (type == 'object' || type == 'array') { - if (obj.clone) { - return obj.clone(); - } - var clone = type == 'array' ? [] : {}; - for (var key in obj) { - // make sure it's a property on the object and not the prototype. this protects against adding polyfills to the - // new object as a property. - if (obj.hasOwnProperty(key)) { - clone[key] = unsafeClone(obj[key]); + if (obj !== null) { + var type = typeof obj; + if (type == 'object') { + if (obj.clone) { + return obj.clone(); + } + var clone = Array.isArray(obj) ? [] : {}; + for (var key in obj) { + // make sure it's a property on the object and not the prototype. this protects against adding polyfills to the + // new object as a property. + if (obj.hasOwnProperty(key)) { + clone[key] = unsafeClone(obj[key]); + } } + return clone; } - return clone; } return obj; From 7847add306aa256dd952c569a8427f8d5d98a705 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Fri, 11 Feb 2022 10:56:56 -0700 Subject: [PATCH 05/23] feat(goog): remove goog.array.every --- src/os/config/settings.js | 4 ++-- src/os/config/storage/baselocalsettingsstorage.js | 4 ++-- src/plugin/capture/capture.js | 3 +-- src/plugin/file/kml/kmlnodelayerui.js | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/os/config/settings.js b/src/os/config/settings.js index 5a7db1b13..62507479a 100644 --- a/src/os/config/settings.js +++ b/src/os/config/settings.js @@ -552,8 +552,8 @@ export default class Settings extends EventTarget { * @private */ onClearedOthers_(deferredListResults) { - var success = googArray.every(deferredListResults, function(deferredListResult) { - return deferredListResult[0]; + var success = deferredListResults.every((result) => { + return result[0]; }, this); if (!success) { diff --git a/src/os/config/storage/baselocalsettingsstorage.js b/src/os/config/storage/baselocalsettingsstorage.js index 3cea4c27f..b080f09c7 100644 --- a/src/os/config/storage/baselocalsettingsstorage.js +++ b/src/os/config/storage/baselocalsettingsstorage.js @@ -168,8 +168,8 @@ export default class BaseLocalSettingsStorage { * @private */ onSet_(deferredListResults) { - var success = goog.array.every(deferredListResults, function(deferredListResult) { - return deferredListResult[0]; + var success = deferredListResults.every((result) => { + return result[0]; }); if (!success) { diff --git a/src/plugin/capture/capture.js b/src/plugin/capture/capture.js index d6ee8f019..882344fb4 100644 --- a/src/plugin/capture/capture.js +++ b/src/plugin/capture/capture.js @@ -4,7 +4,6 @@ import MapContainer from '../../os/mapcontainer.js'; import TimelineController from '../../os/time/timelinecontroller.js'; const Timer = goog.require('goog.Timer'); -const googArray = goog.require('goog.array'); const {default: ILayer} = goog.requireType('os.layer.ILayer'); @@ -21,7 +20,7 @@ export const WAIT_TIME = 100; */ export const onReady = function(callback) { // Check if we are ready to take picture - var ready = googArray.every(MapContainer.getInstance().getLayers(), function(layer) { + var ready = MapContainer.getInstance().getLayers().every((layer) => { layer = /** @type {ILayer} */ (layer); return !layer.isLoading(); }); diff --git a/src/plugin/file/kml/kmlnodelayerui.js b/src/plugin/file/kml/kmlnodelayerui.js index 1028391a3..fd3c475b7 100644 --- a/src/plugin/file/kml/kmlnodelayerui.js +++ b/src/plugin/file/kml/kmlnodelayerui.js @@ -939,7 +939,7 @@ export class Controller extends VectorLayerUICtrl { var refreshInterval; // only show refresh options if all sources support it - this['showRefresh'] = googArray.every(items, function(item) { + this['showRefresh'] = items.every((item) => { var source = item.getSource(); if (source && (source instanceof VectorSource || source instanceof UrlTile && source.isRefreshEnabled())) { From 7a040d17935d123540b992f18996db4f868409c1 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Fri, 11 Feb 2022 12:17:35 -0700 Subject: [PATCH 06/23] feat(goog): remove goog.array.forEachRight --- src/os/im/action/importactionmanager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/im/action/importactionmanager.js b/src/os/im/action/importactionmanager.js index f35477856..7513b3df5 100644 --- a/src/os/im/action/importactionmanager.js +++ b/src/os/im/action/importactionmanager.js @@ -514,7 +514,7 @@ export default class ImportActionManager extends EventTarget { this.defaultsLoaded[id] = osImActionDefault.load(id, defaultActions[filterKey]).then((entries) => { if (entries && entries.length) { // add all of the default entries from the right, we are inserting them from the top, so this maintains order - goog.array.forEachRight(entries, function(entry) { + entries.slice().reverse().forEach(function(entry) { // add the entry to the manager but skip apply to defer the refresh event this.addActionEntry(entry, 0, undefined, true); }, this); From 1b15437b88549e9c51ae2f8a62f62d5cf79b355e Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Tue, 15 Feb 2022 12:19:42 -0700 Subject: [PATCH 07/23] feat(goog): remove goog.array.equals --- src/os/arraybuf.js | 6 ++-- src/os/color.js | 6 +++- src/os/file/mime/text.js | 3 +- src/os/ui/search/searchbox.js | 13 ++++--- src/os/ui/timeline/brush.js | 6 ++-- test/os/array/array.test.js | 10 +++--- test/os/color.test.js | 16 ++++----- test/os/geo/geo.test.js | 36 +++++++++++++------ test/os/mixin/closuremixin.test.js | 19 ++++++---- test/os/source/vectorsource.test.js | 7 ++-- .../ui/server/abstractloadingserver.test.js | 6 ++-- 11 files changed, 77 insertions(+), 51 deletions(-) diff --git a/src/os/arraybuf.js b/src/os/arraybuf.js index f4ea03e58..a09ef76ed 100644 --- a/src/os/arraybuf.js +++ b/src/os/arraybuf.js @@ -36,8 +36,9 @@ export const MagicNumber = { * @deprecated Please use Boolean(os.file.mime.text.getText()) instead */ export const isText = function(ab) { + const arr = new Uint8Array(ab.slice(0, 3)); // If UTF-8 Byte Order Mark exists - if (goog.array.equals(new Uint8Array(ab.slice(0, 3)), BYTE_ORDER_MARKER)) { + if (arr.length === BYTE_ORDER_MARKER.length && BYTE_ORDER_MARKER.every((el, i) => el === arr[i])) { // just assume it is text return true; } @@ -108,8 +109,9 @@ export const isTextCharacter = function(b) { */ export const toString = function(ab) { let s = ''; + const arr = new Uint8Array(ab.slice(0, 3)); // strip the BOM if the content has one - if (goog.array.equals(new Uint8Array(ab.slice(0, 3)), BYTE_ORDER_MARKER)) { + if (arr.length === BYTE_ORDER_MARKER.length && BYTE_ORDER_MARKER.every((el, i) => el === arr[i])) { ab = ab.slice(3); } diff --git a/src/os/color.js b/src/os/color.js index d5c7a3bec..7aa4cd5ab 100644 --- a/src/os/color.js +++ b/src/os/color.js @@ -613,7 +613,11 @@ export const equals = function(color1, color2) { color2 = toRgbArray(color2); } - return goog.array.equals(color1, color2); + if (color1 && color2 && color1.length === color2.length && color1.every((el, i) => el === color2[i])) { + return true; + } + + return false; }; /** diff --git a/src/os/file/mime/text.js b/src/os/file/mime/text.js index 3efcbb41f..29c4460c7 100644 --- a/src/os/file/mime/text.js +++ b/src/os/file/mime/text.js @@ -3,7 +3,6 @@ goog.declareModuleId('os.file.mime.text'); import * as mime from '../mime.js'; const Promise = goog.require('goog.Promise'); -const googArray = goog.require('goog.array'); const log = goog.require('goog.log'); const Logger = goog.requireType('goog.log.Logger'); @@ -65,7 +64,7 @@ export const getText = function(buffer, opt_file) { var boms = BOMS_; for (var i = 0, n = boms.length; i < n; i++) { var bom = boms[i]; - if (arr.length >= bom.length && googArray.equals(arr.slice(0, bom.length), bom)) { + if (arr.length >= bom.length && arr.slice(0, bom.length).every((el, i) => el === bom[i])) { buffer = buffer.slice(bom.length); break; } diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index 67254064a..e10ac2e90 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -737,7 +737,7 @@ export class Controller { const ids = recent.ids; if (ids.length > 0) { const allIds = this.searchManager.getRegisteredSearches().map(osSearch.getSearchId).sort(); - if (googArray.equals(ids, allIds)) { + if (ids.length === allIds.length && ids.every((el, i) => el === allIds[i])) { // ids are an exact match (assumes both lists are sorted) text = '(All Search Types)'; } else if (ids.length == 1) { @@ -771,7 +771,7 @@ export class Controller { const ids = recent.ids; if (ids.length > 0) { const allIds = this.searchManager.getRegisteredSearches().map(osSearch.getSearchId).sort(); - if (googArray.equals(ids, allIds)) { + if (ids.length === allIds.length && ids.every((el, i) => el === allIds[i])) { // ids are an exact match (assumes both lists are sorted) text = 'Search all types for "' + recent.term + '".'; } else if (ids.length == 1) { @@ -910,8 +910,13 @@ export class Controller { newEnabledIds[TriState.ON].push(osSearch.getSearchId(search)); } }); - if (!googArray.equals(newEnabledIds[TriState.ON], enabledIds[TriState.ON]) || - !googArray.equals(newEnabledIds[TriState.BOTH], enabledIds[TriState.BOTH])) { + // Check if arrays are equal for new/enabled ids with ON state + var sameOn = newEnabledIds[TriState.ON].length === enabledIds[TriState.ON] && + newEnabledIds[TriState.ON].every((el, i) => el === enabledIds[TriState.ON][i]); + // Check if arrays are equal for new/enabled ids with BOTH state + var sameBoth = newEnabledIds[TriState.BOTH].length === enabledIds[TriState.BOTH] && + newEnabledIds[TriState.BOTH].every((el, i) => el === enabledIds[TriState.BOTH][i]); + if (!sameOn || !sameBoth) { this.search(); } } diff --git a/src/os/ui/timeline/brush.js b/src/os/ui/timeline/brush.js index a36a1848c..3c1f11c99 100644 --- a/src/os/ui/timeline/brush.js +++ b/src/os/ui/timeline/brush.js @@ -9,7 +9,6 @@ import DragPanEvent from './dragpanevent.js'; import DragPanEventType from './dragpaneventtype.js'; import * as timeline from './timeline.js'; -const googArray = goog.require('goog.array'); const Throttle = goog.require('goog.async.Throttle'); const googEvents = goog.require('goog.events'); const BrowserEvent = goog.require('goog.events.BrowserEvent'); @@ -511,7 +510,10 @@ export default class Brush extends BaseItem { */ fireChangeEvent_() { var newExtent = this.snap_(this.getExtent()); - if (!googArray.equals(newExtent, this.oldExtent_)) { + var sameExtent = newExtent && this.oldExtent_ && + newExtent.length === this.oldExtent_.length && + this.oldExtent_.every((el, i) => el === newExtent[i]); + if (!sameExtent) { this.dispatchEvent(new PropertyChangeEvent('extent', newExtent, this.oldExtent_)); this.oldExtent_ = newExtent; } diff --git a/test/os/array/array.test.js b/test/os/array/array.test.js index 2069cd589..2a3ad35d9 100644 --- a/test/os/array/array.test.js +++ b/test/os/array/array.test.js @@ -1,9 +1,7 @@ -goog.require('goog.array'); goog.require('os.array'); describe('os.array', function() { - const googArray = goog.module.get('goog.array'); const osArray = goog.module.get('os.array'); it('should return indexes for a binary insert', function() { @@ -143,16 +141,16 @@ describe('os.array', function() { var arr = [a, b]; var sorted = arr.sort(goog.partial(osArray.sortByField, 'num')); - expect(googArray.equals(sorted, [a, b])).toBeTruthy(); + expect(sorted.length === [a, b].length && sorted.every((el, i) => el === [a, b][i])).toBeTruthy(); sorted = arr.sort(goog.partial(osArray.sortByFieldDesc, 'num')); - expect(googArray.equals(sorted, [b, a])).toBeTruthy(); + expect(sorted.length === [b, a].length && sorted.every((el, i) => el === [b, a][i])).toBeTruthy(); sorted = arr.sort(goog.partial(osArray.sortByField, 'str')); - expect(googArray.equals(sorted, [a, b])).toBeTruthy(); + expect(sorted.length === [a, b].length && sorted.every((el, i) => el === [a, b][i])).toBeTruthy(); sorted = arr.sort(goog.partial(osArray.sortByFieldDesc, 'str')); - expect(googArray.equals(sorted, [b, a])).toBeTruthy(); + expect(sorted.length === [b, a].length && sorted.every((el, i) => el === [b, a][i])).toBeTruthy(); }); describe('os.array.join', function() { diff --git a/test/os/color.test.js b/test/os/color.test.js index 57f4937db..fcb511e88 100644 --- a/test/os/color.test.js +++ b/test/os/color.test.js @@ -1,10 +1,8 @@ -goog.require('goog.array'); goog.require('goog.object'); goog.require('os.color'); describe('os.color', function() { - const googArray = goog.module.get('goog.array'); const osColor = goog.module.get('os.color'); it('should detect color strings properly', function() { @@ -75,15 +73,15 @@ describe('os.color', function() { expect(osColor.toHexString([255, 0, 255, 1])).toBe('#ff00ff'); expect(osColor.toHexString('0x00ff00')).toBe('#00ff00'); - expect(googArray.equals(osColor.toRgbArray('rgba(255,136,68,0.1)'), [255, 136, 68, 0.1])).toBeTruthy(); - expect(googArray.equals(osColor.toRgbArray(' AB C Def'), [171, 205, 239, 1])).toBeTruthy(); - expect(googArray.equals(osColor.toRgbArray(' rgb(50, 150, 200)'), [50, 150, 200, 1])).toBeTruthy(); - expect(googArray.equals(osColor.toRgbArray(' rgb(50, 150, 200, 0.5)'), [50, 150, 200, 0.5])).toBeTruthy(); - expect(googArray.equals(osColor.toRgbArray([255, 0, 255, 1]), [255, 0, 255, 1])).toBeTruthy(); + expect(osColor.equals(osColor.toRgbArray('rgba(255,136,68,0.1)'), [255, 136, 68, 0.1])).toBeTruthy(); + expect(osColor.equals(osColor.toRgbArray(' AB C Def'), [171, 205, 239, 1])).toBeTruthy(); + expect(osColor.equals(osColor.toRgbArray(' rgb(50, 150, 200)'), [50, 150, 200, 1])).toBeTruthy(); + expect(osColor.equals(osColor.toRgbArray(' rgb(50, 150, 200, 0.5)'), [50, 150, 200, 0.5])).toBeTruthy(); + expect(osColor.equals(osColor.toRgbArray([255, 0, 255, 1]), [255, 0, 255, 1])).toBeTruthy(); // 0x hex strings can have lower or upper case "x" - expect(googArray.equals(osColor.toRgbArray('0x00ff00'), [0, 255, 0, 1])).toBeTruthy(); - expect(googArray.equals(osColor.toRgbArray('0X00ff00'), [0, 255, 0, 1])).toBeTruthy(); + expect(osColor.equals(osColor.toRgbArray('0x00ff00'), [0, 255, 0, 1])).toBeTruthy(); + expect(osColor.equals(osColor.toRgbArray('0X00ff00'), [0, 255, 0, 1])).toBeTruthy(); }); it('should pad hex colors', function() { diff --git a/test/os/geo/geo.test.js b/test/os/geo/geo.test.js index 2657b3b9d..dc3e78502 100644 --- a/test/os/geo/geo.test.js +++ b/test/os/geo/geo.test.js @@ -1,4 +1,3 @@ -goog.require('goog.array'); goog.require('ol.Feature'); goog.require('ol.geom.GeometryCollection'); goog.require('ol.geom.LineString'); @@ -12,7 +11,6 @@ goog.require('os.osasm.wait'); goog.require('os.query'); describe('os.geo', function() { - const googArray = goog.module.get('goog.array'); const Feature = goog.module.get('ol.Feature'); const GeometryCollection = goog.module.get('ol.geom.GeometryCollection'); const LineString = goog.module.get('ol.geom.LineString'); @@ -983,17 +981,21 @@ describe('os.geo', function() { // adjusts the last coordinate to cross correctly in 2D, doesn't duplicate the last coordinate var result = geo.splitOnDateLine(geometry); expect(result instanceof LineString).toBe(true); - expect(googArray.equals(result.getFlatCoordinates(), [175, 0, 185, 0])).toBe(true); + var flatCoordinates = result.getFlatCoordinates(); + var testArr = [175, 0, 185, 0]; + expect(flatCoordinates && flatCoordinates.length === testArr.length && + flatCoordinates.every((el, i) => el === testArr[i])).toBe(true); // splits with repeated normalized coordinate to prevent gaps coordinates = [[170, 0], [175, 0], [-175, 0], [-170, 0]]; geometry = new LineString(coordinates); result = geo.splitOnDateLine(geometry); + flatCoordinates = result.getFlatCoordinates(); + testArr = [170, 0, 175, 0, 185, 0, -175, 0, -170, 0]; expect(result instanceof MultiLineString).toBe(true); - expect(googArray.equals( - result.getFlatCoordinates(), - [170, 0, 175, 0, 185, 0, -175, 0, -170, 0])).toBe(true); + expect(flatCoordinates && flatCoordinates.length === testArr.length && + flatCoordinates.every((el, i) => el === testArr[i])).toBe(true); expect(result.ends_[0]).toBe(6); // splits correctly when coordinates at +/- 180 are present @@ -1001,10 +1003,11 @@ describe('os.geo', function() { geometry = new LineString(coordinates); result = geo.splitOnDateLine(geometry); + flatCoordinates = result.getFlatCoordinates(); + testArr = [170, 0, 175, 0, 180, 0, 185, 0, -175, 0, -170, 0]; expect(result instanceof MultiLineString).toBe(true); - expect(googArray.equals( - result.getFlatCoordinates(), - [170, 0, 175, 0, 180, 0, 185, 0, -175, 0, -170, 0])).toBe(true); + expect(flatCoordinates && flatCoordinates.length === testArr.length && + flatCoordinates.every((el, i) => el === testArr[i])).toBe(true); expect(result.ends_[0]).toBe(8); }); @@ -1014,9 +1017,14 @@ describe('os.geo', function() { var split = geo.splitOnDateLine(geometry); var merged = geo.mergeLineGeometry(split); + var geomFlatCoordinates = geometry.getFlatCoordinates(); + var mergedFlatCoordinates = merged.getFlatCoordinates(); + // coordinates are the same as the original expect(merged instanceof LineString).toBe(true); - expect(googArray.equals(geometry.getFlatCoordinates(), merged.getFlatCoordinates())).toBe(true); + expect(geomFlatCoordinates && mergedFlatCoordinates && + geomFlatCoordinates.length === mergedFlatCoordinates.length && + geomFlatCoordinates.every((el, i) => el === mergedFlatCoordinates[i])).toBe(true); // merges correctly when coordinates at +/- 180 are present coordinates = [[170, 0], [175, 0], [180, 0], [-175, 0], [-170, 0]]; @@ -1024,8 +1032,14 @@ describe('os.geo', function() { split = geo.splitOnDateLine(geometry); merged = geo.mergeLineGeometry(split); + geomFlatCoordinates = geometry.getFlatCoordinates(); + mergedFlatCoordinates = merged.getFlatCoordinates(); + + expect(merged instanceof LineString).toBe(true); - expect(googArray.equals(geometry.getFlatCoordinates(), merged.getFlatCoordinates())).toBe(true); + expect(geomFlatCoordinates && mergedFlatCoordinates && + geomFlatCoordinates.length === mergedFlatCoordinates.length && + geomFlatCoordinates.every((el, i) => el === mergedFlatCoordinates[i])).toBe(true); }); it('should normalise longitudes greater than 180.0', function() { diff --git a/test/os/mixin/closuremixin.test.js b/test/os/mixin/closuremixin.test.js index 1cf40a5ad..280718657 100644 --- a/test/os/mixin/closuremixin.test.js +++ b/test/os/mixin/closuremixin.test.js @@ -9,7 +9,8 @@ describe('os.mixin.closure', function() { expect(arr.hasOwnProperty('testFn')).toBe(false); expect(goog.object.getCount(arr)).toBe(3); expect(goog.object.getKeys(arr).length).toBe(3); - expect(goog.array.equals(arr, goog.object.getValues(arr))); + expect(arr.length === goog.object.getValues(arr).length && + arr.every((el, i) => el === goog.object.getValues(arr)[i])); goog.object.forEach(arr, function(val, key) { expect(key).not.toBe('testFn'); }); @@ -21,21 +22,27 @@ describe('os.mixin.closure', function() { expect(goog.object.getCount(obj)).toBe(3); expect(goog.object.getKeys(obj).length).toBe(3); expect(goog.object.getValues(obj).length).toBe(3); - expect(goog.array.equals(goog.object.getValues(obj), values)); + expect(values.length === goog.object.getValues(obj).length && + values.every((el, i) => el === goog.object.getValues(obj)[i])); goog.object.forEach(obj, function(val, key) { expect(key).not.toBe('testFn'); }); }; var compareArrays = function(arr1, arr2) { - expect(goog.array.equals(arr1, arr2)); - expect(goog.array.equals(arr1, goog.object.getValues(arr2))); + expect(arr1.length === arr2.length && arr1.every((el, i) => el === arr2[i])); + expect(arr1.length === goog.object.getValues(arr2).length && + arr1.every((el, i) => el === goog.object.getValues(arr2)[i])); }; var compareObjects = function(obj1, obj2) { expect(goog.object.equals(obj1, obj2)); - expect(goog.array.equals(goog.object.getKeys(obj1), goog.object.getKeys(obj2))).toBe(true); - expect(goog.array.equals(goog.object.getValues(obj1), goog.object.getValues(obj2))).toBe(true); + var obj1Keys = goog.object.getKeys(obj1); + var obj2Keys = goog.object.getKeys(obj2); + expect(obj1Keys.length === obj2Keys.length && obj1Keys.every((el, i) => el === obj2Keys[i])).toBe(true); + var obj1Values = goog.object.getValues(obj1); + var obj2Values = goog.object.getValues(obj2); + expect(obj1Values.length === obj2Values.length && obj1Values.every((el, i) => el === obj2Values[i])).toBe(true); }; it('works with array polyfills', function() { diff --git a/test/os/source/vectorsource.test.js b/test/os/source/vectorsource.test.js index f84cc57a0..b28c4d2d3 100644 --- a/test/os/source/vectorsource.test.js +++ b/test/os/source/vectorsource.test.js @@ -1,4 +1,3 @@ -goog.require('goog.array'); goog.require('goog.events.EventType'); goog.require('goog.functions'); goog.require('goog.net.EventType'); @@ -32,7 +31,6 @@ goog.require('plugin.file.geojson.GeoJSONParser'); describe('os.source.Vector', function() { - const googArray = goog.module.get('goog.array'); const GoogEventType = goog.module.get('goog.events.EventType'); const functions = goog.module.get('goog.functions'); const googNetEventType = goog.module.get('goog.net.EventType'); @@ -643,8 +641,9 @@ describe('os.source.Vector', function() { expect(source.getColumnsArray()).toBe(source.columns); var copy = source.getColumns(); - expect(copy).not.toBe(source.columns); - expect(googArray.equals(copy, source.columns)).toBe(true); + var sourceColumns = source.columns; + expect(copy).not.toBe(sourceColumns); + expect(copy.length === sourceColumns.length && copy.every((el, i) => el === sourceColumns[i])).toBe(true); }); it('should always add an ID column to the source', function() { diff --git a/test/os/ui/server/abstractloadingserver.test.js b/test/os/ui/server/abstractloadingserver.test.js index c97b37b8a..81b74cf4a 100644 --- a/test/os/ui/server/abstractloadingserver.test.js +++ b/test/os/ui/server/abstractloadingserver.test.js @@ -1,9 +1,7 @@ -goog.require('goog.array'); goog.require('os.ui.server.AbstractLoadingServer'); describe('os.ui.server.AbstractLoadingServer', function() { - const googArray = goog.module.get('goog.array'); const {default: AbstractLoadingServer} = goog.module.get('os.ui.server.AbstractLoadingServer'); var server = new AbstractLoadingServer(); @@ -26,7 +24,7 @@ describe('os.ui.server.AbstractLoadingServer', function() { var alts = server.getAlternateUrls(); expect(alts.length).toBe(3); - expect(googArray.equals(alts, alternateUrls)).toBe(true); + expect(alts && alts.length === alternateUrls.length && alts.every((el, i) => el === alternateUrls[i])).toBe(true); }); it('removes alternate URLs', function() { @@ -47,7 +45,7 @@ describe('os.ui.server.AbstractLoadingServer', function() { var alts = server.getAlternateUrls(); expect(alts.length).toBe(3); - expect(googArray.equals(alts, alternateUrls)).toBe(true); + expect(alts && alts.length === alternateUrls.length && alts.every((el, i) => el === alternateUrls[i])).toBe(true); }); it('rotates through the URL and alternates', function() { From 5641390ab012517a3a4527c4b8faf8098a472c4d Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Wed, 16 Feb 2022 09:48:07 -0700 Subject: [PATCH 08/23] feat(goog): remove goog.array.moveItem --- src/os/ui/column/columnmanager.js | 4 ++-- src/os/ui/im/action/editfilteraction.js | 3 ++- src/os/ui/layer/labelcontrols.js | 4 ++-- src/os/ui/search/searchbox.js | 9 ++++++--- src/os/ui/slick/slickgrid.js | 11 +++++++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/os/ui/column/columnmanager.js b/src/os/ui/column/columnmanager.js index d3cf01a8e..471144a00 100644 --- a/src/os/ui/column/columnmanager.js +++ b/src/os/ui/column/columnmanager.js @@ -8,7 +8,6 @@ import SlickGridEvent from '../slick/slickgridevent.js'; import {close} from '../window.js'; import {directiveTag as columnRowUi} from './columnrow.js'; -const {moveItem} = goog.require('goog.array'); const dispose = goog.require('goog.dispose'); const {getDocument} = goog.require('goog.dom'); const KeyCodes = goog.require('goog.events.KeyCodes'); @@ -311,7 +310,8 @@ export class Controller { var index = findIndex(srcColumns, findByField.bind(this, 'id', columns[i]['id'])); if (index > -1) { var targetIndex = j > index ? j - 1 : j; - moveItem(srcColumns, index, targetIndex); + const columnToMove = srcColumns.splice(index, 1)[0]; + srcColumns.splice(targetIndex, 0, columnToMove); } } } diff --git a/src/os/ui/im/action/editfilteraction.js b/src/os/ui/im/action/editfilteraction.js index 4bc92619d..dba3b7b8f 100644 --- a/src/os/ui/im/action/editfilteraction.js +++ b/src/os/ui/im/action/editfilteraction.js @@ -295,7 +295,8 @@ export default class Controller extends EditFiltersCtrl { // if the index changed, update the label order var stopIndex = ui['item'].index(); if (this.startIndex_ != stopIndex) { - goog.array.moveItem(this['actions'], this.startIndex_, stopIndex); + const actionToMove = this['actions'].splice(this.startIndex_, 1)[0]; + this['actions'].splice(stopIndex, 0, actionToMove); apply(this.scope); } } diff --git a/src/os/ui/layer/labelcontrols.js b/src/os/ui/layer/labelcontrols.js index a52aef43f..92eb67497 100644 --- a/src/os/ui/layer/labelcontrols.js +++ b/src/os/ui/layer/labelcontrols.js @@ -11,7 +11,6 @@ import {apply} from '../ui.js'; import LabelControlsEventType from './labelcontrolseventtype.js'; const Disposable = goog.require('goog.Disposable'); -const {moveItem} = goog.require('goog.array'); const {remove} = goog.require('ol.array'); const {LabelConfig} = goog.requireType('os.style.label'); @@ -274,7 +273,8 @@ export class Controller extends Disposable { // if the index changed, update the label order var stopIndex = ui['item'].index(); if (this.startIndex_ != stopIndex) { - moveItem(this.scope['labels'], this.startIndex_, stopIndex); + const labelToMove = this.scope['labels'].splice(this.startIndex_, 1)[0]; + this.scope['labels'].splice(stopIndex, 0, labelToMove); apply(this.scope); this.onColumnChange(); } diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index e10ac2e90..cc92cd003 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -553,7 +553,8 @@ export class Controller { order.forEach(function(value, index) { const currentIndex = this['providerGroups'].indexOf(value); if (currentIndex > 0) { - googArray.moveItem(this['providerGroups'], currentIndex, index); + const providerToMove = this['providerGroups'].splice(currentIndex, 1)[0]; + this['providerGroups'].splice(index, 0, providerToMove); } }, this); @@ -825,7 +826,8 @@ export class Controller { // move the item to the top of the recent list const recentIndex = googArray.indexOf(this['recentSearches'], recent); if (recentIndex > 0) { - googArray.moveItem(this['recentSearches'], recentIndex, 0); + const searchToMove = this['recentSearches'].splice(recentIndex, 1)[0]; + this['recentSearches'].splice(0, 0, searchToMove); } // save recent searches @@ -960,7 +962,8 @@ export class Controller { if (recentIndex > -1) { // already in the array, so move it to the top - googArray.moveItem(this['recentSearches'], recentIndex, 0); + const searchToMove = this['recentSearches'].splice(recentIndex, 1)[0]; + this['recentSearches'].splice(0, 0, searchToMove); } else { const recent = /** @type {!osx.search.RecentSearch} */ ({ ids: enabledIds, diff --git a/src/os/ui/slick/slickgrid.js b/src/os/ui/slick/slickgrid.js index c11dc9ac1..547c1d72f 100644 --- a/src/os/ui/slick/slickgrid.js +++ b/src/os/ui/slick/slickgrid.js @@ -22,7 +22,7 @@ import SlickGridEvent from './slickgridevent.js'; const Disposable = goog.require('goog.Disposable'); const Timer = goog.require('goog.Timer'); -const {defaultCompare, insert, moveItem} = goog.require('goog.array'); +const {defaultCompare, insert} = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const nextTick = goog.require('goog.async.nextTick'); const dispose = goog.require('goog.dispose'); @@ -837,7 +837,8 @@ export class Controller extends Disposable { var targetIndex = j > index ? j - 1 : j; insert(changed, srcColumns[index]); insert(changed, srcColumns[targetIndex]); - moveItem(srcColumns, index, targetIndex); + const columnToMove = srcColumns.splice(index, 1)[0]; + srcColumns.splice(targetIndex, 0, columnToMove); } } } @@ -934,7 +935,8 @@ export class Controller extends Disposable { var columns = this.getColumnsInternal(); var index = columns.findIndex(findByField.bind(this, 'id', context.column['id'])); if (index > -1) { - moveItem(columns, index, 0); + const columnToMove = columns.splice(index, 1)[0]; + columns.splice(0, 0, columnToMove); this.onUserColumnsChange([columns[index]]); } } @@ -952,7 +954,8 @@ export class Controller extends Disposable { var columns = this.getColumnsInternal(); var index = columns.findIndex(findByField.bind(this, 'id', context.column['id'])); if (index > -1) { - moveItem(columns, index, columns.length - 1); + const columnToMove = columns.splice(index, 1)[0]; + columns.splice(columns.length - 1, 0, columnToMove); this.onUserColumnsChange([columns[index]]); } } From 3d6429f043461c7f95aa7d4fd55e893e8d4bbc07 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Wed, 16 Feb 2022 11:25:02 -0700 Subject: [PATCH 09/23] feat(goog): remove goog.array.insertAt --- src/os/array/array.js | 2 +- src/os/im/action/filteractionentry.js | 2 +- src/os/im/action/importactionmanager.js | 2 +- src/os/ui/actionmenu.js | 8 ++++---- src/os/user/settings/favoritemanager.js | 14 +++++++------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/os/array/array.js b/src/os/array/array.js index c48983019..c0d891ad1 100644 --- a/src/os/array/array.js +++ b/src/os/array/array.js @@ -22,7 +22,7 @@ export const binaryInsert = function(array, value, opt_compareFn) { var index = googArray.binarySearch(array, value, opt_compareFn); if (index < 0) { index = -index - 1; - googArray.insertAt(array, value, index); + array.splice(index, 0, value); return index; } diff --git a/src/os/im/action/filteractionentry.js b/src/os/im/action/filteractionentry.js index 0292484f2..571beddbf 100644 --- a/src/os/im/action/filteractionentry.js +++ b/src/os/im/action/filteractionentry.js @@ -213,7 +213,7 @@ export default class FilterActionEntry extends FilterEntry { if (!hasChild) { // insert at the specified index, or at the end if unspecified var index = opt_index != null ? opt_index : this.children_.length; - goog.array.insertAt(this.children_, child, index); + this.children_.splice(index, 0, child); child.setParent(this); return child; diff --git a/src/os/im/action/importactionmanager.js b/src/os/im/action/importactionmanager.js index 7513b3df5..557d2fac4 100644 --- a/src/os/im/action/importactionmanager.js +++ b/src/os/im/action/importactionmanager.js @@ -322,7 +322,7 @@ export default class ImportActionManager extends EventTarget { entries[index] = entry; } else if (opt_index > -1 && opt_index < entries.length) { // insert at the given index - goog.array.insertAt(entries, entry, opt_index); + entries.splice(opt_index, 0, entry); } else { // append to the end of the array entries.push(entry); diff --git a/src/os/ui/actionmenu.js b/src/os/ui/actionmenu.js index 1990ba830..6ad0c4ada 100644 --- a/src/os/ui/actionmenu.js +++ b/src/os/ui/actionmenu.js @@ -13,7 +13,7 @@ import MenuOptions from './action/menuoptions.js'; import Module from './module.js'; import {apply} from './ui.js'; -const {binaryInsert, insertAt} = goog.require('goog.array'); +const {binaryInsert} = goog.require('goog.array'); const {getViewportSize} = goog.require('goog.dom'); const {listen, unlistenByKey} = goog.require('goog.events'); const GoogEventType = goog.require('goog.events.EventType'); @@ -263,7 +263,7 @@ export class Controller { * {MenuItem} with nested {MenuItemAction} and/or {MenuItemList} entries. * * @param {Object} menuStructure JSON object structure which declares the depth and placement of the menu items - * @param {Array} menuItems The list of menu items to which the converted menuStructure actions are placed. + * @param {!Array} menuItems The list of menu items to which the converted menuStructure actions are placed. * @private * @suppress {deprecated} */ @@ -307,11 +307,11 @@ export class Controller { division = menuOptions && menuOptions.division; if (previousDivision != division) { if (i > 0) { - insertAt(menuItems, new MenuItemSeparator(), i); + menuItems.splice(i, 0, new MenuItemSeparator()); i++; } if (division != null) { - insertAt(menuItems, new MenuItemSeparatorHeader(division.replace(/^[0-9]*:/, '')), i); + menuItems.splice(i, 0, new MenuItemSeparatorHeader(division.replace(/^[0-9]*:/, ''))); i++; } } diff --git a/src/os/user/settings/favoritemanager.js b/src/os/user/settings/favoritemanager.js index 15576a61f..ff777a1d1 100644 --- a/src/os/user/settings/favoritemanager.js +++ b/src/os/user/settings/favoritemanager.js @@ -84,7 +84,7 @@ export default class FavoriteManager extends EventTarget { /** * Return all the favorites * - * @return {Array} + * @return {!Array} */ getFavorites() { var favs = /** @type {Array} */ (Settings.getInstance().get([FavoriteManager.KEY])); @@ -223,7 +223,7 @@ export default class FavoriteManager extends EventTarget { } } else { // store at the root - googArray.insertAt(favs, fav); + favs.unshift(fav); } this.saveToSettings(favs); @@ -440,9 +440,9 @@ export default class FavoriteManager extends EventTarget { /** * Dig through folders to find the favorite. When found remove it and return the complete list with the removal * - * @param {Array} favs + * @param {!Array} favs * @param {string} key - * @return {Array} - array with the favorite removed + * @return {!Array} - array with the favorite removed * @private */ static removeFavoriteInternal_(favs, key) { @@ -554,10 +554,10 @@ export default class FavoriteManager extends EventTarget { /** * Save the favorite to a folder * - * @param {Array} favs + * @param {!Array} favs * @param {FavoriteSetting} favorite * @param {string} folder - the folder key - * @return {Array} - the modified favorite array + * @return {!Array} - the modified favorite array * @private */ static saveFolderInternal_(favs, favorite, folder) { @@ -565,7 +565,7 @@ export default class FavoriteManager extends EventTarget { var fav = favs[i]; // If we found the folder we want to store the favorite. if (fav['key'] == folder) { - googArray.insertAt(fav['children'], favorite); + fav['children'].unshift(favorite); break; } else if (fav['type'] == FavoriteType.FOLDER) { var children = FavoriteManager.saveFolderInternal_(fav['children'], favorite, folder); From 42f970e8c060f183b19d76d38f76de6883f3fe51 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Wed, 16 Feb 2022 13:31:16 -0700 Subject: [PATCH 10/23] feat(goog): remove goog.array.insert --- src/os/config/namespace.js | 4 +++- src/os/config/settings.js | 14 +++++++------- src/os/data/groupby/dategroupby.js | 17 ++++++++++++----- src/os/data/groupby/layerprovidergroupby.js | 5 +++-- src/os/data/groupby/layertypegroupby.js | 9 ++++++--- src/os/data/groupby/layerzordergroupby.js | 6 ++++-- src/os/data/groupby/recentgroupby.js | 7 ++++--- src/os/data/groupby/taglistgroupby.js | 5 ++--- src/os/data/groupby/typegroupby.js | 6 +++--- src/os/events/events.js | 5 +++-- src/os/ui/data/groupby/taggroupby.js | 5 ++--- src/os/ui/filterlayergroupby.js | 4 +++- src/os/ui/im/action/filteraction.js | 4 ++-- src/os/xt/peer.js | 4 +++- test/os/data/typegroupby.mock.js | 5 +++-- test/os/ui/slick/typegroupby.mock.js | 5 +++-- 16 files changed, 63 insertions(+), 42 deletions(-) diff --git a/src/os/config/namespace.js b/src/os/config/namespace.js index f4cb32542..a4e66cf7d 100644 --- a/src/os/config/namespace.js +++ b/src/os/config/namespace.js @@ -83,7 +83,9 @@ export const removeObsoleteKeys = function(obj) { keys.forEach(function(key) { if (googObject.containsKey(reduced, key)) { delete reduced[key]; - googArray.insert(keysToDelete, key); + if (!keysToDelete.includes(key)) { + keysToDelete.push(key); + } } }); return osObject.expand(reduced); diff --git a/src/os/config/settings.js b/src/os/config/settings.js index 62507479a..a09872b74 100644 --- a/src/os/config/settings.js +++ b/src/os/config/settings.js @@ -753,9 +753,9 @@ export default class Settings extends EventTarget { if (oldVal !== null && !Array.isArray(oldVal) && typeof oldVal === 'object') { // delete elements of a deeply nested object this.markKeysForDelete_(keys, undefined, oldVal); - } else { + } else if (!osConfigNamespace.keysToDelete.includes(osConfigNamespace.getPrefixedKey(keys.join('.')))) { // delete the key entirely - googArray.insert(osConfigNamespace.keysToDelete, osConfigNamespace.getPrefixedKey(keys.join('.'))); + osConfigNamespace.keysToDelete.push(osConfigNamespace.getPrefixedKey(keys.join('.'))); } this.dispatchChange_(keys, undefined, oldVal); @@ -780,8 +780,8 @@ export default class Settings extends EventTarget { if (joined == Settings.WRITE_STORAGE_KEY) { this.peer_.send(namespacedKeys[0], {keys: keys, newValue: newVal}); - } else { - googArray.insert(this.toNotifyExternal_, {namespace: namespacedKeys[0], keys: keys}); + } else if (!this.toNotifyExternal_.includes({namespace: namespacedKeys[0], keys: keys})) { + this.toNotifyExternal_.push({namespace: namespacedKeys[0], keys: keys}); } if (this.saveDelay_) { @@ -817,9 +817,9 @@ export default class Settings extends EventTarget { var newObjKeys = newVal != null ? Object.keys(osObject.reduce(newVal)) : []; var keysAsStr = keys.join('.'); oldObjKeys.forEach(function(oldObjKey) { - if (!newObjKeys.includes(oldObjKey)) { - googArray.insert(osConfigNamespace.keysToDelete, osConfigNamespace.getPrefixedKey(keysAsStr + '.' + - oldObjKey)); + if (!newObjKeys.includes(oldObjKey) && + !osConfigNamespace.keysToDelete.includes(osConfigNamespace.getPrefixedKey(keysAsStr + '.' + oldObjKey))) { + osConfigNamespace.keysToDelete.push(osConfigNamespace.getPrefixedKey(keysAsStr + '.' + oldObjKey)); } }); } diff --git a/src/os/data/groupby/dategroupby.js b/src/os/data/groupby/dategroupby.js index 7e86d5bb4..772c472ba 100644 --- a/src/os/data/groupby/dategroupby.js +++ b/src/os/data/groupby/dategroupby.js @@ -5,7 +5,6 @@ import SlickTreeNode from '../../ui/slick/slicktreenode.js'; import DataManager from '../datamanager.js'; import BaseGroupBy from './basegroupby.js'; -const googArray = goog.require('goog.array'); const googString = goog.require('goog.string'); const {default: IDataDescriptor} = goog.requireType('os.data.IDataDescriptor'); @@ -68,23 +67,31 @@ export default class DateGroupBy extends BaseGroupBy { if (!isNaN(max) && max > Number.NEGATIVE_INFINITY) { if (max > this.now_) { - googArray.insert(ids, 'xxReports future activity'); + if (!ids.includes('xxReports future activity')) { + ids.push('xxReports future activity'); + } return ids; } var p = periods; for (var i = 0, n = p.length; i < n; i++) { if ((this.now_ - p[i].offset) <= max) { - googArray.insert(ids, googString.padNumber(i, 2) + p[i].label); + if (!ids.includes(googString.padNumber(i, 2) + p[i].label)) { + ids.push(googString.padNumber(i, 2) + p[i].label); + } return ids; } } - googArray.insert(ids, 'yyNo recent activity'); + if (!ids.includes('yyNo recent activity')) { + ids.push('yyNo recent activity'); + } return ids; } - googArray.insert(ids, 'zzCould not determine activity'); + if (!ids.includes('zzCould not determine activity')) { + ids.push('zzCould not determine activity'); + } return ids; } diff --git a/src/os/data/groupby/layerprovidergroupby.js b/src/os/data/groupby/layerprovidergroupby.js index 9a62f6aaf..b1f6029eb 100644 --- a/src/os/data/groupby/layerprovidergroupby.js +++ b/src/os/data/groupby/layerprovidergroupby.js @@ -3,7 +3,6 @@ goog.declareModuleId('os.data.groupby.LayerProviderGroupBy'); import SlickTreeNode from '../../ui/slick/slicktreenode.js'; import BaseGroupBy from './basegroupby.js'; -const googArray = goog.require('goog.array'); const {default: LayerNode} = goog.requireType('os.data.LayerNode'); @@ -31,7 +30,9 @@ export default class LayerProviderGroupBy extends BaseGroupBy { var layer = /** @type {LayerNode} */ (node).getLayer(); var p = layer.getProvider() || 'Unknown Provider'; - googArray.insert(ids, p); + if (!ids.includes(p)) { + ids.push(p); + } } catch (e) { } diff --git a/src/os/data/groupby/layertypegroupby.js b/src/os/data/groupby/layertypegroupby.js index b5ebe628d..7ea72fb09 100644 --- a/src/os/data/groupby/layertypegroupby.js +++ b/src/os/data/groupby/layertypegroupby.js @@ -6,7 +6,6 @@ import {getMapContainer} from '../../map/mapinstance.js'; import SlickTreeNode from '../../ui/slick/slicktreenode.js'; import BaseGroupBy from './basegroupby.js'; -const googArray = goog.require('goog.array'); const googString = goog.require('goog.string'); const {default: LayerNode} = goog.requireType('os.data.LayerNode'); @@ -36,6 +35,7 @@ export default class LayerTypeGroupBy extends BaseGroupBy { var layer = /** @type {LayerNode} */ (node).getLayer(); var layers = getMapContainer().getMap().getLayers().getArray(); var p = layer.getOSType() || '00Unknown Type'; + var id; for (var i = 0, n = layers.length; i < n; i++) { if (layers[i] instanceof Group) { @@ -43,12 +43,15 @@ export default class LayerTypeGroupBy extends BaseGroupBy { if (group.getLayers().getArray().indexOf(/** @type {ol.layer.Base} */ (layer)) > -1 || (p == LayerType.GROUPS && group.getOSType() == LayerType.FEATURES)) { - var id = googString.padNumber(99 - i, 2) + p; + id = googString.padNumber(99 - i, 2) + p; } } } - googArray.insert(ids, id || p); + const insertId = id || p; + if (!ids.includes(insertId)) { + ids.push(insertId); + } } catch (e) { } diff --git a/src/os/data/groupby/layerzordergroupby.js b/src/os/data/groupby/layerzordergroupby.js index 291e43ddf..1f810e3c3 100644 --- a/src/os/data/groupby/layerzordergroupby.js +++ b/src/os/data/groupby/layerzordergroupby.js @@ -5,7 +5,6 @@ import {getMapContainer} from '../../map/mapinstance.js'; import SlickTreeNode from '../../ui/slick/slicktreenode.js'; import BaseGroupBy from './basegroupby.js'; -const googArray = goog.require('goog.array'); const googString = goog.require('goog.string'); const {default: LayerNode} = goog.requireType('os.data.LayerNode'); @@ -39,7 +38,10 @@ export default class LayerZOrderGroupBy extends BaseGroupBy { var group = /** @type {Group} */ (layers[i]); if (group.getLayers().getArray().indexOf(/** @type {ol.layer.Base} */ (layer)) > -1) { - googArray.insert(ids, googString.padNumber(99 - i, 2) + group.getOSType()); + const insertId = googString.padNumber(99 - i, 2) + group.getOSType(); + if (!ids.includes(insertId)) { + ids.push(insertId); + } break; } } diff --git a/src/os/data/groupby/recentgroupby.js b/src/os/data/groupby/recentgroupby.js index dc027713d..1d9c48385 100644 --- a/src/os/data/groupby/recentgroupby.js +++ b/src/os/data/groupby/recentgroupby.js @@ -4,8 +4,6 @@ import DescriptorNode from '../../ui/data/descriptornode.js'; import SlickTreeNode from '../../ui/slick/slicktreenode.js'; import BaseGroupBy from './basegroupby.js'; -const googArray = goog.require('goog.array'); - const {default: IDataDescriptor} = goog.requireType('os.data.IDataDescriptor'); @@ -83,7 +81,10 @@ export default class RecentGroupBy extends BaseGroupBy { for (var i = 0, n = this.times_.length; i < n; i++) { var t = d.getLastActive(); if (!isNaN(t) && t >= this.times_[i].time) { - googArray.insert(ids, i + this.times_[i].label); + const insertId = i + this.times_[i].label; + if (!ids.includes(insertId)) { + ids.push(insertId); + } return ids; } } diff --git a/src/os/data/groupby/taglistgroupby.js b/src/os/data/groupby/taglistgroupby.js index 7450469ba..953004155 100644 --- a/src/os/data/groupby/taglistgroupby.js +++ b/src/os/data/groupby/taglistgroupby.js @@ -3,7 +3,6 @@ goog.declareModuleId('os.data.groupby.TagListGroupBy'); import Settings from '../../config/settings.js'; import TagGroupBy from '../../ui/data/groupby/taggroupby.js'; -const googArray = goog.require('goog.array'); const log = goog.require('goog.log'); const {default: ISearchable} = goog.requireType('os.data.ISearchable'); @@ -66,8 +65,8 @@ export default class TagListGroupBy extends TagGroupBy { for (var i = 0, n = tags.length; i < n; i++) { if (tags[i]) { var t = tags[i].toUpperCase(); - if (this.list_.indexOf(t) > -1) { - googArray.insert(ids, 'a' + t); + if (this.list_.indexOf(t) > -1 && !ids.includes('a' + t)) { + ids.push('a' + t); } } else { invalid = true; diff --git a/src/os/data/groupby/typegroupby.js b/src/os/data/groupby/typegroupby.js index 98ae79b95..0f3826f0b 100644 --- a/src/os/data/groupby/typegroupby.js +++ b/src/os/data/groupby/typegroupby.js @@ -4,8 +4,6 @@ import DescriptorNode from '../../ui/data/descriptornode.js'; import SlickTreeNode from '../../ui/slick/slicktreenode.js'; import BaseGroupBy from './basegroupby.js'; -const googArray = goog.require('goog.array'); - /** * Groups nodes by type @@ -53,7 +51,9 @@ export default class TypeGroupBy extends BaseGroupBy { val = 'No Type'; } - googArray.insert(ids, val); + if (!ids.includes(val)) { + ids.push(val); + } return ids; } diff --git a/src/os/events/events.js b/src/os/events/events.js index dbad15d10..775878c41 100644 --- a/src/os/events/events.js +++ b/src/os/events/events.js @@ -2,7 +2,6 @@ goog.declareModuleId('os.events'); import SelectionType from './selectiontype.js'; -const googArray = goog.require('goog.array'); const GoogEventType = goog.require('goog.events.EventType'); const googObject = goog.require('goog.object'); @@ -70,7 +69,9 @@ const exemptionFunctions = []; * @param {function((Document|Element), string):boolean} checker The exemption check function */ export const addExemption = function(checker) { - googArray.insert(exemptionFunctions, checker); + if (!exemptionFunctions.includes(checker)) { + exemptionFunctions.push(checker); + } }; /** diff --git a/src/os/ui/data/groupby/taggroupby.js b/src/os/ui/data/groupby/taggroupby.js index fe2036210..bacda2133 100644 --- a/src/os/ui/data/groupby/taggroupby.js +++ b/src/os/ui/data/groupby/taggroupby.js @@ -3,7 +3,6 @@ goog.declareModuleId('os.ui.data.groupby.TagGroupBy'); import BaseGroupBy from '../../../data/groupby/basegroupby.js'; import SlickTreeNode from '../../slick/slicktreenode.js'; -const googArray = goog.require('goog.array'); const log = goog.require('goog.log'); const {default: ISearchable} = goog.requireType('os.data.ISearchable'); @@ -51,8 +50,8 @@ export default class TagGroupBy extends BaseGroupBy { if (tags) { var invalid = false; for (var i = 0, n = tags.length; i < n; i++) { - if (tags[i]) { - googArray.insert(ids, 'a' + tags[i].toUpperCase()); + if (tags[i] && !ids.includes('a' + tags[i].toUpperCase())) { + ids.push('a' + tags[i].toUpperCase()); } else { invalid = true; } diff --git a/src/os/ui/filterlayergroupby.js b/src/os/ui/filterlayergroupby.js index c8fdc08ae..49572b06d 100644 --- a/src/os/ui/filterlayergroupby.js +++ b/src/os/ui/filterlayergroupby.js @@ -57,7 +57,9 @@ export default class FilterLayerGroupBy extends FilterGroupBy { } } - goog.array.insert(ids, val); + if (!ids.includes(val)) { + ids.push(val); + } return ids; } } diff --git a/src/os/ui/im/action/filteraction.js b/src/os/ui/im/action/filteraction.js index 64d53bdde..e2cd0c0fd 100644 --- a/src/os/ui/im/action/filteraction.js +++ b/src/os/ui/im/action/filteraction.js @@ -242,8 +242,8 @@ export const removeEntryCmd = function(entry) { * @param {ITreeNode} node The current node. */ export const isFilterActionNode = function(targetArr, node) { - if (node instanceof FilterActionNode) { - goog.array.insert(targetArr, node); + if (node instanceof FilterActionNode && !targetArr.includes(node)) { + targetArr.push(node); } else if (node.getChildren()) { node.getChildren().forEach(isFilterActionNode.bind(undefined, targetArr)); } diff --git a/src/os/xt/peer.js b/src/os/xt/peer.js index abf6f1922..03aa26683 100644 --- a/src/os/xt/peer.js +++ b/src/os/xt/peer.js @@ -342,7 +342,9 @@ export default class Peer { var types = this.handlers_[i].getTypes(); for (var j = 0, m = types.length; j < m; j++) { - googArray.insert(set, types[j]); + if (!set.includes(types[j])) { + set.push(types[j]); + } } } diff --git a/test/os/data/typegroupby.mock.js b/test/os/data/typegroupby.mock.js index d6488825f..f62247311 100644 --- a/test/os/data/typegroupby.mock.js +++ b/test/os/data/typegroupby.mock.js @@ -1,6 +1,5 @@ goog.module('os.data.groupby.MockTypeGroupBy'); -const googArray = goog.require('goog.array'); const {default: BaseGroupBy} = goog.require('os.data.groupby.BaseGroupBy'); const {default: TriStateTreeNode} = goog.require('os.structs.TriStateTreeNode'); @@ -43,7 +42,9 @@ class MockTypeGroupBy extends BaseGroupBy { val = 'No Type'; } - googArray.insert(ids, val); + if (!ids.includes(val)) { + ids.push(val); + } return ids; } diff --git a/test/os/ui/slick/typegroupby.mock.js b/test/os/ui/slick/typegroupby.mock.js index 742033be4..82c44aab3 100644 --- a/test/os/ui/slick/typegroupby.mock.js +++ b/test/os/ui/slick/typegroupby.mock.js @@ -1,6 +1,5 @@ goog.module('os.ui.MockTypeGroupBy'); -const googArray = goog.require('goog.array'); const {default: BaseGroupBy} = goog.require('os.data.groupby.BaseGroupBy'); const {default: SlickTreeNode} = goog.require('os.ui.slick.SlickTreeNode'); @@ -43,7 +42,9 @@ class MockTypeGroupBy extends BaseGroupBy { val = 'No Type'; } - googArray.insert(ids, val); + if (!ids.includes(val)) { + ids.push(val); + } return ids; } From 2e0d710834ac35ac80dc02a9c357005c463987cf Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Wed, 16 Feb 2022 14:02:02 -0700 Subject: [PATCH 11/23] feat(goog): remove goog.array.forEach --- src/os/im/action/filteractionparser.js | 11 ++++++----- src/os/state/v4/filteractionstate.js | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/os/im/action/filteractionparser.js b/src/os/im/action/filteractionparser.js index 4741cffb6..998f14141 100644 --- a/src/os/im/action/filteractionparser.js +++ b/src/os/im/action/filteractionparser.js @@ -6,6 +6,7 @@ import TagName from './tagname.js'; const dom = goog.require('goog.dom'); const xml = goog.require('goog.dom.xml'); +const googString = goog.require('goog.string'); const {default: FilterActionEntry} = goog.requireType('os.im.action.FilterActionEntry'); const {default: IParser} = goog.requireType('os.parse.IParser'); @@ -74,7 +75,7 @@ export default class FilterActionParser { /** * Extracts filter actions from an array of XML nodes. * - * @param {!IArrayLike} nodes The XML nodes to extract an entry from. + * @param {!Array} nodes The XML nodes to extract an entry from. * @return {!Array} */ static parseNodes(nodes) { @@ -82,11 +83,11 @@ export default class FilterActionParser { var entries = []; var parentMap = {}; - goog.array.forEach(nodes, function(node) { + nodes.forEach(function(node) { var actions = []; var filter = null; - var id = /** @type {string} */ (node.getAttribute('id')) || goog.string.getRandomString(); + var id = /** @type {string} */ (node.getAttribute('id')) || googString.getRandomString(); var title = /** @type {string} */ (node.getAttribute('title')) || ''; var description = /** @type {?string} */ (node.getAttribute('description')) || ''; var tags = /** @type {?string} */ (node.getAttribute('tags')) || ''; @@ -107,7 +108,7 @@ export default class FilterActionParser { if (actionsNode && actionsNode.childNodes.length) { var actionEls = dom.getChildren(actionsNode); - goog.array.forEach(actionEls, function(el) { + Array.from(actionEls).forEach(function(el) { var action = iam.createActionFromXml(el); if (action) { actions.push(action); @@ -162,7 +163,7 @@ export default class FilterActionParser { var iam = getImportActionManager(); var root = dom.getFirstElementChild(doc); var actionNodes = root.querySelectorAll(iam.xmlEntry); - var entries = FilterActionParser.parseNodes(actionNodes); + var entries = FilterActionParser.parseNodes(Array.from(actionNodes)); return entries; } diff --git a/src/os/state/v4/filteractionstate.js b/src/os/state/v4/filteractionstate.js index e9b5eb909..eb6fef6a5 100644 --- a/src/os/state/v4/filteractionstate.js +++ b/src/os/state/v4/filteractionstate.js @@ -50,7 +50,7 @@ export default class FilterAction extends XMLState { var iam = ImportActionManager.getInstance(); var children = getChildren(obj); if (children && children.length > 0) { - var entries = FilterActionParser.parseNodes(children); + var entries = FilterActionParser.parseNodes(Array.from(children)); for (var i = 0, n = entries.length; i < n; i++) { var e = entries[i]; From 2d41e58ad93545c337b6feaf22b38c2f573716c0 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Wed, 16 Feb 2022 14:12:13 -0700 Subject: [PATCH 12/23] feat(goog): remove goog.array.clone --- src/os/config/namespace.js | 3 +-- src/os/config/settings.js | 4 ++-- src/os/ui/search/searchbox.js | 2 +- src/os/ui/util/autovheight.js | 4 ++-- src/os/user/settings/favoritemanager.js | 2 +- test/os/mixin/closuremixin.test.js | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/os/config/namespace.js b/src/os/config/namespace.js index a4e66cf7d..13454e9e5 100644 --- a/src/os/config/namespace.js +++ b/src/os/config/namespace.js @@ -8,7 +8,6 @@ goog.declareModuleId('os.config.namespace'); import * as osObject from '../object/object.js'; import * as osConfig from './config.js'; -const googArray = goog.require('goog.array'); const googObject = goog.require('goog.object'); @@ -153,7 +152,7 @@ export const getPrefixedKeys = function(keys) { if (keys && keys.length > 0) { var reduced = keys.join('.'); var prefix = isCoreKey(/** @type {!string} */ (reduced)) ? osConfig.coreNs : osConfig.appNs; - namespaced = googArray.clone(keys); + namespaced = Array.from(keys); namespaced.unshift(prefix); } return namespaced || []; diff --git a/src/os/config/settings.js b/src/os/config/settings.js index a09872b74..67ad5a11b 100644 --- a/src/os/config/settings.js +++ b/src/os/config/settings.js @@ -432,7 +432,7 @@ export default class Settings extends EventTarget { log.fine(logger, 'Saving settings...'); - var keysToDelete = googArray.clone(osConfigNamespace.getObsoleteKeys()); + var keysToDelete = Array.from(osConfigNamespace.getObsoleteKeys()); googArray.insertArrayAt(keysToDelete, osConfigNamespace.keysToDelete.slice()); if (opt_settingsToOverwrite != null) { @@ -673,7 +673,7 @@ export default class Settings extends EventTarget { if (this.loaded_) { var val = googObject.getValueByKeys(this.mergedConfig_, keys); if (Array.isArray(val)) { - val = googArray.clone(val); + val = Array.from(val); } else if (goog.isObject(val)) { val = googObject.clone(val); } diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index cc92cd003..b0a2b4799 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -526,7 +526,7 @@ export class Controller { this['searchOptionsNoGroup'] = []; const proGroups = /** @type {!Object>} */ (Settings.getInstance().get('providerGroups', {})); - const copiedOptions = googArray.clone(this['searchOptions']); + const copiedOptions = Array.from(this['searchOptions']); // Iterate over the Provider group names for (const groupName in proGroups) { diff --git a/src/os/ui/util/autovheight.js b/src/os/ui/util/autovheight.js index 0a65f3d71..24dda4922 100644 --- a/src/os/ui/util/autovheight.js +++ b/src/os/ui/util/autovheight.js @@ -213,7 +213,7 @@ export class Controller { this.vsm_.listen(GoogEventType.RESIZE, this.onResize_, false, this); // add resize to common elements - var allCommonElements = googArray.clone(windowCommonElements); + var allCommonElements = Array.from(windowCommonElements); Object.assign(allCommonElements, windowCommonOptionalElements); allCommonElements.forEach(function(sibling) { resize($(/** @type {string} */ (sibling)), this.resizeFn_); @@ -237,7 +237,7 @@ export class Controller { this.vsm_.unlisten(GoogEventType.RESIZE, this.onResize_, false, this); // remove resize from common elements - var allCommonElements = googArray.clone(windowCommonElements); + var allCommonElements = Array.from(windowCommonElements); googArray.extend(allCommonElements, windowCommonOptionalElements); allCommonElements.forEach(function(sibling) { if (this.resizeFn_) { diff --git a/src/os/user/settings/favoritemanager.js b/src/os/user/settings/favoritemanager.js index ff777a1d1..470795761 100644 --- a/src/os/user/settings/favoritemanager.js +++ b/src/os/user/settings/favoritemanager.js @@ -254,7 +254,7 @@ export default class FavoriteManager extends EventTarget { if (opt_types) { fullList = this.getFavTypes(list, opt_types); } else if (list) { - fullList = googArray.clone(list); + fullList = Array.from(list); } else { fullList = []; } diff --git a/test/os/mixin/closuremixin.test.js b/test/os/mixin/closuremixin.test.js index 280718657..598578c1a 100644 --- a/test/os/mixin/closuremixin.test.js +++ b/test/os/mixin/closuremixin.test.js @@ -52,7 +52,7 @@ describe('os.mixin.closure', function() { testArray(original); // make sure clone ignores polyfills - var clone = goog.array.clone(original); + var clone = Array.from(original); testArray(clone); compareArrays(original, clone); From 8ea4859aff6afe875cbc20eb1a7c2eb58841d880 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Wed, 16 Feb 2022 15:11:04 -0700 Subject: [PATCH 13/23] feat(goog): remove goog.array.defaultCompare and more insert --- src/os/array/array.js | 20 ++++++++++++----- src/os/color.js | 3 ++- src/os/data/basedescriptor.js | 4 ++-- src/os/data/histo/colormodellegendrenderer.js | 5 ++--- src/os/feature/feature.js | 4 ++-- src/os/file/filemanager.js | 4 ++-- src/os/hist/hist.js | 5 +++-- src/os/im/action/importaction.js | 3 ++- src/os/legend/legend.js | 6 ++--- src/os/mapcontainer.js | 5 +++-- src/os/net/net.js | 4 ++-- src/os/net/request.js | 7 +++--- src/os/net/requesthandlerfactory.js | 6 ++--- src/os/object/object.js | 7 +++--- src/os/query/basequerymanager.js | 6 ++--- src/os/search/abstractsearchmanager.js | 4 ++-- src/os/source/source.js | 6 ++--- src/os/state/state.js | 7 +++--- src/os/state/statemanager.js | 12 ++++++---- src/os/time/time.js | 4 ++-- src/os/ui/checklist.js | 4 ++-- .../column/mapping/columnmappingsettingsui.js | 13 +++++------ src/os/ui/config/settingsmanager.js | 4 ++-- src/os/ui/file/exportmanager.js | 4 ++-- src/os/ui/im/importmanager.js | 7 +++--- src/os/ui/menu/menuitem.js | 5 +++-- src/os/ui/query/queryhandler.js | 5 +++-- src/os/ui/search/facetedsearch.js | 7 +++--- src/os/ui/search/searchbox.js | 3 ++- src/os/ui/slick/column.js | 8 +++---- src/os/ui/slick/slickgrid.js | 14 +++++++----- src/os/ui/slick/treesearch.js | 6 ++--- src/os/ui/timeline/offarrows.js | 6 ++--- src/plugin/descriptor/descriptorsearch.js | 3 ++- src/plugin/vectortools/vectortools.js | 4 ++-- test/os/structs/arraycollection.test.js | 22 +++++++++---------- 36 files changed, 132 insertions(+), 105 deletions(-) diff --git a/src/os/array/array.js b/src/os/array/array.js index c0d891ad1..7552f7d4c 100644 --- a/src/os/array/array.js +++ b/src/os/array/array.js @@ -69,7 +69,7 @@ export const forEach = function(arr, f, opt_obj) { * @template VALUE */ export const sortByField = function(field, a, b) { - return googArray.defaultCompare(a[field], b[field]); + return defaultSort(a[field], b[field]); }; /** @@ -82,7 +82,7 @@ export const sortByField = function(field, a, b) { * @template VALUE */ export const sortByFieldDesc = function(field, a, b) { - return googArray.defaultCompare(b[field], a[field]); + return defaultSort(b[field], a[field]); }; /** @@ -239,7 +239,7 @@ export let JoinIndex; * @return {number} */ export const crossProductSort = function(a, b) { - return -1 * googArray.defaultCompare(a.crossProduct, b.crossProduct); + return -1 * defaultSort(a.crossProduct, b.crossProduct); }; /** @@ -307,7 +307,7 @@ export const join = function(sets, copyFunction) { * assumed to contain equal-length groups of values, and the target is searched using a group length (stride) and offset * within each group. * - * If no opt_compareFn is specified, elements are compared using `googArray.defaultCompare`, which compares the + * If no opt_compareFn is specified, elements are compared using `os.array.defaultSort`, which compares the * elements using the built in < and > operators. This will produce the expected behavior for homogeneous arrays of * String(s) and Number(s). * @@ -332,7 +332,7 @@ export const join = function(sets, copyFunction) { * @template TARGET, VALUE */ export const binaryStrideSearch = function(arr, target, stride, offset, opt_compareFn) { - var compareFn = opt_compareFn || googArray.defaultCompare; + var compareFn = opt_compareFn || defaultSort; // ensure the offset is within the group bounds offset = math.clamp(offset, 0, stride - 1); @@ -362,3 +362,13 @@ export const binaryStrideSearch = function(arr, target, stride, offset, opt_comp // ~left is a shorthand for -left - 1. return found ? left : ~left; }; + +/** + * @param {VALUE} a + * @param {VALUE} b + * @return {number} + * @template VALUE + */ +export const defaultSort = (a, b) => { + return a > b ? 1 : a < b ? -1 : 0; +}; diff --git a/src/os/color.js b/src/os/color.js index 7aa4cd5ab..722c7dbb5 100644 --- a/src/os/color.js +++ b/src/os/color.js @@ -9,6 +9,7 @@ goog.require('goog.color.Rgb'); goog.require('goog.math'); goog.require('goog.math.Matrix'); +import {defaultSort} from './array/array.js'; /** * @typedef {{ @@ -588,7 +589,7 @@ export const colorSort = function(c1, c2) { const val1 = Math.round(hsl1[0] * 100) + Math.round(hsl1[1] * 100) / 100 + Math.round(hsl1[2] * 100) / 10000; const val2 = Math.round(hsl2[0] * 100) + Math.round(hsl2[1] * 100) / 100 + Math.round(hsl2[2] * 100) / 10000; - return goog.array.defaultCompare(val2, val1); + return defaultSort(val2, val1); }; /** diff --git a/src/os/data/basedescriptor.js b/src/os/data/basedescriptor.js index 1ada7bcae..bc8f94a2d 100644 --- a/src/os/data/basedescriptor.js +++ b/src/os/data/basedescriptor.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.data.BaseDescriptor'); +import {defaultSort} from '../array/array.js'; import * as dispatcher from '../dispatcher.js'; import PropertyChangeEvent from '../events/propertychangeevent.js'; import osImplements from '../implements.js'; @@ -11,7 +12,6 @@ import DescriptorEvent from './descriptorevent.js'; import DescriptorEventType from './descriptoreventtype.js'; import IDataDescriptor from './idatadescriptor.js'; -const googArray = goog.require('goog.array'); const nextTick = goog.require('goog.async.nextTick'); const UtcDateTime = goog.require('goog.date.UtcDateTime'); const EventTarget = goog.require('goog.events.EventTarget'); @@ -730,7 +730,7 @@ export default class BaseDescriptor extends EventTarget { } else if (!isNaN(a.getLastActive()) && isNaN(b.getLastActive())) { return -1; } else { - return googArray.defaultCompare(a.getLastActive(), b.getLastActive()); + return defaultSort(a.getLastActive(), b.getLastActive()); } } diff --git a/src/os/data/histo/colormodellegendrenderer.js b/src/os/data/histo/colormodellegendrenderer.js index 1f8eed54e..70f1b3333 100644 --- a/src/os/data/histo/colormodellegendrenderer.js +++ b/src/os/data/histo/colormodellegendrenderer.js @@ -1,11 +1,11 @@ goog.declareModuleId('os.data.histo.legend'); +import {defaultSort} from '../../array/array.js'; import NumericBinMethod from '../../histo/numericbinmethod.js'; import * as legend from '../../legend/legend.js'; import {ROOT} from '../../os.js'; import Module from '../../ui/module.js'; -const googArray = goog.require('goog.array'); const googObject = goog.require('goog.object'); const {default: VectorLayer} = goog.requireType('os.layer.Vector'); @@ -69,8 +69,7 @@ export const addVectorColorModel = function(layer, options) { if (keys.length > 0) { // TODO: should we use goog.string.caseInsensitiveCompare for the default case? - var sortFn = binMethod instanceof NumericBinMethod ? legend.numericCompare : - googArray.defaultCompare; + var sortFn = binMethod instanceof NumericBinMethod ? legend.numericCompare : defaultSort; keys.sort(sortFn); for (var i = 0; i < keys.length; i++) { diff --git a/src/os/feature/feature.js b/src/os/feature/feature.js index aa0b803e0..53061e3bf 100644 --- a/src/os/feature/feature.js +++ b/src/os/feature/feature.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.feature'); +import {defaultSort} from '../array/array.js'; import * as osBearing from '../bearing/bearing.js'; import BearingType from '../bearing/bearingtype.js'; import CommandProcessor from '../command/commandprocessor.js'; @@ -32,7 +33,6 @@ import {quoteString} from '../ui/filter/filterstring.js'; import DynamicFeature from './dynamicfeature.js'; -const {defaultCompare} = goog.require('goog.array'); const {containsValue} = goog.require('goog.object'); const reflect = goog.require('goog.reflect'); const {floatAwareCompare} = goog.require('goog.string'); @@ -1310,7 +1310,7 @@ export const sortByField = function(field, a, b) { return floatAwareCompare(aValue, bValue); } - return defaultCompare(aValue, bValue); + return defaultSort(aValue, bValue); } else if (aValue != null) { return -1; } else if (bValue != null) { diff --git a/src/os/file/filemanager.js b/src/os/file/filemanager.js index f53d14c0f..bef4146d2 100644 --- a/src/os/file/filemanager.js +++ b/src/os/file/filemanager.js @@ -1,9 +1,9 @@ goog.declareModuleId('os.file.FileManager'); +import {defaultSort} from '../array/array.js'; import {detect, getTypeChain} from './mime.js'; import * as text from './mime/text.js'; -const {defaultCompare} = goog.require('goog.array'); const GoogFileReader = goog.require('goog.fs.FileReader'); const log = goog.require('goog.log'); @@ -143,7 +143,7 @@ export default class FileManager { * @private */ sortDescPriority_(a, b) { - return defaultCompare(b.getPriority(), a.getPriority()); + return defaultSort(b.getPriority(), a.getPriority()); } /** diff --git a/src/os/hist/hist.js b/src/os/hist/hist.js index 99995edac..ec3954cde 100644 --- a/src/os/hist/hist.js +++ b/src/os/hist/hist.js @@ -3,10 +3,11 @@ */ goog.declareModuleId('os.hist'); +import {defaultSort} from '../array/array.js'; import osImplements from '../implements.js'; import IHistogramProvider from './ihistogramprovider.js'; -const {binaryInsert, defaultCompare} = goog.require('goog.array'); +const {binaryInsert} = goog.require('goog.array'); const googObject = goog.require('goog.object'); const Layer = goog.requireType('ol.layer.Layer'); @@ -94,7 +95,7 @@ export const getBinCounts = function(histograms, opt_combine, opt_skipCompare) { if (opt_skipCompare) { return -1; } - return aCount != bCount ? defaultCompare(bCount, aCount) : -1; + return aCount != bCount ? defaultSort(bCount, aCount) : -1; }); }); } diff --git a/src/os/im/action/importaction.js b/src/os/im/action/importaction.js index 5348b5bd4..8df847c55 100644 --- a/src/os/im/action/importaction.js +++ b/src/os/im/action/importaction.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.im.action'); +import {defaultSort} from '../../array/array.js'; import {instanceOf} from '../../classregistry.js'; import LayerClass from '../../layer/layerclass.js'; import * as osSource from '../../source/source.js'; @@ -149,7 +150,7 @@ export const reduceEnabled = function(ids, entry) { export const sortByLabel = function(a, b) { var aLabel = a ? a.getLabel() : ''; var bLabel = b ? b.getLabel() : ''; - return goog.array.defaultCompare(aLabel, bLabel); + return defaultSort(aLabel, bLabel); }; /** diff --git a/src/os/legend/legend.js b/src/os/legend/legend.js index 421809149..13bdb98c7 100644 --- a/src/os/legend/legend.js +++ b/src/os/legend/legend.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.legend'); +import {defaultSort} from '../array/array.js'; import Settings from '../config/settings.js'; import * as dispatcher from '../dispatcher.js'; import {noop} from '../fn/fn.js'; @@ -13,7 +14,6 @@ import StyleManager from '../style/stylemanager_shim.js'; import {measureText} from '../ui/ui.js'; import ILegendRenderer from './ilegendrenderer.js'; -const {defaultCompare} = goog.require('goog.array'); const {clamp} = goog.require('goog.math'); const Feature = goog.require('ol.Feature'); const ImageState = goog.require('ol.ImageState'); @@ -196,7 +196,7 @@ export const registerLayerPlugin = function(options) { */ export const sortPluginByPriority = function(a, b) { // sort in descending order - return -defaultCompare(a.priority || 0, b.priority || 0); + return -defaultSort(a.priority || 0, b.priority || 0); }; /** @@ -557,7 +557,7 @@ export const numericCompare = function(labelA, labelB) { var a = Number(aMatch[1]); var b = Number(bMatch[1]); - return a > b ? 1 : a < b ? -1 : 0; + return defaultSort(a, b); }; /** diff --git a/src/os/mapcontainer.js b/src/os/mapcontainer.js index ff448d850..9e959ab44 100644 --- a/src/os/mapcontainer.js +++ b/src/os/mapcontainer.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.MapContainer'); import EventType from './action/eventtype.js'; +import {defaultSort} from './array/array.js'; import {isColorString} from './color.js'; import CommandProcessor from './command/commandprocessor.js'; import FlyToExtent from './command/flytoextentcmd.js'; @@ -64,7 +65,7 @@ import AltitudeMode from './webgl/altitudemode.js'; import {isSupported as isWebglSupported, hasPerformanceCaveat} from './webgl/webgl.js'; const Promise = goog.require('goog.Promise'); -const {binarySelect, defaultCompare} = goog.require('goog.array'); +const {binarySelect} = goog.require('goog.array'); const {assert} = goog.require('goog.asserts'); const ConditionalDelay = goog.require('goog.async.ConditionalDelay'); const Delay = goog.require('goog.async.Delay'); @@ -1884,7 +1885,7 @@ export default class MapContainer extends EventTarget { * @private */ static compareGroups_(a, b) { - return defaultCompare(a.getPriority(), b.getPriority()); + return defaultSort(a.getPriority(), b.getPriority()); } /** diff --git a/src/os/net/net.js b/src/os/net/net.js index 21b6b0b4a..c2e925268 100644 --- a/src/os/net/net.js +++ b/src/os/net/net.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.net'); +import {defaultSort} from '../array/array.js'; import {registerClass} from '../classregistry.js'; import {getSettings} from '../config/configinstance.js'; import instanceOf from '../instanceof.js'; @@ -8,7 +9,6 @@ import CrossOrigin from './crossorigin.js'; const Uri = goog.require('goog.Uri'); const QueryData = goog.require('goog.Uri.QueryData'); -const {defaultCompare} = goog.require('goog.array'); const {hashCode} = goog.require('goog.string'); @@ -147,7 +147,7 @@ export const loadCrossOriginCache = function() { * @return {number} per typical compare functions */ const sortCache_ = function(a, b) { - return defaultCompare(b.priority, a.priority); + return defaultSort(b.priority, a.priority); }; /** diff --git a/src/os/net/request.js b/src/os/net/request.js index 95f18e3a7..72e819fa4 100644 --- a/src/os/net/request.js +++ b/src/os/net/request.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.net.Request'); +import {defaultSort} from '../array/array.js'; import * as dispatcher from '../dispatcher.js'; import {getDefaultValidators} from './net.js'; import RequestEvent from './requestevent.js'; @@ -10,7 +11,7 @@ import VariableReplacer from './variablereplacer.js'; const Promise = goog.require('goog.Promise'); const Uri = goog.require('goog.Uri'); -const {binaryInsert, binaryRemove, defaultCompare} = goog.require('goog.array'); +const {binaryInsert, binaryRemove} = goog.require('goog.array'); const EventTarget = goog.require('goog.events.EventTarget'); const log = goog.require('goog.log'); const Level = goog.require('goog.log.Level'); @@ -826,10 +827,10 @@ export default class Request extends EventTarget { * @private */ static modifierCompare_(a, b) { - var r = defaultCompare(a.getPriority(), b.getPriority()); + var r = defaultSort(a.getPriority(), b.getPriority()); if (r === 0) { - return defaultCompare(a.getId(), b.getId()); + return defaultSort(a.getId(), b.getId()); } else { return -r; } diff --git a/src/os/net/requesthandlerfactory.js b/src/os/net/requesthandlerfactory.js index 2d9d720ae..bd0e3b7e5 100644 --- a/src/os/net/requesthandlerfactory.js +++ b/src/os/net/requesthandlerfactory.js @@ -1,8 +1,8 @@ goog.declareModuleId('os.net.RequestHandlerFactory'); -const {defaultCompare} = goog.require('goog.array'); -const {remove} = goog.require('ol.array'); +import {defaultSort} from '../array/array'; +const {remove} = goog.require('ol.array'); const {default: IRequestHandler} = goog.requireType('os.net.IRequestHandler'); @@ -77,7 +77,7 @@ export const getHandlers = function(method, uri, opt_timeout) { * @return {number} per compare functions */ function(a, b) { - return -1 * defaultCompare(a.getScore(), b.getScore()); + return -1 * defaultSort(a.getScore(), b.getScore()); }); } diff --git a/src/os/object/object.js b/src/os/object/object.js index ae77ffd18..27bb23628 100644 --- a/src/os/object/object.js +++ b/src/os/object/object.js @@ -3,7 +3,8 @@ */ goog.declareModuleId('os.object'); -const {defaultCompare} = goog.require('goog.array'); +import {defaultSort} from '../array/array'; + const {getCount, getValueByKeys, isEmpty} = goog.require('goog.object'); const {startsWith, toTitleCase} = goog.require('goog.string'); @@ -286,13 +287,13 @@ export const getValueExtractor = function(attribute) { * @param {Object} o1 Object one * @param {Object} o2 Object two * @param {function(*, *):number=} opt_comparitor Optional comparison function. - * Otherwise {@link googArray.defaultCompare} will be used + * Otherwise {@link os.array.defaultSort} will be used * @return {number} */ export const compareByField = function(field, o1, o2, opt_comparitor) { var v1 = getCompareFieldValue(field, o1); var v2 = getCompareFieldValue(field, o2); - return opt_comparitor ? opt_comparitor(v1, v2) : defaultCompare(v1, v2); + return opt_comparitor ? opt_comparitor(v1, v2) : defaultSort(v1, v2); }; /** diff --git a/src/os/query/basequerymanager.js b/src/os/query/basequerymanager.js index 7932a335f..e93d5d3bd 100644 --- a/src/os/query/basequerymanager.js +++ b/src/os/query/basequerymanager.js @@ -1,12 +1,12 @@ goog.declareModuleId('os.query.BaseQueryManager'); +import {defaultSort} from '../array/array.js'; import PropertyChangeEvent from '../events/propertychangeevent.js'; import ComboNode from '../ui/query/combonode.js'; import {ALL_ID} from '../ui/query/query.js'; import {AreaState} from './query.js'; import {getAreaManager, getFilterManager, getQueryManager, setQueryManager} from './queryinstance.js'; -const {defaultCompare} = goog.require('goog.array'); const {assert} = goog.require('goog.asserts'); const Delay = goog.require('goog.async.Delay'); const EventTarget = goog.require('goog.events.EventTarget'); @@ -1123,7 +1123,7 @@ export default class BaseQueryManager extends EventTarget { return caseInsensitiveCompare(astr, bstr); } - return defaultCompare(astr, bstr); + return defaultSort(astr, bstr); }); } @@ -1167,7 +1167,7 @@ export default class BaseQueryManager extends EventTarget { var result = 0; for (var i = 0, n = fields.length; i < n; i++) { - result = defaultCompare(a[fields[i]], b[fields[i]]); + result = defaultSort(a[fields[i]], b[fields[i]]); if (result) { return result; diff --git a/src/os/search/abstractsearchmanager.js b/src/os/search/abstractsearchmanager.js index 5c7d1f962..41f988f6c 100644 --- a/src/os/search/abstractsearchmanager.js +++ b/src/os/search/abstractsearchmanager.js @@ -1,10 +1,10 @@ goog.declareModuleId('os.search.AbstractSearchManager'); +import {defaultSort} from '../array/array.js'; import FavoriteManager from '../user/settings/favoritemanager.js'; import FavoriteType from '../user/settings/favoritetype.js'; import SearchEventType from './searcheventtype.js'; -const {defaultCompare} = goog.require('goog.array'); const GoogEvent = goog.require('goog.events.Event'); const EventTarget = goog.require('goog.events.EventTarget'); const {hashCode} = goog.require('goog.string'); @@ -194,7 +194,7 @@ export default class AbstractSearchManager extends EventTarget { */ scoreCompare(a, b) { // default is ascending order, so flip the sign - return -defaultCompare(a.getScore(), b.getScore()); + return -defaultSort(a.getScore(), b.getScore()); } /** diff --git a/src/os/source/source.js b/src/os/source/source.js index 217a674cf..4c340ce99 100644 --- a/src/os/source/source.js +++ b/src/os/source/source.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.source'); import AlertEventSeverity from '../alert/alerteventseverity.js'; import AlertManager from '../alert/alertmanager.js'; +import {defaultSort} from '../array/array.js'; import ColumnDefinition from '../data/columndefinition.js'; import DataManager from '../data/datamanager.js'; import DataEventType from '../data/event/dataeventtype.js'; @@ -20,7 +21,6 @@ import TimelineController from '../time/timelinecontroller.js'; import {numerateNameCompare} from '../ui/slick/column.js'; const Timer = goog.require('goog.Timer'); -const {defaultCompare} = goog.require('goog.array'); const {isEmptyOrWhitespace, makeSafe} = goog.require('goog.string'); const Feature = goog.require('ol.Feature'); const Property = goog.require('ol.layer.Property'); @@ -197,7 +197,7 @@ export const isVisible = function(source) { * @return {number} The comparison */ export const titleCompare = function(a, b) { - return defaultCompare(a.getTitle(), b.getTitle()); + return defaultSort(a.getTitle(), b.getTitle()); }; /** @@ -210,7 +210,7 @@ export const titleCompare = function(a, b) { export const zIndexCompare = function(a, b) { var aZ = a.get(Property.Z_INDEX) || 0; var bZ = b.get(Property.Z_INDEX) || 0; - return defaultCompare(bZ, aZ); + return defaultSort(bZ, aZ); }; /** diff --git a/src/os/state/state.js b/src/os/state/state.js index 891a714d8..1c8100122 100644 --- a/src/os/state/state.js +++ b/src/os/state/state.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.state'); +import {defaultSort} from '../array/array.js'; import CommandProcessor from '../command/commandprocessor.js'; import DataManager from '../data/datamanager.js'; import BaseProvider from '../ui/data/baseprovider.js'; @@ -7,8 +8,6 @@ import DescriptorProvider from '../ui/data/descriptorprovider.js'; import {hasUrlScheme} from '../url/url.js'; import Tag from './tag.js'; -const {defaultCompare} = goog.require('goog.array'); - const {default: IDataDescriptor} = goog.requireType('os.data.IDataDescriptor'); const {default: IState} = goog.requireType('os.state.IState'); @@ -61,7 +60,7 @@ export const stateToString = function(state) { */ export const priorityCompare = function(a, b) { // a/b are flipped to sort in descending priority order - return defaultCompare(b.getPriority(), a.getPriority()); + return defaultSort(b.getPriority(), a.getPriority()); }; /** @@ -72,7 +71,7 @@ export const priorityCompare = function(a, b) { * @return {number} The comparison */ export const titleCompare = function(a, b) { - return defaultCompare(a.getTitle(), b.getTitle()); + return defaultSort(a.getTitle(), b.getTitle()); }; /** diff --git a/src/os/state/statemanager.js b/src/os/state/statemanager.js index 8a47a2908..0cde8f760 100644 --- a/src/os/state/statemanager.js +++ b/src/os/state/statemanager.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.state.StateManager'); +import {defaultSort} from '../array/array.js'; import DataManager from '../data/datamanager.js'; import ProviderEntry from '../data/providerentry.js'; import osImplements from '../implements.js'; @@ -27,7 +28,6 @@ import ViewState from './v4/viewstate.js'; import Versions from './versions.js'; import XMLStateManager from './xmlstatemanager.js'; -const {defaultCompare, insert} = goog.require('goog.array'); const {getFirstElementChild} = goog.require('goog.dom'); const log = goog.require('goog.log'); const {remove} = goog.require('ol.array'); @@ -211,7 +211,7 @@ export default class StateManager extends XMLStateManager { if (stateDescriptors.length) { // sort by last active to get the most recently activated state and default in its details stateDescriptors.sort(function(a, b) { - return defaultCompare(a, b); + return defaultSort(a, b); }); var descriptor = /** @type {IStateDescriptor} */ (stateDescriptors[0]); @@ -294,7 +294,9 @@ export default class StateManager extends XMLStateManager { if (!opt_versionKey) { opt_versionKey = this.getVersion(); } - insert(this.functionMap_[opt_versionKey].loadFunctions, loadFunction); + if (!this.functionMap_[opt_versionKey].loadFunctions.includes(loadFunction)) { + this.functionMap_[opt_versionKey].loadFunctions.push(loadFunction); + } } /** @@ -321,7 +323,9 @@ export default class StateManager extends XMLStateManager { if (!opt_versionKey) { opt_versionKey = this.getVersion(); } - insert(this.functionMap_[opt_versionKey].saveFunctions, saveFunction); + if (!this.functionMap_[opt_versionKey].saveFunctions.includes(saveFunction)) { + this.functionMap_[opt_versionKey].saveFunctions.push(saveFunction); + } } /** diff --git a/src/os/time/time.js b/src/os/time/time.js index 716bf0871..bfdab0af8 100644 --- a/src/os/time/time.js +++ b/src/os/time/time.js @@ -5,11 +5,11 @@ */ goog.declareModuleId('os.time'); +import {defaultSort} from '../array/array.js'; import Settings from '../config/settings.js'; import VariableReplacer from '../net/variablereplacer.js'; import Duration from './duration.js'; -const googArray = goog.require('goog.array'); const asserts = goog.require('goog.asserts'); const UtcDateTime = goog.require('goog.date.UtcDateTime'); const DateTimeFormat = goog.require('goog.i18n.DateTimeFormat'); @@ -737,7 +737,7 @@ export const applyOffset = function(offset) { * @return {number} */ export const dateCompare = function(a, b) { - return googArray.defaultCompare(b.toISOString(), a.toISOString()); + return defaultSort(b.toISOString(), a.toISOString()); }; /** diff --git a/src/os/ui/checklist.js b/src/os/ui/checklist.js index 5effb8db9..121097c8c 100644 --- a/src/os/ui/checklist.js +++ b/src/os/ui/checklist.js @@ -1,12 +1,12 @@ goog.declareModuleId('os.ui.ChecklistUI'); +import {defaultSort} from '../array/array.js'; import * as dispatcher from '../dispatcher.js'; import {ROOT} from '../os.js'; import ChecklistEvent from './checklistevent.js'; import Module from './module.js'; import * as ui from './ui.js'; -const {defaultCompare} = goog.require('goog.array'); const {getDocument} = goog.require('goog.dom'); const GoogEvent = goog.require('goog.events.Event'); const GoogEventType = goog.require('goog.events.EventType'); @@ -161,7 +161,7 @@ export class Controller { */ labelCompare_(a, b) { if (!a.label || !b.label) { - return defaultCompare(a.label, b.label); + return defaultSort(a.label, b.label); } return a.label.localeCompare(/** @type {string} */ (b.label), undefined, {sensitivity: 'base', numeric: true}); } diff --git a/src/os/ui/column/mapping/columnmappingsettingsui.js b/src/os/ui/column/mapping/columnmappingsettingsui.js index d69e5505f..2ffcb7fc6 100644 --- a/src/os/ui/column/mapping/columnmappingsettingsui.js +++ b/src/os/ui/column/mapping/columnmappingsettingsui.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.ui.column.mapping.ColumnMappingSettingsUI'); +import {defaultSort} from '../../../array/array.js'; import ColumnMappingEventType from '../../../column/columnmappingeventtype.js'; import ColumnMappingManager from '../../../column/columnmappingmanager.js'; import {ROOT} from '../../../os.js'; @@ -13,8 +14,6 @@ import {directiveTag as columnMappingExportUi} from './columnmappingexport.js'; import {launchColumnMappingWindow} from './columnmappingform.js'; import ColumnMappingNode from './columnmappingnode.js'; -const {defaultCompare, insert} = goog.require('goog.array'); - const {default: IColumnMapping} = goog.requireType('os.column.IColumnMapping'); @@ -133,12 +132,12 @@ export class Controller { if (selected.length > 0) { for (var i = 0, ii = selected.length; i < ii; i++) { // don't include the subnodes if they are selected in the tree - if (selected[i] instanceof ColumnMappingNode) { - insert(selectedItems, selected[i].getColumnMapping()); + if (selected[i] instanceof ColumnMappingNode && !selectedItems.includes(selected[i].getColumnMapping())) { + selectedItems.push(selected[i].getColumnMapping()); } else { var parent = selected[i].getParent(); - if (parent instanceof ColumnMappingNode) { - insert(selectedItems, parent.getColumnMapping()); + if (parent instanceof ColumnMappingNode && !selectedItems.includes(parent.getColumnMapping())) { + selectedItems.push(parent.getColumnMapping()); } } } @@ -197,5 +196,5 @@ const mappingToNode = function(mapping) { * @return {number} */ const sortMappings = function(a, b) { - return defaultCompare(a.getName(), b.getName()); + return defaultSort(a.getName(), b.getName()); }; diff --git a/src/os/ui/config/settingsmanager.js b/src/os/ui/config/settingsmanager.js index 9ea2a5bb1..c6c48555b 100644 --- a/src/os/ui/config/settingsmanager.js +++ b/src/os/ui/config/settingsmanager.js @@ -1,12 +1,12 @@ goog.declareModuleId('os.ui.config.SettingsManager'); +import {defaultSort} from '../../array/array.js'; import SlickTreeNode from '../slick/slicktreenode.js'; import SettingNode from './settingnode.js'; import SettingPlugin from './settingplugin.js'; import SettingsManagerEvent from './settingsmanagerevent.js'; import SettingsManagerEventType from './settingsmanagereventtype.js'; -const {defaultCompare} = goog.require('goog.array'); const EventTarget = goog.require('goog.events.EventTarget'); const log = goog.require('goog.log'); const Logger = goog.requireType('goog.log.Logger'); @@ -79,7 +79,7 @@ export default class SettingsManager extends EventTarget { if (children) { var sortedChildren = children.slice(); sortedChildren.sort(function(a, b) { - return defaultCompare(a.getLabel(), b.getLabel()); + return defaultSort(a.getLabel(), b.getLabel()); }); return sortedChildren; } diff --git a/src/os/ui/file/exportmanager.js b/src/os/ui/file/exportmanager.js index 44f132685..7014cecd1 100644 --- a/src/os/ui/file/exportmanager.js +++ b/src/os/ui/file/exportmanager.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.ui.file.ExportManager'); import AlertEventSeverity from '../../alert/alerteventseverity.js'; import AlertManager from '../../alert/alertmanager.js'; +import {defaultSort} from '../../array/array.js'; import Settings from '../../config/settings.js'; import DataManager from '../../data/datamanager.js'; import EventType from '../../events/eventtype.js'; @@ -11,7 +12,6 @@ import {getLocalUrl} from '../../file/index.js'; import ImportManager from '../im/importmanager.js'; import * as osWindow from '../window.js'; -const {defaultCompare} = goog.require('goog.array'); const dispose = goog.require('goog.dispose'); const EventTarget = goog.require('goog.events.EventTarget'); const log = goog.require('goog.log'); @@ -340,7 +340,7 @@ export default class ExportManager extends EventTarget { * @private */ static sortByLabel_(a, b) { - return defaultCompare(a.getLabel(), b.getLabel()); + return defaultSort(a.getLabel(), b.getLabel()); } /** diff --git a/src/os/ui/im/importmanager.js b/src/os/ui/im/importmanager.js index 4f65dcf2a..217f7e072 100644 --- a/src/os/ui/im/importmanager.js +++ b/src/os/ui/im/importmanager.js @@ -1,8 +1,9 @@ goog.declareModuleId('os.ui.im.ImportManager'); +import {defaultSort} from '../../array/array.js'; import Importer from '../../im/importer.js'; -const {defaultCompare, removeDuplicates} = goog.require('goog.array'); +const {removeDuplicates} = goog.require('goog.array'); const log = goog.require('goog.log'); const {forEach} = goog.require('goog.object'); @@ -207,10 +208,10 @@ export default class ImportManager { registerImportDetails(details, opt_isData) { if (opt_isData) { this.dataTypes_.push(details); - this.dataTypes_.sort(defaultCompare); + this.dataTypes_.sort(defaultSort); } else { this.details_.push(details); - this.details_.sort(defaultCompare); + this.details_.sort(defaultSort); } } diff --git a/src/os/ui/menu/menuitem.js b/src/os/ui/menu/menuitem.js index 633d52f2c..77355b77f 100644 --- a/src/os/ui/menu/menuitem.js +++ b/src/os/ui/menu/menuitem.js @@ -1,8 +1,9 @@ goog.declareModuleId('os.ui.menu.MenuItem'); +import {defaultSort} from '../../array/array.js'; import MenuItemType from './menuitemtype.js'; -const {defaultCompare, removeIf} = goog.require('goog.array'); +const {removeIf} = goog.require('goog.array'); const {default: MenuEvent} = goog.requireType('os.ui.menu.MenuEvent'); const {default: MenuItemOptions} = goog.requireType('os.ui.menu.MenuItemOptions'); @@ -280,6 +281,6 @@ export default class MenuItem { * @private */ static sort_(a, b) { - return defaultCompare(a.sort, b.sort) || defaultCompare(a.label, b.label); + return defaultSort(a.sort, b.sort) || defaultSort(a.label, b.label); } } diff --git a/src/os/ui/query/queryhandler.js b/src/os/ui/query/queryhandler.js index 69e3183f5..06cf93fc2 100644 --- a/src/os/ui/query/queryhandler.js +++ b/src/os/ui/query/queryhandler.js @@ -1,11 +1,12 @@ goog.declareModuleId('os.ui.query.QueryHandler'); +import {defaultSort} from '../../array/array.js'; import FilterEntry from '../../filter/filterentry.js'; import instanceOf from '../../instanceof.js'; import {getAreaManager, getFilterManager, getQueryManager} from '../../query/queryinstance.js'; const Disposable = goog.require('goog.Disposable'); -const {defaultCompare, removeDuplicates} = goog.require('goog.array'); +const {removeDuplicates} = goog.require('goog.array'); const {isEmptyOrWhitespace, makeSafe} = goog.require('goog.string'); const Feature = goog.requireType('ol.Feature'); @@ -360,7 +361,7 @@ export default class QueryHandler extends Disposable { var order1 = order[0] + 'Id'; entries.sort(function(a, b) { - return defaultCompare(a[order1], b[order1]); + return defaultSort(a[order1], b[order1]); }); var lastId = undefined; diff --git a/src/os/ui/search/facetedsearch.js b/src/os/ui/search/facetedsearch.js index de8082dc2..fc4220a7a 100644 --- a/src/os/ui/search/facetedsearch.js +++ b/src/os/ui/search/facetedsearch.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.ui.search.FacetedSearchCtrl'); +import {defaultSort} from '../../array/array.js'; import Settings from '../../config/settings.js'; import SearchEventType from '../../search/searcheventtype.js'; import TriState from '../../structs/tristate.js'; @@ -7,7 +8,7 @@ import SlickTreeNode from '../slick/slicktreenode.js'; import {apply} from '../ui.js'; import FacetNode from './facetnode.js'; -const {defaultCompare, sortObjectsByKey} = goog.require('goog.array'); +const {sortObjectsByKey} = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const {caseInsensitiveCompare} = goog.require('goog.string'); @@ -274,7 +275,7 @@ export default class Controller { } else if (ax === -1) { return 1; } else { - return defaultCompare(ax, bx); + return defaultSort(ax, bx); } } @@ -423,7 +424,7 @@ export default class Controller { * @private */ static sortResults_(a, b) { - return -1 * defaultCompare(a.getScore(), b.getScore()); + return -1 * defaultSort(a.getScore(), b.getScore()); } } diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index b0a2b4799..44a448fb2 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.ui.search.SearchBoxUI'); import '../dragdrop/dragdropui.js'; +import {defaultSort} from '../../array/array.js'; import Settings from '../../config/settings.js'; import * as dispatcher from '../../dispatcher.js'; import osImplements from '../../implements.js'; @@ -637,7 +638,7 @@ export class Controller { getSearchOptionsGroup(groupName) { const group = this['searchOptionsGroups'][groupName]; googArray.sort(group, function(a, b) { - return googArray.defaultCompare(a.getName(), b.getName()); + return defaultSort(a.getName(), b.getName()); }); return group; } diff --git a/src/os/ui/slick/column.js b/src/os/ui/slick/column.js index f9593b165..f8ec99e2a 100644 --- a/src/os/ui/slick/column.js +++ b/src/os/ui/slick/column.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.ui.slick.column'); +import {defaultSort} from '../../array/array.js'; import ColumnDefinition from '../../data/columndefinition.js'; import Menu from '../menu/menu.js'; import MenuItem from '../menu/menuitem.js'; @@ -9,7 +10,6 @@ import ColumnEventType from './columneventtype.js'; import ColumnMenuGroup from './columnmenugroup.js'; import {color as formatterColor} from './formatter.js'; -const {defaultCompare} = goog.require('goog.array'); const {numerateCompare} = goog.require('goog.string'); const {default: ColumnContext} = goog.requireType('os.ui.slick.ColumnContext'); @@ -133,7 +133,7 @@ export const autoSizeAndSortColumns = function(a, b) { var ao = ac ? ac.order : 0; var bo = bc ? bc.order : 0; - return defaultCompare(ao, bo); + return defaultSort(ao, bo); }; /** @@ -142,7 +142,7 @@ export const autoSizeAndSortColumns = function(a, b) { * @return {number} */ export const nameCompare = function(a, b) { - return defaultCompare(a['name'], b['name']); + return defaultSort(a['name'], b['name']); }; /** @@ -361,7 +361,7 @@ export const restore = function(from, to) { if (fa && fb) { // both columns are in the descriptor list, sort against their index - return defaultCompare(fa.index, fb.index); + return defaultSort(fa.index, fb.index); } else if (fa) { // only a was on the descriptor, sort it left return -1; diff --git a/src/os/ui/slick/slickgrid.js b/src/os/ui/slick/slickgrid.js index 547c1d72f..1b84f170d 100644 --- a/src/os/ui/slick/slickgrid.js +++ b/src/os/ui/slick/slickgrid.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.ui.slick.SlickGridUI'); import AlertEventSeverity from '../../alert/alerteventseverity.js'; import AlertManager from '../../alert/alertmanager.js'; +import {defaultSort} from '../../array/array.js'; import {killRightButton} from '../../events/events.js'; import {filterFalsey} from '../../fn/fn.js'; import osImplements from '../../implements.js'; @@ -22,7 +23,6 @@ import SlickGridEvent from './slickgridevent.js'; const Disposable = goog.require('goog.Disposable'); const Timer = goog.require('goog.Timer'); -const {defaultCompare, insert} = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const nextTick = goog.require('goog.async.nextTick'); const dispose = goog.require('goog.dispose'); @@ -547,7 +547,7 @@ export class Controller extends Disposable { var rows = this.getSelectedRows(); if (rows && rows.length) { // sort the selected rows, so items match the order in the view - rows = rows.slice().sort(defaultCompare); + rows = rows.slice().sort(defaultSort); // map rows to data items and filter out falsey values selected = rows.map(function(row) { @@ -835,8 +835,12 @@ export class Controller extends Disposable { var index = srcColumns.findIndex(findByField.bind(this, 'id', columns[i]['id'])); if (index > -1) { var targetIndex = j > index ? j - 1 : j; - insert(changed, srcColumns[index]); - insert(changed, srcColumns[targetIndex]); + if (!changed.includes(srcColumns[index])) { + changed.push(srcColumns[index]); + } + if (!changed.includes(srcColumns[targetIndex])) { + changed.push(srcColumns[targetIndex]); + } const columnToMove = srcColumns.splice(index, 1)[0]; srcColumns.splice(targetIndex, 0, columnToMove); } @@ -1403,7 +1407,7 @@ export class Controller extends Disposable { } if (result == undefined) { - // inlined defaultCompare to avoid the function call + // inlined defaultSort to avoid the function call result = (v1 > v2 ? 1 : v1 < v2 ? -1 : 0) * sign; } diff --git a/src/os/ui/slick/treesearch.js b/src/os/ui/slick/treesearch.js index 7cc249518..31bebfe02 100644 --- a/src/os/ui/slick/treesearch.js +++ b/src/os/ui/slick/treesearch.js @@ -1,12 +1,12 @@ goog.declareModuleId('os.ui.slick.TreeSearch'); +import {defaultSort} from '../../array/array.js'; import ISearchable from '../../data/isearchable.js'; import osImplements from '../../implements.js'; import {merge} from '../../object/object.js'; import SlickTreeNode from './slicktreenode.js'; const Disposable = goog.require('goog.Disposable'); -const {defaultCompare} = goog.require('goog.array'); const {numerateCompare, regExpEscape} = goog.require('goog.string'); const {default: INodeGroupBy} = goog.requireType('os.data.groupby.INodeGroupBy'); @@ -392,7 +392,7 @@ export default class TreeSearch extends Disposable { * @return {number} */ static idCompare(a, b) { - return defaultCompare(a.getId(), b.getId()); + return defaultSort(a.getId(), b.getId()); } /** @@ -441,7 +441,7 @@ export default class TreeSearch extends Disposable { var val = numerateCompare(/** @type {string} */ (a.getLabel()), /** @type {string} */ (b.getLabel())); if (val === 0) { - val = defaultCompare(a.getId(), b.getId()); // lexicographic sort + val = defaultSort(a.getId(), b.getId()); // lexicographic sort } return val; diff --git a/src/os/ui/timeline/offarrows.js b/src/os/ui/timeline/offarrows.js index 15bb1dafd..85691ece6 100644 --- a/src/os/ui/timeline/offarrows.js +++ b/src/os/ui/timeline/offarrows.js @@ -1,10 +1,10 @@ goog.declareModuleId('os.ui.timeline.OffArrows'); +import {defaultSort} from '../../array/array.js'; import PropertyChangeEvent from '../../events/propertychangeevent.js'; import BaseItem from './baseitem.js'; import * as timelineUi from './timeline.js'; -const googArray = goog.require('goog.array'); const GoogEventType = goog.require('goog.events.EventType'); const olExtent = goog.require('ol.extent'); @@ -229,7 +229,7 @@ export default class OffArrows extends BaseItem { * @private */ static compareLeft_(a, b) { - return googArray.defaultCompare(a.getExtent()[0], b.getExtent()[0]); + return defaultSort(a.getExtent()[0], b.getExtent()[0]); } /** @@ -242,6 +242,6 @@ export default class OffArrows extends BaseItem { */ static compareRight_(a, b) { // this is flipped because we mirror the right group to flip the arrows - return -1 * googArray.defaultCompare(a.getExtent()[1], b.getExtent()[1]); + return -1 * defaultSort(a.getExtent()[1], b.getExtent()[1]); } } diff --git a/src/plugin/descriptor/descriptorsearch.js b/src/plugin/descriptor/descriptorsearch.js index 05bc43301..713710d8d 100644 --- a/src/plugin/descriptor/descriptorsearch.js +++ b/src/plugin/descriptor/descriptorsearch.js @@ -1,5 +1,6 @@ goog.declareModuleId('plugin.descriptor.DescriptorSearch'); +import {defaultSort} from '../../os/array/array.js'; import DataManager from '../../os/data/datamanager.js'; import osImplements from '../../os/implements.js'; import AbstractSearch from '../../os/search/abstractsearch.js'; @@ -150,7 +151,7 @@ export default class DescriptorSearch extends AbstractSearch { } googArray.sort(results, function(a, b) { - return googArray.defaultCompare(b.getScore(), a.getScore()); + return defaultSort(b.getScore(), a.getScore()); }); if (promises.length) { diff --git a/src/plugin/vectortools/vectortools.js b/src/plugin/vectortools/vectortools.js index 18c0b7719..5440a6508 100644 --- a/src/plugin/vectortools/vectortools.js +++ b/src/plugin/vectortools/vectortools.js @@ -1,5 +1,6 @@ goog.declareModuleId('plugin.vectortools'); +import {defaultSort} from '../../os/array/array.js'; import ColumnMappingManager from '../../os/column/columnmappingmanager.js'; import DataManager from '../../os/data/datamanager.js'; import RecordField from '../../os/data/recordfield.js'; @@ -12,7 +13,6 @@ import VectorSource from '../../os/source/vectorsource.js'; import StyleType from '../../os/style/styletype.js'; import Options from './options.js'; -const googArray = goog.require('goog.array'); const googString = goog.require('goog.string'); const Feature = goog.requireType('ol.Feature'); @@ -175,7 +175,7 @@ export const getColumnMappings = function(sourceIds) { var sortColumns = function(a, b) { var ai = filterKeys.indexOf(a['layer']); var bi = filterKeys.indexOf(b['layer']); - return googArray.defaultCompare(ai, bi); + return defaultSort(ai, bi); }; /** diff --git a/test/os/structs/arraycollection.test.js b/test/os/structs/arraycollection.test.js index 0df56512f..fea2414a3 100644 --- a/test/os/structs/arraycollection.test.js +++ b/test/os/structs/arraycollection.test.js @@ -1,12 +1,12 @@ -goog.require('goog.array'); goog.require('goog.structs'); +goog.require('os.array'); goog.require('os.structs.ArrayCollection'); goog.require('os.structs.EventType'); describe('os.structs.ArrayCollection', function() { - const googArray = goog.module.get('goog.array'); const {default: ArrayCollection} = goog.module.get('os.structs.ArrayCollection'); const {default: EventType} = goog.module.get('os.structs.EventType'); + const {defaultSort} = goog.module.get('os.array'); /** * Mock filter function for unit tests @@ -104,9 +104,9 @@ describe('os.structs.ArrayCollection', function() { it('should properly handle a sort added later', function() { var c = new ArrayCollection([3, 2, 1]); - c.setSort(googArray.defaultCompare); + c.setSort(defaultSort); expect(c.sortChanged_).toBe(true); - expect(c.getSort()).toBe(googArray.defaultCompare); + expect(c.getSort()).toBe(defaultSort); c.refresh(); expect(c.sortChanged_).toBe(false); @@ -117,7 +117,7 @@ describe('os.structs.ArrayCollection', function() { it('should keep items sorted when added with a sort', function() { var c = new ArrayCollection([1, 3, 5]); - c.setSort(googArray.defaultCompare); + c.setSort(defaultSort); c.refresh(); c.add(2); @@ -126,7 +126,7 @@ describe('os.structs.ArrayCollection', function() { it('should remove via binary search with a sort', function() { var c = new ArrayCollection([3, 2, 1]); - c.setSort(googArray.defaultCompare); + c.setSort(defaultSort); c.refresh(); c.remove(2); @@ -135,7 +135,7 @@ describe('os.structs.ArrayCollection', function() { it('should find the proper index with a sort', function() { var c = new ArrayCollection([3, 2, 1]); - c.setSort(googArray.defaultCompare); + c.setSort(defaultSort); c.refresh(); expect(c.getItemIndex(3)).toBe(2); @@ -200,7 +200,7 @@ describe('os.structs.ArrayCollection', function() { it('should properly handle both a filter and a sort added later', function() { var c = new ArrayCollection([4, 3, 2, 1]); - c.setSort(googArray.defaultCompare); + c.setSort(defaultSort); c.setFilter(mockFilter); c.refresh(); @@ -213,7 +213,7 @@ describe('os.structs.ArrayCollection', function() { it('should properly handle adding items with both a filter and a sort', function() { var c = new ArrayCollection(); - c.setSort(googArray.defaultCompare); + c.setSort(defaultSort); c.setFilter(mockFilter); c.refresh(); @@ -234,7 +234,7 @@ describe('os.structs.ArrayCollection', function() { it('should properly handle removing items with both a filter and a sort', function() { var c = new ArrayCollection([4, 3, 2, 1]); - c.setSort(googArray.defaultCompare); + c.setSort(defaultSort); c.setFilter(mockFilter); c.refresh(); @@ -254,7 +254,7 @@ describe('os.structs.ArrayCollection', function() { it('should find the proper index with both a filter and a sort', function() { var c = new ArrayCollection([4, 3, 2, 1]); - c.setSort(googArray.defaultCompare); + c.setSort(defaultSort); c.setFilter(mockFilter); c.refresh(); From 4dadc78fdc71488e89c568d20b67c6fe6d3fc192 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 09:10:52 -0700 Subject: [PATCH 14/23] feat(goog): remove goog.array.filter --- src/os/arraybuf.js | 2 -- src/os/config/themesettings.js | 3 +-- src/os/data/histo/colormodel.js | 3 +-- src/os/data/xf/datamodel.js | 3 +-- src/os/time/xf/timemodel.js | 5 ++--- src/os/xml.js | 3 +-- src/plugin/featureaction/ui/featurestyleactionconfig.js | 5 ++--- src/plugin/file/kml/kmlnodelayerui.js | 5 ++--- 8 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/os/arraybuf.js b/src/os/arraybuf.js index a09ef76ed..91625d612 100644 --- a/src/os/arraybuf.js +++ b/src/os/arraybuf.js @@ -1,7 +1,5 @@ goog.declareModuleId('os.arraybuf'); -goog.require('goog.array'); - /** * The Byte Order Marker (BOM) sequence. diff --git a/src/os/config/themesettings.js b/src/os/config/themesettings.js index 5363f0ebf..ba55a308d 100644 --- a/src/os/config/themesettings.js +++ b/src/os/config/themesettings.js @@ -9,7 +9,6 @@ import ThemeSettingsChangeEvent from './themesettingschangeevent.js'; import {directiveTag as settingsUi} from './themesettingsui.js'; const Promise = goog.require('goog.Promise'); -const {filter} = goog.require('goog.array'); const ConditionalDelay = goog.require('goog.async.ConditionalDelay'); const GoogEvent = goog.require('goog.events.Event'); const {findValue} = goog.require('goog.object'); @@ -201,7 +200,7 @@ export default class ThemeSettings extends SettingPlugin { // Get the current theme(s) var themeRegEx = /(themes\/).*?(\..*\.css)/; var stylesheets = $('[rel=stylesheet]'); - var ourThemes = filter(stylesheets, function(el) { + var ourThemes = Array.from(stylesheets).filter(function(el) { return themeRegEx.test(el.href); }); diff --git a/src/os/data/histo/colormodel.js b/src/os/data/histo/colormodel.js index 167397979..4c403890e 100644 --- a/src/os/data/histo/colormodel.js +++ b/src/os/data/histo/colormodel.js @@ -11,7 +11,6 @@ import RecordField from '../recordfield.js'; import ColorMethod from './colormethod.js'; import * as osDataHisto from './histogramutils.js'; -const googArray = goog.require('goog.array'); const EventTarget = goog.require('goog.events.EventTarget'); const GoogEventType = goog.require('goog.events.EventType'); const googObject = goog.require('goog.object'); @@ -332,7 +331,7 @@ export default class ColorModel extends EventTarget { var bins = this.getResults(); if (this.hasManualColors()) { // exclude any manually-colored bins from the autocolor - bins = googArray.filter(bins, function(bin) { + bins = bins.filter(function(bin) { return !this.manualBinColors_[bin.getLabel()]; }, this); } diff --git a/src/os/data/xf/datamodel.js b/src/os/data/xf/datamodel.js index 9055ab480..91e5f75e7 100644 --- a/src/os/data/xf/datamodel.js +++ b/src/os/data/xf/datamodel.js @@ -3,7 +3,6 @@ goog.declareModuleId('os.data.xf.DataModel'); import PropertyChangeEvent from '../../events/propertychangeevent.js'; import PropertyChange from './propertychange.js'; -const googArray = goog.require('goog.array'); const EventTarget = goog.require('goog.events.EventTarget'); const log = goog.require('goog.log'); const googObject = goog.require('goog.object'); @@ -395,7 +394,7 @@ export default class DataModel extends EventTarget { var results = /** @type {!Array} */ (opt_bottom ? dim.bottom(opt_value) : dim.top(opt_value)); if (this.filterFunction) { - results = googArray.filter(results, this.filterFunction, this); + results = results.filter(this.filterFunction, this); } return results; diff --git a/src/os/time/xf/timemodel.js b/src/os/time/xf/timemodel.js index 52dcc8fb0..4f0493b7d 100644 --- a/src/os/time/xf/timemodel.js +++ b/src/os/time/xf/timemodel.js @@ -9,7 +9,6 @@ import TimeInstant from '../timeinstant.js'; import TimelineController from '../timelinecontroller.js'; import TimeRange from '../timerange.js'; -const googArray = goog.require('goog.array'); const functions = goog.require('goog.functions'); const log = goog.require('goog.log'); const googObject = goog.require('goog.object'); @@ -441,7 +440,7 @@ export default class TimeModel extends DataModel { } if (this.filterFunction) { - results = googArray.filter(results, this.filterFunction, this); + results = results.filter(this.filterFunction, this); } this.lastRange = range; @@ -509,7 +508,7 @@ export default class TimeModel extends DataModel { var results = /** @type {!Array} */ (opt_bottom ? dim.bottom(opt_value) : dim.top(opt_value)); if (this.filterFunction) { - results = googArray.filter(results, this.filterFunction, this); + results = results.filter(this.filterFunction, this); } return results; diff --git a/src/os/xml.js b/src/os/xml.js index d8c4ca6fd..e46fd252c 100644 --- a/src/os/xml.js +++ b/src/os/xml.js @@ -1,6 +1,5 @@ goog.declareModuleId('os.xml'); -const googArray = goog.require('goog.array'); const dom = goog.require('goog.dom'); const NodeType = goog.require('goog.dom.NodeType'); const googDomXml = goog.require('goog.dom.xml'); @@ -153,7 +152,7 @@ export const createElementNS = function(tag, nsUri, opt_doc, opt_content, opt_at */ export const getChildrenByTagName = function(element, tag) { var children = dom.getChildren(element); - return googArray.filter(children, function(node) { + return Array.from(children).filter(function(node) { return node.localName == tag; }); }; diff --git a/src/plugin/featureaction/ui/featurestyleactionconfig.js b/src/plugin/featureaction/ui/featurestyleactionconfig.js index f5781d8b7..217c8d407 100644 --- a/src/plugin/featureaction/ui/featurestyleactionconfig.js +++ b/src/plugin/featureaction/ui/featurestyleactionconfig.js @@ -19,7 +19,6 @@ import VectorStyleControlsEventType from '../../../os/ui/layer/vectorstylecontro import Module from '../../../os/ui/module.js'; import ActionConfigCtrl from './featureactionconfig.js'; -const googArray = goog.require('goog.array'); const googObject = goog.require('goog.object'); const googString = goog.require('goog.string'); @@ -190,8 +189,8 @@ export class Controller extends ActionConfigCtrl { source = /** @type {!VectorSource} */ (source); var shapes = googObject.getKeys(osStyle.SHAPES); - this.scope['shapes'] = googArray.filter(shapes, source.supportsShape, source); - this.scope['centerShapes'] = googArray.filter(shapes, source.isNotEllipseOrLOBOrDefault, source); + this.scope['shapes'] = shapes.filter(source.supportsShape, source); + this.scope['centerShapes'] = shapes.filter(source.isNotEllipseOrLOBOrDefault, source); this.scope['columns'] = layer.getColumnsFromSource(source); // autodetect diff --git a/src/plugin/file/kml/kmlnodelayerui.js b/src/plugin/file/kml/kmlnodelayerui.js index fd3c475b7..c6cf128fe 100644 --- a/src/plugin/file/kml/kmlnodelayerui.js +++ b/src/plugin/file/kml/kmlnodelayerui.js @@ -39,7 +39,6 @@ import * as kml from '../../../os/ui/file/kml/kml.js'; import {Controller as VectorLayerUICtrl, directive as vectorLayerUIDirective} from '../../../os/ui/layer/vectorlayerui.js'; import Module from '../../../os/ui/module.js'; -const googArray = goog.require('goog.array'); const olArray = goog.require('ol.array'); const UrlTile = goog.require('ol.source.UrlTile'); @@ -357,7 +356,7 @@ export class Controller extends VectorLayerUICtrl { for (var i = 0, n = items.length; i < n; i++) { var source = items[i].getSource(); if (source && source instanceof VectorSource) { - shapes = googArray.filter(shapes, source.supportsShape, source); + shapes = shapes.filter(source.supportsShape, source); } } } @@ -395,7 +394,7 @@ export class Controller extends VectorLayerUICtrl { for (var i = 0, n = items.length; i < n; i++) { var source = items[i].getSource(); if (source && source instanceof VectorSource) { - shapes = googArray.filter(shapes, source.supportsShape, source); + shapes = shapes.filter(source.supportsShape, source); } } } From 2aaaeed877b0c8a2c2939f683638ded997bb00ee Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 10:17:36 -0700 Subject: [PATCH 15/23] feat(goog): remove more goog.array.equals --- src/os/style/style.js | 4 ++-- src/os/ui/multiurlproviderimport.js | 4 +--- src/os/ui/query/area/userarea.js | 9 +++++++-- src/os/ui/sourcegrid.js | 15 +++------------ test/os/ogc/wmts/wmtslayerparserv100.test.js | 11 ++++++----- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/os/style/style.js b/src/os/style/style.js index ba3af6050..ac1e9ba04 100644 --- a/src/os/style/style.js +++ b/src/os/style/style.js @@ -21,7 +21,6 @@ import StyleManager from './stylemanager.js'; import StyleType from './styletype.js'; -const {equals} = goog.require('goog.array'); const {toRadians} = goog.require('goog.math'); const {asArray, asString, toString} = goog.require('ol.color'); @@ -864,7 +863,8 @@ export const dashPatternToOptions = function(pattern) { if (Array.isArray(pattern)) { for (var i = 0; i < LINE_STYLE_OPTIONS.length; i++) { var lineDashOption = /** @type {styleLineDashOption} */ (LINE_STYLE_OPTIONS[i]); - if (equals(lineDashOption.pattern, pattern)) { + if (lineDashOption.pattern.length === pattern.length && + lineDashOption.pattern.every((el, i) => el === pattern[i])) { return lineDashOption; } } diff --git a/src/os/ui/multiurlproviderimport.js b/src/os/ui/multiurlproviderimport.js index 570ede7aa..ce25aace4 100644 --- a/src/os/ui/multiurlproviderimport.js +++ b/src/os/ui/multiurlproviderimport.js @@ -3,8 +3,6 @@ goog.declareModuleId('os.ui.MultiUrlProviderImportCtrl'); import './uniqueserverurl.js'; import SingleUrlProviderImportCtrl from './singleurlproviderimport.js'; -const {equals} = goog.require('goog.array'); - const {default: AbstractLoadingServer} = goog.requireType('os.ui.server.AbstractLoadingServer'); @@ -75,7 +73,7 @@ export default class Controller extends SingleUrlProviderImportCtrl { var originals = this.getAlternateUrls(); if (alternateUrls && originals) { // both defined, so compare the URLs - if (!equals(alternateUrls, originals)) { + if (alternateUrls.length !== originals.length || originals.some((el, i) => el !== alternateUrls[i])) { return true; } } else if (alternateUrls != originals) { diff --git a/src/os/ui/query/area/userarea.js b/src/os/ui/query/area/userarea.js index d602eefea..88e248c51 100644 --- a/src/os/ui/query/area/userarea.js +++ b/src/os/ui/query/area/userarea.js @@ -24,7 +24,6 @@ import {close} from '../../window.js'; import WindowEventType from '../../windoweventtype.js'; const Disposable = goog.require('goog.Disposable'); -const {equals} = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const dispose = goog.require('goog.dispose'); const {getDocument} = goog.require('goog.dom'); @@ -691,7 +690,13 @@ export class Controller extends Disposable { }, this).filter(filterFalsey); if (coords.length > 2) { - if (!equals(coords[0], coords[coords.length - 1])) { + var sameCoord = coords[0].length == coords[coords.length - 1].length; + for (let i = 0; i < coords[0].length; i++) { + if (coords[0][i] !== coords[coords.length - 1][i]) { + sameCoord = false; + } + } + if (!sameCoord) { coords.push(coords[0]); } diff --git a/src/os/ui/sourcegrid.js b/src/os/ui/sourcegrid.js index b71ed1584..c56edb184 100644 --- a/src/os/ui/sourcegrid.js +++ b/src/os/ui/sourcegrid.js @@ -16,7 +16,6 @@ import ColumnMenuGroup from './slick/columnmenugroup.js'; import * as formatter from './slick/formatter.js'; import {Controller as SlickGridCtrl} from './slick/slickgrid.js'; -const {equals} = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const dispose = goog.require('goog.dispose'); const GoogEventType = goog.require('goog.events.EventType'); @@ -526,6 +525,7 @@ export class Controller extends SlickGridCtrl { /** * @inheritDoc + * @suppress {checkTypes} To avoid [] access on a struct. */ onGridSelectedChange(e, args) { if (!this.inEvent && this.source) { @@ -536,17 +536,8 @@ export class Controller extends SlickGridCtrl { // only update the source if the user interacted with the grid if (this.inInteraction) { var result = rows.map(this.mapRowsToItems, this); - var equal = equals(result, this.source.getSelectedItems(), - /** - * Compare feature id's. - * @param {Feature} a First feature. - * @param {Feature} b Second feature. - * @return {boolean} If the id's are the same. - * @suppress {checkTypes} To avoid [] access on a struct. - */ - function(a, b) { - return a['id'] == b['id']; - }); + var equal = result.length == this.source.getSelectedItems().length && + result.every((el, i) => el['id'] == this.source.getSelectedItems()[i]['id']); if (!equal) { // only update the selection if it changed diff --git a/test/os/ogc/wmts/wmtslayerparserv100.test.js b/test/os/ogc/wmts/wmtslayerparserv100.test.js index 7e3438bbb..7aac84e41 100644 --- a/test/os/ogc/wmts/wmtslayerparserv100.test.js +++ b/test/os/ogc/wmts/wmtslayerparserv100.test.js @@ -1,4 +1,3 @@ -goog.require('goog.array'); goog.require('goog.dom.xml'); goog.require('goog.object'); goog.require('ol.format.WMTSCapabilities'); @@ -9,7 +8,6 @@ goog.require('os.ogc.wmts.WMTSLayerParserV100'); goog.require('os.ui.ogc.OGCDescriptor'); describe('os.ogc.wmts.WMTSLayerParserV100', () => { - const {equals: arrayEquals} = goog.module.get('goog.array'); const {loadXml} = goog.module.get('goog.dom.xml'); const {isEmpty: isObjectEmpty} = goog.module.get('goog.object'); const WMTSCapabilities = goog.module.get('ol.format.WMTSCapabilities'); @@ -72,7 +70,8 @@ describe('os.ogc.wmts.WMTSLayerParserV100', () => { expect(descriptor.getDescription()).toBe('Description of WMTS 3857 Layer 1.'); expect(descriptor.getWmtsDateFormat()).toBeNull(); expect(descriptor.getWmtsTimeFormat()).toBeNull(); - expect(arrayEquals(descriptor.getBBox(), expectedBbox3857)).toBe(true); + expect(descriptor.getBBox().length === expectedBbox3857.length && + descriptor.getBBox().every((el, i) => el === expectedBbox3857[i])).toBe(true); wmtsOptions = descriptor.getWmtsOptions(); expect(wmtsOptions.length).toBe(1); @@ -89,7 +88,8 @@ describe('os.ogc.wmts.WMTSLayerParserV100', () => { expect(descriptor.getDescription()).toBeNull(); expect(descriptor.getWmtsDateFormat()).toBeNull(); expect(descriptor.getWmtsTimeFormat()).toBeNull(); - expect(arrayEquals(descriptor.getBBox(), expectedBbox3857)).toBe(true); + expect(descriptor.getBBox().length === expectedBbox3857.length && + descriptor.getBBox().every((el, i) => el === expectedBbox3857[i])).toBe(true); wmtsOptions = descriptor.getWmtsOptions(); expect(wmtsOptions.length).toBe(1); @@ -106,7 +106,8 @@ describe('os.ogc.wmts.WMTSLayerParserV100', () => { expect(descriptor.getDescription()).toBe('Description of WMTS 4326 Layer 1.'); expect(descriptor.getWmtsDateFormat()).toBe('YYYY-MM-DD'); expect(descriptor.getWmtsTimeFormat()).toBe('{start}'); - expect(arrayEquals(descriptor.getBBox(), expectedBbox4326)).toBe(true); + expect(descriptor.getBBox().length === expectedBbox4326.length && + descriptor.getBBox().every((el, i) => el === expectedBbox4326[i])).toBe(true); wmtsOptions = descriptor.getWmtsOptions(); expect(wmtsOptions.length).toBe(1); From 620f18b4c9b183b20b2fe3a867876bada5eec1f6 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 10:41:11 -0700 Subject: [PATCH 16/23] feat(goog): remove goog.array.some --- src/os/command/commandprocessor.js | 3 +-- src/os/data/datamanager.js | 3 +-- src/os/ui/query/basicqueryreader.js | 3 +-- src/os/ui/search/searchbox.js | 2 +- test/os/data/fileprovider.test.js | 8 +++----- test/os/net/request.test.js | 2 -- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/os/command/commandprocessor.js b/src/os/command/commandprocessor.js index d2366fc02..3c5000aad 100644 --- a/src/os/command/commandprocessor.js +++ b/src/os/command/commandprocessor.js @@ -4,7 +4,6 @@ import CommandEvent from './commandevent.js'; import EventType from './eventtype.js'; import State from './state.js'; -const googArray = goog.require('goog.array'); const dispose = goog.require('goog.dispose'); const GoogEvent = goog.require('goog.events.Event'); const EventTarget = goog.require('goog.events.EventTarget'); @@ -88,7 +87,7 @@ export default class CommandProcessor extends EventTarget { * @return {boolean} */ isProcessing() { - return this.current_ != this.target_ || googArray.some(this.history_, function(cmd) { + return this.current_ != this.target_ || this.history_.some(function(cmd) { return cmd.state === State.EXECUTING; }); } diff --git a/src/os/data/datamanager.js b/src/os/data/datamanager.js index 3791eee8f..e6fa65df7 100644 --- a/src/os/data/datamanager.js +++ b/src/os/data/datamanager.js @@ -28,7 +28,6 @@ import IDataManager from './idatamanager.js';// eslint-disable-line import IUrlDescriptor from './iurldescriptor.js'; import PropertyChange from './propertychange.js'; -const googArray = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const EventTarget = goog.require('goog.events.EventTarget'); const GoogEventType = goog.require('goog.events.EventType'); @@ -543,7 +542,7 @@ export default class DataManager extends EventTarget { hasError() { var providers = /** @type {Array} */ (this.providerRoot_.getChildren()); if (providers) { - return googArray.some(providers, function(p) { + return providers.some(function(p) { return p.getEnabled() && p.getError(); }); } diff --git a/src/os/ui/query/basicqueryreader.js b/src/os/ui/query/basicqueryreader.js index 01d9b5c21..0cc7bbd28 100644 --- a/src/os/ui/query/basicqueryreader.js +++ b/src/os/ui/query/basicqueryreader.js @@ -9,7 +9,6 @@ import {unescape as xmlUnescape} from '../../xml.js'; import {OPERATIONS} from '../filter/filter.js'; import AbstractQueryReader from './abstractqueryreader.js'; -const {some} = goog.require('goog.array'); const {assert} = goog.require('goog.asserts'); const {assertIsElement} = goog.require('goog.asserts.dom'); const {getChildren, getFirstElementChild, getNextElementSibling, getParentElement} = goog.require('goog.dom'); @@ -74,7 +73,7 @@ export default class BasicQueryReader extends AbstractQueryReader { if (!isFilter) { // if any of the children match any of the ops, then ele is a filter entry - isFilter = some(children, function(item) { + isFilter = Array.from(children).some(function(item) { return OPERATIONS.some(function(op) { return op.matches(angular.element(item)); }); diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index 44a448fb2..0b60af18d 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -690,7 +690,7 @@ export class Controller { * @export */ hasDisabledSearch() { - return googArray.some(this['searchOptions'], function(search) { + return this['searchOptions'].some(function(search) { return !search.isEnabled(); }); } diff --git a/test/os/data/fileprovider.test.js b/test/os/data/fileprovider.test.js index f54ff2b4d..4ef2c3a6b 100644 --- a/test/os/data/fileprovider.test.js +++ b/test/os/data/fileprovider.test.js @@ -1,4 +1,3 @@ -goog.require('goog.array'); goog.require('os.data.BaseDescriptor'); goog.require('os.data.DataManager'); goog.require('os.data.FileDescriptor'); @@ -6,7 +5,6 @@ goog.require('os.data.FileProvider'); goog.require('os.mock'); describe('os.data.FileProvider', function() { - const googArray = goog.module.get('goog.array'); const {default: BaseDescriptor} = goog.module.get('os.data.BaseDescriptor'); const {default: DataManager} = goog.module.get('os.data.DataManager'); const {default: FileDescriptor} = goog.module.get('os.data.FileDescriptor'); @@ -35,13 +33,13 @@ describe('os.data.FileProvider', function() { p.load(false); expect(p.getChildren().length).toBe(2); - expect(googArray.some(p.getChildren(), function(node) { + expect(p.getChildren().some(function(node) { return node.getDescriptor() == desc1; })).toBe(true); - expect(googArray.some(p.getChildren(), function(node) { + expect(p.getChildren().some(function(node) { return node.getDescriptor() == desc2; })).toBe(true); - expect(googArray.some(p.getChildren(), function(node) { + expect(p.getChildren().some(function(node) { return node.getDescriptor() == desc3; })).toBe(false); }); diff --git a/test/os/net/request.test.js b/test/os/net/request.test.js index a0819ce0f..52b76f91f 100644 --- a/test/os/net/request.test.js +++ b/test/os/net/request.test.js @@ -1,7 +1,5 @@ goog.require('goog.Uri'); -goog.require('goog.array'); goog.require('goog.net.EventType'); -goog.require('ol.array'); goog.require('os.net'); goog.require('os.net.ExtDomainHandler'); goog.require('os.net.MockModifier'); From 9b2665898f08ed16fba1f592004e19322c1fa8a3 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 10:57:25 -0700 Subject: [PATCH 17/23] feat(goog): remove goog.array.removeDuplicates --- src/os/filter/basefiltermanager.js | 2 +- src/os/object/object.js | 2 +- src/os/source/vectorsource.js | 5 +++-- src/os/ui/areas.js | 3 ++- src/os/ui/ex/areaexportdialog.js | 2 +- src/os/ui/im/action/filteractionsui.js | 5 ++--- src/os/ui/im/importmanager.js | 5 ++--- src/os/ui/menu/filtermenu.js | 2 +- src/os/ui/ogc/ogcserver.js | 2 +- src/os/ui/query/queryhandler.js | 5 ++--- src/os/ui/search/searchbox.js | 4 ++-- src/os/user/settings/favoritemanager.js | 8 ++++---- src/plugin/places/places.js | 2 +- 13 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/os/filter/basefiltermanager.js b/src/os/filter/basefiltermanager.js index 181460cfc..ad6fb6321 100644 --- a/src/os/filter/basefiltermanager.js +++ b/src/os/filter/basefiltermanager.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.filter.BaseFilterManager'); import AlertEventSeverity from '../alert/alerteventseverity.js'; import AlertManager from '../alert/alertmanager.js'; +import {removeDuplicates} from '../array/array.js'; import CommandProcessor from '../command/commandprocessor.js'; import Settings from '../config/settings.js'; import DataManager from '../data/datamanager.js'; @@ -20,7 +21,6 @@ import cloneToContext from './clonetocontext.js'; import FilterEntry from './filterentry.js'; import FilterType from './filtertype.js'; -const {removeDuplicates} = goog.require('goog.array'); const EventTarget = goog.require('goog.events.EventTarget'); const googObject = goog.require('goog.object'); const googString = goog.require('goog.string'); diff --git a/src/os/object/object.js b/src/os/object/object.js index 27bb23628..277cb1e8f 100644 --- a/src/os/object/object.js +++ b/src/os/object/object.js @@ -266,7 +266,7 @@ export const getFirstValue = function(key, var_args) { * Creates a value extractor function. Use the provided attribute to retrieve a value from an item. Useful * for collection iterators and such to extract values of their records. * - * Example: googArray.removeDuplicates(arrWithElementsWithIds, newArr, os.object.getValueExtractor('id')); + * Example: os.array.removeDuplicates(arrWithElementsWithIds, newArr, os.object.getValueExtractor('id')); * * @param {!string} attribute The attribute whose value to retrieve from an item. If the attribute name references * a function, it is invoked on the item. diff --git a/src/os/source/vectorsource.js b/src/os/source/vectorsource.js index 5aad5ed68..691a99c1b 100644 --- a/src/os/source/vectorsource.js +++ b/src/os/source/vectorsource.js @@ -5,6 +5,7 @@ import '../mixin/rbushmixin.js'; import EventType from '../action/eventtype.js'; import AlertEventSeverity from '../alert/alerteventseverity.js'; import AlertManager from '../alert/alertmanager.js'; +import {removeDuplicates} from '../array/array.js'; import {registerClass} from '../classregistry.js'; import {toHexString} from '../color.js'; import ColumnDefinition from '../data/columndefinition.js'; @@ -59,7 +60,7 @@ import SourceClass from './sourceclass.js'; import * as sourceColumn from './sourcecolumn.js'; const Timer = goog.require('goog.Timer'); -const {binaryInsert, binaryRemove, removeDuplicates} = goog.require('goog.array'); +const {binaryInsert, binaryRemove} = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const nextTick = goog.require('goog.async.nextTick'); const dispose = goog.require('goog.dispose'); @@ -889,7 +890,7 @@ export default class Vector extends OLVectorSource { if (this.columns) { // remove any duplicates var colByName = /** @type {function((ColumnDefinition|string)):string} */ (getValueExtractor('name')); - removeDuplicates(this.columns, this.columns, colByName); + removeDuplicates(this.columns, undefined, colByName); var descriptor = DataManager.getInstance().getDescriptor(this.getId()); if (descriptor) { diff --git a/src/os/ui/areas.js b/src/os/ui/areas.js index be3300fd4..db5b0ebcf 100644 --- a/src/os/ui/areas.js +++ b/src/os/ui/areas.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.ui.AreasUI'); import './dragdrop/urldragdropui.js'; import AlertManager from '../alert/alertmanager.js'; +import {removeDuplicates} from '../array/array.js'; import AreaNode from '../data/areanode.js'; import AreaTreeSearch from '../data/areatreesearch.js'; import SourceGroupBy from '../data/groupby/sourcegroupby.js'; @@ -19,7 +20,7 @@ import Module from './module.js'; import * as CombinatorUI from './query/combinator.js'; import AbstractGroupByTreeSearchCtrl from './slick/abstractgroupbytreesearchctrl.js'; -const {flatten, removeDuplicates} = goog.require('goog.array'); +const {flatten} = goog.require('goog.array'); const GoogEventType = goog.require('goog.events.EventType'); const GoogEvent = goog.requireType('goog.events.Event'); diff --git a/src/os/ui/ex/areaexportdialog.js b/src/os/ui/ex/areaexportdialog.js index d36c143f4..c43e6aa2a 100644 --- a/src/os/ui/ex/areaexportdialog.js +++ b/src/os/ui/ex/areaexportdialog.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.ui.ex.AreaExportUI'); import KMLExporter from '../../../plugin/file/kml/kmlexporter.js'; import SHPExporter from '../../../plugin/file/shp/shpexporter.js'; +import {removeDuplicates} from '../../array/array.js'; import {METHOD_FIELD} from '../../interpolate.js'; import {DEFAULT_VECTOR_CONFIG, setFeatureStyle} from '../../style/style.js'; import StyleType from '../../style/styletype.js'; @@ -9,7 +10,6 @@ import {Controller as ExportDialogCtrl, directive as exportDialogDirective} from import Module from '../module.js'; import {create as createWindow} from '../window.js'; -const {removeDuplicates} = goog.require('goog.array'); const {default: ExportOptions} = goog.requireType('os.ex.ExportOptions'); const {default: VectorSource} = goog.requireType('os.source.Vector'); diff --git a/src/os/ui/im/action/filteractionsui.js b/src/os/ui/im/action/filteractionsui.js index 5da02f954..d707ee7f3 100644 --- a/src/os/ui/im/action/filteractionsui.js +++ b/src/os/ui/im/action/filteractionsui.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.ui.im.action.FilterActionsCtrl'); +import {removeDuplicates} from '../../../array/array.js'; import CommandProcessor from '../../../command/commandprocessor.js'; import * as dispatcher from '../../../dispatcher.js'; import {Metrics as ActionMetrics} from '../../../im/action/importaction.js'; @@ -17,8 +18,6 @@ import {launchFilterActionExport} from './filteractionexport.js'; import FilterActionNode from './filteractionnode.js'; import FilterActionTreeSearch from './filteractiontreesearch.js'; -const googArray = goog.require('goog.array'); - const {default: FilterActionEntry} = goog.requireType('os.im.action.FilterActionEntry'); @@ -141,7 +140,7 @@ export default class Controller extends AbstractGroupByTreeSearchCtrl { var entries = FilterActionNode.toEntries(entryNodes); // the tag group by sometimes creates multiple nodes for the same entry, so remove duplicate entries here - googArray.removeDuplicates(entries); + removeDuplicates(entries); ImportActionManager.getInstance().setActionEntries(this.entryType, entries); } diff --git a/src/os/ui/im/importmanager.js b/src/os/ui/im/importmanager.js index 217f7e072..4f4e036a8 100644 --- a/src/os/ui/im/importmanager.js +++ b/src/os/ui/im/importmanager.js @@ -1,9 +1,8 @@ goog.declareModuleId('os.ui.im.ImportManager'); -import {defaultSort} from '../../array/array.js'; +import {defaultSort, removeDuplicates} from '../../array/array.js'; import Importer from '../../im/importer.js'; -const {removeDuplicates} = goog.require('goog.array'); const log = goog.require('goog.log'); const {forEach} = goog.require('goog.object'); @@ -174,7 +173,7 @@ export default class ImportManager { forEach(this.importUIs_, function(importer) { importers.push(importer); }); - removeDuplicates(importers, null, function(importer) { + removeDuplicates(importers, undefined, function(importer) { return importer.launchUI.toString(); }); return importers; diff --git a/src/os/ui/menu/filtermenu.js b/src/os/ui/menu/filtermenu.js index 39565abff..2ed71f968 100644 --- a/src/os/ui/menu/filtermenu.js +++ b/src/os/ui/menu/filtermenu.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.ui.menu.filter'); import EventType from '../../action/eventtype.js'; +import {removeDuplicates} from '../../array/array.js'; import CommandProcessor from '../../command/commandprocessor.js'; import FilterEnable from '../../command/filterenablecmd.js'; import SequenceCommand from '../../command/sequencecommand.js'; @@ -16,7 +17,6 @@ import Menu from './menu.js'; import MenuItem from './menuitem.js'; import MenuItemType from './menuitemtype.js'; -const {removeDuplicates} = goog.require('goog.array'); const {remove} = goog.require('ol.array'); const {default: FilterEntry} = goog.requireType('os.filter.FilterEntry'); diff --git a/src/os/ui/ogc/ogcserver.js b/src/os/ui/ogc/ogcserver.js index ade418678..9eb829902 100644 --- a/src/os/ui/ogc/ogcserver.js +++ b/src/os/ui/ogc/ogcserver.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.ui.ogc.OGCServer'); import AlertEventSeverity from '../../alert/alerteventseverity.js'; import AlertManager from '../../alert/alertmanager.js'; +import {removeDuplicates} from '../../array/array.js'; import Settings from '../../config/settings.js'; import DataManager from '../../data/datamanager.js'; import IDataProvider from '../../data/idataprovider.js'; @@ -20,7 +21,6 @@ import LayerParsers from './wms/layerparsers.js'; const Uri = goog.require('goog.Uri'); const QueryData = goog.require('goog.Uri.QueryData'); -const {removeDuplicates} = goog.require('goog.array'); const dispose = goog.require('goog.dispose'); const {loadXml} = goog.require('goog.dom.xml'); const log = goog.require('goog.log'); diff --git a/src/os/ui/query/queryhandler.js b/src/os/ui/query/queryhandler.js index 06cf93fc2..9cad8b8ba 100644 --- a/src/os/ui/query/queryhandler.js +++ b/src/os/ui/query/queryhandler.js @@ -1,12 +1,11 @@ goog.declareModuleId('os.ui.query.QueryHandler'); -import {defaultSort} from '../../array/array.js'; +import {defaultSort, removeDuplicates} from '../../array/array.js'; import FilterEntry from '../../filter/filterentry.js'; import instanceOf from '../../instanceof.js'; import {getAreaManager, getFilterManager, getQueryManager} from '../../query/queryinstance.js'; const Disposable = goog.require('goog.Disposable'); -const {removeDuplicates} = goog.require('goog.array'); const {isEmptyOrWhitespace, makeSafe} = goog.require('goog.string'); const Feature = goog.requireType('ol.Feature'); @@ -330,7 +329,7 @@ export default class QueryHandler extends Disposable { entries = entries.filter(this.filters, this); // Since this is only for exclusions or no areas. We only need 1 of each filter - removeDuplicates(entries, null, function(entry) { + removeDuplicates(entries, undefined, function(entry) { return /** @type {string} */ (entry['filterId']); }); } diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index 0b60af18d..8502a36e7 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -1,7 +1,7 @@ goog.declareModuleId('os.ui.search.SearchBoxUI'); import '../dragdrop/dragdropui.js'; -import {defaultSort} from '../../array/array.js'; +import {defaultSort, removeDuplicates} from '../../array/array.js'; import Settings from '../../config/settings.js'; import * as dispatcher from '../../dispatcher.js'; import osImplements from '../../implements.js'; @@ -942,7 +942,7 @@ export class Controller { if (results && results.length > 0) { const typeahead = this.autocompleteSrc_.data('typeahead'); const current = typeahead['source'].concat(results); - googArray.removeDuplicates(current); // don't allow dupes in auto-complete results + removeDuplicates(current); // don't allow dupes in auto-complete results typeahead['source'] = current; typeahead['lookup'](); } diff --git a/src/os/user/settings/favoritemanager.js b/src/os/user/settings/favoritemanager.js index 470795761..889c1d0b4 100644 --- a/src/os/user/settings/favoritemanager.js +++ b/src/os/user/settings/favoritemanager.js @@ -124,7 +124,7 @@ export default class FavoriteManager extends EventTarget { } } } - googArray.removeDuplicates(favFolders); + osArray.removeDuplicates(favFolders); return favFolders; } @@ -165,7 +165,7 @@ export default class FavoriteManager extends EventTarget { */ getFavTypes(favs, types) { var result = FavoriteManager.getTypeInternal_(favs, types); - googArray.removeDuplicates(result, undefined, function(fav) { + osArray.removeDuplicates(result, undefined, function(fav) { return fav['key']; }); return result; @@ -179,7 +179,7 @@ export default class FavoriteManager extends EventTarget { */ getFolders(opt_ignore) { var folders = FavoriteManager.getFoldersInternal_(this.getFavorites(), opt_ignore); - googArray.removeDuplicates(folders); + osArray.removeDuplicates(folders); return folders; } @@ -217,7 +217,7 @@ export default class FavoriteManager extends EventTarget { // Are we putting this favorite into a folder? if (opt_folders && opt_folders.length > 0) { - googArray.removeDuplicates(opt_folders); + osArray.removeDuplicates(opt_folders); for (var i = 0; i < opt_folders.length; i++) { favs = FavoriteManager.saveFolderInternal_(favs, fav, opt_folders[i]); } diff --git a/src/plugin/places/places.js b/src/plugin/places/places.js index 47751ce10..cac1ce6cc 100644 --- a/src/plugin/places/places.js +++ b/src/plugin/places/places.js @@ -1,6 +1,7 @@ goog.declareModuleId('plugin.places'); import * as annotation from '../../os/annotation/annotation.js'; +import {removeDuplicates} from '../../os/array/array.js'; import CommandProcessor from '../../os/command/commandprocessor.js'; import SequenceCommand from '../../os/command/sequencecommand.js'; import ColumnDefinition from '../../os/data/columndefinition.js'; @@ -23,7 +24,6 @@ import KMLField from '../file/kml/kmlfield.js'; import KMLTreeExporter from '../file/kml/kmltreeexporter.js'; import {getKMLRoot, updateFolder, updatePlacemark} from '../file/kml/ui/kmlui.js'; -const {removeDuplicates} = goog.require('goog.array'); const {getUid} = goog.require('ol'); const Feature = goog.require('ol.Feature'); const Geometry = goog.require('ol.geom.Geometry'); From e1aeb328fa0ba0f9a15b0e5f814cc7e14c75605a Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 11:32:25 -0700 Subject: [PATCH 18/23] feat(goog): remove more goog.array functions --- src/os/color.js | 1 - src/os/config/settings.js | 3 +-- src/os/config/storage/settingsstorageloader.js | 4 +--- src/os/interaction/doubleclickinteraction.js | 5 ++--- src/os/mixin/imagesourcemixin.js | 5 +++-- src/os/mixin/tileimagemixin.js | 5 +++-- src/os/track/track.js | 2 +- src/os/ui/filter/ui/copyfilter.js | 14 ++++++++++---- src/os/ui/filter/ui/filtergroupby.js | 6 +++--- src/os/ui/filter/ui/filtertypegroupby.js | 5 +++-- src/os/ui/ogc/wms/wmslayerparserv111.js | 3 +-- src/os/ui/ogc/wms/wmslayerparserv130.js | 5 ++--- src/os/ui/query/addfilter.js | 7 ++----- src/os/ui/search/searchbox.js | 2 +- test/os/ui/action/actionmanager.test.js | 8 +++----- 15 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/os/color.js b/src/os/color.js index 722c7dbb5..a5ae42fa0 100644 --- a/src/os/color.js +++ b/src/os/color.js @@ -3,7 +3,6 @@ */ goog.declareModuleId('os.color'); -goog.require('goog.array'); goog.require('goog.color'); goog.require('goog.color.Rgb'); goog.require('goog.math'); diff --git a/src/os/config/settings.js b/src/os/config/settings.js index 67ad5a11b..08f41dca3 100644 --- a/src/os/config/settings.js +++ b/src/os/config/settings.js @@ -19,7 +19,6 @@ import SettingsWritableStorageType from './storage/settingswritablestoragetype.j const Promise = goog.require('goog.Promise'); const Timer = goog.require('goog.Timer'); -const googArray = goog.require('goog.array'); const DeferredList = goog.require('goog.async.DeferredList'); const Delay = goog.require('goog.async.Delay'); const GoogEvent = goog.require('goog.events.Event'); @@ -433,7 +432,7 @@ export default class Settings extends EventTarget { log.fine(logger, 'Saving settings...'); var keysToDelete = Array.from(osConfigNamespace.getObsoleteKeys()); - googArray.insertArrayAt(keysToDelete, osConfigNamespace.keysToDelete.slice()); + keysToDelete.unshift(...osConfigNamespace.keysToDelete.slice()); if (opt_settingsToOverwrite != null) { userPrefsToPersist = opt_settingsToOverwrite; diff --git a/src/os/config/storage/settingsstorageloader.js b/src/os/config/storage/settingsstorageloader.js index 68a42a860..cee8c054e 100644 --- a/src/os/config/storage/settingsstorageloader.js +++ b/src/os/config/storage/settingsstorageloader.js @@ -5,7 +5,6 @@ import {appNs, coreNs} from '../config.js'; import ConfigType from '../configtype.js'; import SettingsFile from './settingsfile.js'; -const {insertArrayAt} = goog.require('goog.array'); const Deferred = goog.require('goog.async.Deferred'); const DeferredList = goog.require('goog.async.DeferredList'); const log = goog.require('goog.log'); @@ -144,8 +143,7 @@ export default class SettingsStorageLoader { if (Array.isArray(existingVal) && Array.isArray(value) && JSON.stringify(existingVal) != JSON.stringify(value)) { log.info(logger, 'Merging settings arrays - ' + 'existingVal: ' + existingVal + ', value: ' + value); - insertArrayAt(/** @type {Array} */ (value), /** @type {Array} */ (existingVal), - /** @type {Array} */ (value).length); + value.push(...existingVal); log.info(logger, 'Result of merge: ' + value); } diff --git a/src/os/interaction/doubleclickinteraction.js b/src/os/interaction/doubleclickinteraction.js index 55e948560..5e04bded4 100644 --- a/src/os/interaction/doubleclickinteraction.js +++ b/src/os/interaction/doubleclickinteraction.js @@ -6,7 +6,6 @@ import osImplements from '../implements.js'; import VectorLayer from '../layer/vector.js'; import launchMultiFeatureInfo from '../ui/feature/launchmultifeatureinfo.js'; -const {insert} = goog.require('goog.array'); const Feature = goog.require('ol.Feature'); const MapBrowserEventType = goog.require('ol.MapBrowserEventType'); const ViewHint = goog.require('ol.ViewHint'); @@ -69,8 +68,8 @@ export default class DoubleClick extends Interaction { var vector = /** @type {VectorLayer} */ (layer); var id = vector.getId(); - if (vector && id) { - insert(features, feature); + if (vector && id && !features.includes(feature)) { + features.push(feature); } } } diff --git a/src/os/mixin/imagesourcemixin.js b/src/os/mixin/imagesourcemixin.js index b63b862fa..bc5d26341 100644 --- a/src/os/mixin/imagesourcemixin.js +++ b/src/os/mixin/imagesourcemixin.js @@ -4,7 +4,6 @@ import PropertyChangeEvent from '../events/propertychangeevent.js'; import osImplements from '../implements.js'; import ILoadingSource from '../ol/source/iloadingsource.js'; -const {insert} = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const ImageState = goog.require('ol.ImageState'); const {remove} = goog.require('ol.array'); @@ -42,7 +41,9 @@ ImageSource.prototype.addImageFilter = function(fn) { this.imageFilters = []; } - insert(this.imageFilters, fn); + if (!this.imageFilters.includes(fn)) { + this.imageFilters.push(fn); + } }; diff --git a/src/os/mixin/tileimagemixin.js b/src/os/mixin/tileimagemixin.js index 86aae8db5..8d7d322f9 100644 --- a/src/os/mixin/tileimagemixin.js +++ b/src/os/mixin/tileimagemixin.js @@ -11,7 +11,6 @@ import osImplements from '../implements.js'; import IFilterableTileSource from '../source/ifilterabletilesource.js'; import ColorableTile from '../tile/colorabletile.js'; -const {insert} = goog.require('goog.array'); const {remove} = goog.require('ol.array'); const TileImage = goog.require('ol.source.TileImage'); @@ -43,7 +42,9 @@ TileImage.prototype.addTileFilter = function(fn) { this.tileFilters = []; } - insert(this.tileFilters, fn); + if (!this.tileFilters.includes(fn)) { + this.tileFilters.push(fn); + } this.applyTileFilters(); }; diff --git a/src/os/track/track.js b/src/os/track/track.js index 6c2adb7f7..966b410a7 100644 --- a/src/os/track/track.js +++ b/src/os/track/track.js @@ -447,7 +447,7 @@ let addToTrack_ = function(options) { var insertIndex = osArray.binaryStrideSearch(flatCoordinates, value, stride, stride - 1); if (insertIndex < 0) { // insert coordinates in the corresponding location - googArray.insertArrayAt(flatCoordinates, coordinate, ~insertIndex); + flatCoordinates.splice(~insertIndex, 0, ...coordinate); added.push(features ? features[i] : coordinate); } else { skippedCoords++; diff --git a/src/os/ui/filter/ui/copyfilter.js b/src/os/ui/filter/ui/copyfilter.js index ccee20963..9d9324a1d 100644 --- a/src/os/ui/filter/ui/copyfilter.js +++ b/src/os/ui/filter/ui/copyfilter.js @@ -15,7 +15,6 @@ import {close} from '../../window.js'; import WindowEventType from '../../windoweventtype.js'; import {filterColumns, getFilterKeyFromType} from '../filter.js'; -const {insert} = goog.require('goog.array'); const {assertString} = goog.require('goog.asserts'); const {getCount} = goog.require('goog.object'); const {caseInsensitiveCompare, getRandomString} = goog.require('goog.string'); @@ -179,7 +178,9 @@ export class Controller { var filterNode = this.sourceEntry_.getFilterNode(); var columnNames = filterNode.querySelectorAll('PropertyName'); for (var i = 0, ii = columnNames.length; i < ii; i++) { - insert(this.sourceColumnNames_, columnNames[i].textContent); + if (!this.sourceColumnNames_.includes(columnNames[i].textContent)) { + this.sourceColumnNames_.push(columnNames[i].textContent); + } } this['layers'] = layers; @@ -327,7 +328,9 @@ export class Controller { mapping.addColumn(this['sourceFilterKey'], sourceColumnName); } - insert(layersToMappings[targetFilterKey], mapping); + if (!layersToMappings[targetFilterKey].includes(mapping)) { + layersToMappings[targetFilterKey].push(mapping); + } } } @@ -342,7 +345,10 @@ export class Controller { var mapping = model['mapping']; layersToMappings[targetFilterKey] = layersToMappings[targetFilterKey] || []; - insert(layersToMappings[targetFilterKey], mapping); + + if (!layersToMappings[targetFilterKey].includes(mapping)) { + layersToMappings[targetFilterKey].push(mapping); + } } } diff --git a/src/os/ui/filter/ui/filtergroupby.js b/src/os/ui/filter/ui/filtergroupby.js index c698b7c6f..07e935ecd 100644 --- a/src/os/ui/filter/ui/filtergroupby.js +++ b/src/os/ui/filter/ui/filtergroupby.js @@ -5,8 +5,6 @@ import BaseGroupBy from '../../../data/groupby/basegroupby.js'; import SlickTreeNode from '../../slick/slicktreenode.js'; import {directiveTag} from './filtergroupui.js'; -const {insert} = goog.require('goog.array'); - const {default: FilterNode} = goog.requireType('os.ui.filter.ui.FilterNode'); @@ -60,7 +58,9 @@ export default class FilterGroupBy extends BaseGroupBy { } } - insert(ids, val); + if (!ids.includes(val)) { + ids.push(val); + } return ids; } diff --git a/src/os/ui/filter/ui/filtertypegroupby.js b/src/os/ui/filter/ui/filtertypegroupby.js index 79a1ff77f..8f77e827e 100644 --- a/src/os/ui/filter/ui/filtertypegroupby.js +++ b/src/os/ui/filter/ui/filtertypegroupby.js @@ -2,7 +2,6 @@ goog.declareModuleId('os.ui.filter.ui.FilterTypeGroupBy'); import FilterGroupBy from './filtergroupby.js'; -const {insert} = goog.require('goog.array'); const {toTitleCase} = goog.require('goog.string'); const {default: FilterNode} = goog.requireType('os.ui.filter.ui.FilterNode'); @@ -52,7 +51,9 @@ export default class FilterTypeGroupBy extends FilterGroupBy { } } - insert(ids, val); + if (!ids.includes(val)) { + ids.push(val); + } return ids; } } diff --git a/src/os/ui/ogc/wms/wmslayerparserv111.js b/src/os/ui/ogc/wms/wmslayerparserv111.js index 06695bb13..4fef35042 100644 --- a/src/os/ui/ogc/wms/wmslayerparserv111.js +++ b/src/os/ui/ogc/wms/wmslayerparserv111.js @@ -3,7 +3,6 @@ goog.declareModuleId('os.ui.ogc.wms.WMSLayerParserV111'); import {COLOR_STYLE_REGEX, DEFAULT_TILE_STYLE} from '../../../ogc/ogc.js'; import AbstractWMSLayerParser from './abstractwmslayerparser.js'; -const {clone: cloneArray} = goog.require('goog.array'); const {clone: cloneObject, getValueByKeys} = goog.require('goog.object'); @@ -52,7 +51,7 @@ export default class WMSLayerParserV111 extends AbstractWMSLayerParser { if (bboxArray && bboxArray.length > 0) { for (i = 0; i < bboxArray.length; i++) { if (bboxArray[i]['crs'] == 'EPSG:4326') { - layer.setBBox(/** @type {ol.Extent} */ (cloneArray(bboxArray[i]['extent']))); + layer.setBBox(/** @type {ol.Extent} */ (Array.from(bboxArray[i]['extent']))); break; } } diff --git a/src/os/ui/ogc/wms/wmslayerparserv130.js b/src/os/ui/ogc/wms/wmslayerparserv130.js index 7e3fd917c..7bed27a43 100644 --- a/src/os/ui/ogc/wms/wmslayerparserv130.js +++ b/src/os/ui/ogc/wms/wmslayerparserv130.js @@ -3,7 +3,6 @@ goog.declareModuleId('os.ui.ogc.wms.WMSLayerParserV130'); import {COLOR_STYLE_REGEX, DEFAULT_TILE_STYLE} from '../../../ogc/ogc.js'; import AbstractWMSLayerParser from './abstractwmslayerparser.js'; -const {clone: cloneArray} = goog.require('goog.array'); const {clone: cloneObject, getValueByKeys} = goog.require('goog.object'); @@ -49,7 +48,7 @@ export default class WMSLayerParserV130 extends AbstractWMSLayerParser { var epsg4326box = null; for (i = 0; i < bboxArray.length; i++) { if (bboxArray[i]['crs'] == 'CRS:84') { - layer.setBBox(/** @type {ol.Extent} */ (cloneArray(bboxArray[i]['extent']))); + layer.setBBox(/** @type {ol.Extent} */ (Array.from(bboxArray[i]['extent']))); break; } else if (bboxArray[i]['crs'] == 'EPSG:4326') { epsg4326box = bboxArray[i]; @@ -59,7 +58,7 @@ export default class WMSLayerParserV130 extends AbstractWMSLayerParser { if (!layer.getBBox() && epsg4326box) { // EPSG:4326 in WMS 1.3.0 is in the correct coordinate order (lat, lon rather than lon, lat), so we // need to flip the values in the array - var extent = cloneArray(epsg4326box['extent']); + var extent = Array.from(epsg4326box['extent']); layer.setBBox([extent[1], extent[0], extent[3], extent[2]]); } } diff --git a/src/os/ui/query/addfilter.js b/src/os/ui/query/addfilter.js index 2f64364d6..39f155598 100644 --- a/src/os/ui/query/addfilter.js +++ b/src/os/ui/query/addfilter.js @@ -7,7 +7,6 @@ import MenuItem from '../menu/menuitem.js'; import MenuItemType from '../menu/menuitemtype.js'; import Module from '../module.js'; -const {insert} = goog.require('goog.array'); const dispose = goog.require('goog.dispose'); const GoogEventType = goog.require('goog.events.EventType'); const {caseInsensitiveCompare} = goog.require('goog.string'); @@ -147,10 +146,8 @@ export class Controller { } } - if (this.scope['layer']) { - if (this.scope['layer']['id']) { - insert(layers, this.scope['layer']); - } + if (this.scope['layer'] && this.scope['layer']['id'] && !layers.includes(this.scope['layer'])) { + layers.push(this.scope['layer']); } layers.sort(Controller.sortLayers); diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index 8502a36e7..08cc0db49 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -825,7 +825,7 @@ export class Controller { this.search(); // move the item to the top of the recent list - const recentIndex = googArray.indexOf(this['recentSearches'], recent); + const recentIndex = this['recentSearches'].indexOf(recent); if (recentIndex > 0) { const searchToMove = this['recentSearches'].splice(recentIndex, 1)[0]; this['recentSearches'].splice(0, 0, searchToMove); diff --git a/test/os/ui/action/actionmanager.test.js b/test/os/ui/action/actionmanager.test.js index 45fb29abf..2cfde2acd 100644 --- a/test/os/ui/action/actionmanager.test.js +++ b/test/os/ui/action/actionmanager.test.js @@ -1,11 +1,9 @@ -goog.require('goog.array'); goog.require('goog.events.Event'); goog.require('os.ui.action.Action'); goog.require('os.ui.action.ActionManager'); goog.require('os.ui.action.EventType'); describe('os.ui.action.ActionManager', function() { - const googArray = goog.module.get('goog.array'); const GoogEvent = goog.module.get('goog.events.Event'); const {default: Action} = goog.module.get('os.ui.action.Action'); const {default: ActionManager} = goog.module.get('os.ui.action.ActionManager'); @@ -149,9 +147,9 @@ describe('os.ui.action.ActionManager', function() { it('starts with the correct enabled state when action args are initialized', function() { var am = new ActionManager().withActionArgs(['a', 'c']); - am.addAction(new Action('a').enableWhen((args) => googArray.indexOf(args, 'a') > -1)); - am.addAction(new Action('b').enableWhen((args) => googArray.indexOf(args, 'b') > -1)); - am.addAction(new Action('c').enableWhen((args) => googArray.indexOf(args, 'c') > -1)); + am.addAction(new Action('a').enableWhen((args) => args.indexOf('a') > -1)); + am.addAction(new Action('b').enableWhen((args) => args.indexOf('b') > -1)); + am.addAction(new Action('c').enableWhen((args) => args.indexOf('c') > -1)); var enabled = am.getEnabledActions(); expect(enabled.length).toBe(2); expect(enabled).toContain(am.getAction('a')); From 110392fbab271fe403ee5ecd35403c6e25c287ea Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 12:28:18 -0700 Subject: [PATCH 19/23] feat(goog): remove more goog.array.remove functions --- .../config/abstractdatasourcelayerconfig.js | 8 ++++---- src/os/layer/foldermanager.js | 5 ++--- src/os/ui/menu/menuitem.js | 11 +++++----- src/os/ui/search/searchbox.js | 2 +- src/os/ui/state/statemenu.js | 5 +---- src/os/user/settings/favoritemanager.js | 16 ++++++++------- src/plugin/track/trackmanager.js | 20 ++++++------------- 7 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/os/layer/config/abstractdatasourcelayerconfig.js b/src/os/layer/config/abstractdatasourcelayerconfig.js index f4a1508b5..7cc5dc840 100644 --- a/src/os/layer/config/abstractdatasourcelayerconfig.js +++ b/src/os/layer/config/abstractdatasourcelayerconfig.js @@ -10,7 +10,6 @@ import AbstractLayerConfig from './abstractlayerconfig.js'; import {mapFeatureTypeColumn} from './layerconfig.js'; const Uri = goog.require('goog.Uri'); -const {removeIf} = goog.require('goog.array'); const {assert} = goog.require('goog.asserts'); const {getLogger} = goog.require('goog.log'); const VectorRenderType = goog.require('ol.layer.VectorRenderType'); @@ -119,9 +118,10 @@ export default class AbstractDataSourceLayerConfig extends AbstractLayerConfig { // exclude the geometry column var geometryColumn = featureType.getGeometryColumnName(); if (geometryColumn) { - removeIf(columns, function(column) { - return column.name == geometryColumn; - }); + const columnIndex = columns.findIndex((col) => col.name == geometryColumn); + if (columnIndex >= 0) { + columns.splice(columnIndex, 1); + } } // if columns are saved on the descriptor, we want to update their types to match that of the feature type since that diff --git a/src/os/layer/foldermanager.js b/src/os/layer/foldermanager.js index 933b7e6a7..7ff3c1114 100644 --- a/src/os/layer/foldermanager.js +++ b/src/os/layer/foldermanager.js @@ -5,7 +5,6 @@ import LayerEventType from '../events/layereventtype.js'; import MapContainer from '../mapcontainer.js'; import {FolderEventType, SettingsKey} from './folder.js'; -const {remove} = goog.require('goog.array'); const EventTarget = goog.require('goog.events.EventTarget'); const log = goog.require('goog.log'); @@ -110,8 +109,8 @@ export default class FolderManager extends EventTarget { options.children.forEach((child) => { const children = parentFolder ? parentFolder.children : this.items; - if (children) { - remove(children, child); + if (children && children.indexOf(child) >= 0) { + children.splice(children.indexOf(child)); } child.parentId = options.id; diff --git a/src/os/ui/menu/menuitem.js b/src/os/ui/menu/menuitem.js index 77355b77f..1fa32c866 100644 --- a/src/os/ui/menu/menuitem.js +++ b/src/os/ui/menu/menuitem.js @@ -3,8 +3,6 @@ goog.declareModuleId('os.ui.menu.MenuItem'); import {defaultSort} from '../../array/array.js'; import MenuItemType from './menuitemtype.js'; -const {removeIf} = goog.require('goog.array'); - const {default: MenuEvent} = goog.requireType('os.ui.menu.MenuEvent'); const {default: MenuItemOptions} = goog.requireType('os.ui.menu.MenuItemOptions'); @@ -134,9 +132,12 @@ export default class MenuItem { removeChild(eventTypeOrLabel) { var rv = false; if (this.children) { - rv = removeIf(this.children, function(item) { - return item.eventType === eventTypeOrLabel || item.label === eventTypeOrLabel; - }); + const childIndex = this.children.findIndex( + (item) => item.eventType === eventTypeOrLabel || item.label === eventTypeOrLabel); + if (childIndex >= 0) { + this.children.splice(childIndex, 1); + rv = true; + } if (!this.children.length) { this.children = undefined; diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index 08cc0db49..6bd8552cd 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -544,7 +544,7 @@ export class Controller { }); if (ind > -1) { currentGroup.push(copiedOptions[ind]); - googArray.removeAt(copiedOptions, ind); + copiedOptions.splice(ind, 1); } }, this); this['searchOptionsGroups'][groupName] = currentGroup; diff --git a/src/os/ui/state/statemenu.js b/src/os/ui/state/statemenu.js index 821cf4a5d..2329b9232 100644 --- a/src/os/ui/state/statemenu.js +++ b/src/os/ui/state/statemenu.js @@ -19,7 +19,6 @@ import MenuItemType from '../menu/menuitemtype.js'; import StateClear from './cmd/stateclearcmd.js'; import IStateDescriptor from './istatedescriptor.js'; -const {removeAllIf} = goog.require('goog.array'); const Throttle = goog.require('goog.async.Throttle'); const googDispose = goog.require('goog.dispose'); @@ -167,9 +166,7 @@ export const refreshMenu = function() { // Remove all groups from the menu var menuRoot = menu.getRoot(); if (menuRoot.children) { - removeAllIf(menuRoot.children, function(item) { - return item.type === MenuItemType.GROUP; - }); + menuRoot.children = menuRoot.children.filter((item) => item.type === MenuItemType.GROUP); } // dataManager.getDescriptors will get everything diff --git a/src/os/user/settings/favoritemanager.js b/src/os/user/settings/favoritemanager.js index 889c1d0b4..098f19671 100644 --- a/src/os/user/settings/favoritemanager.js +++ b/src/os/user/settings/favoritemanager.js @@ -449,7 +449,7 @@ export default class FavoriteManager extends EventTarget { for (var i = 0; i < favs.length; i++) { var fav = favs[i]; if (fav['key'] == key) { - googArray.removeAt(favs, i); + favs.splice(i, 1); } else if (fav['type'] == FavoriteType.FOLDER) { var children = FavoriteManager.removeFavoriteInternal_(fav['children'], key); if (children.length != fav['children'].length) { @@ -474,9 +474,10 @@ export default class FavoriteManager extends EventTarget { for (var i = 0; i < favs.length; i++) { var fav = favs[i]; if (fav['key'] == folder) { - googArray.removeIf(fav['children'], function(child) { - return child['key'] == key; - }); + const childIndex = fav['children'].findIndex((child) => child['key'] == key); + if (childIndex >= 0) { + fav['children'].splice(childIndex, 1); + } } else if (fav['type'] == FavoriteType.FOLDER) { var children = FavoriteManager.removeFavoriteFromFolderInternal_(fav['children'], key, folder); if (children.length != fav['children'].length) { @@ -537,9 +538,10 @@ export default class FavoriteManager extends EventTarget { if (folders) { // Remove the ignored folder if it exists if (opt_ignore) { - googArray.removeIf(folders, function(folder) { - return folder['key'] == opt_ignore; - }); + const folderIndex = folders.findIndex((folder) => folder['key'] == opt_ignore); + if (folderIndex >= 0) { + folders.splice(folderIndex, 1); + } } googArray.extend(result, folders); diff --git a/src/plugin/track/trackmanager.js b/src/plugin/track/trackmanager.js index 54e07d600..aa69ef071 100644 --- a/src/plugin/track/trackmanager.js +++ b/src/plugin/track/trackmanager.js @@ -25,7 +25,6 @@ import PlacesManager from '../places/placesmanager.js'; import * as pluginTrack from './track.js'; import TrackInteraction from './trackinteraction.js'; -const googArray = goog.require('goog.array'); const asserts = goog.require('goog.asserts'); const ConditionalDelay = goog.require('goog.async.ConditionalDelay'); const Throttle = goog.require('goog.async.Throttle'); @@ -157,20 +156,13 @@ export default class TrackManager extends EventTarget { if (track) { events.unlisten(track, events.EventType.CHANGE, this.onFeatureValueChange_, this); - googArray.removeIf(this.following_, function(item) { - return item === track; - }); - - googArray.removeIf(this.activeTracks_, function(item) { - return item === track; - }); + const followingIndex = this.following_.indexOf(track); + if (followingIndex >= 0) { + this.following_.splice(followingIndex, 1); + } // also need to remove it from the active tracks - for (let k = 0; k < this.activeTracks_.length; k++) { - if (this.activeTracks_[k] == track) { - googArray.removeAt(this.activeTracks_, k); - } - } + this.activeTracks_ = this.activeTracks_.filter((item) => item != track); } }, this); } @@ -271,7 +263,7 @@ export default class TrackManager extends EventTarget { // check which of the active tracks are to be followed for (let i = 0; i < this.activeTracks_.length; i++) { if (!array.includes(this.following_, this.activeTracks_[i])) { - googArray.removeAt(this.activeTracks_, i); + this.activeTracks_.splice(i, 1); } } } From 087423f092918a3b28137b31bb7278b4e4cc66aa Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 13:29:49 -0700 Subject: [PATCH 20/23] feat(goog): replace goog.array.bucket with new os.array version --- src/os/array/array.js | 23 +++++++++++++++++++++++ src/os/data/layertreesearch.js | 5 ++--- src/os/im/mapping/mappingmanager.js | 2 +- src/os/track/track.js | 3 +-- src/os/ui/im/abstractmapperctrl.js | 3 +-- src/os/ui/window.js | 4 +--- src/os/user/settings/favoritemanager.js | 8 ++++---- src/plugin/arc/query/arcqueryhandler.js | 4 ++-- 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/os/array/array.js b/src/os/array/array.js index 7552f7d4c..2855b64d7 100644 --- a/src/os/array/array.js +++ b/src/os/array/array.js @@ -363,6 +363,29 @@ export const binaryStrideSearch = function(arr, target, stride, offset, opt_comp return found ? left : ~left; }; +/** + * Based on the goog.array.bucket method. Splits an array into disjoint buckets according to a splitting function. + * + * @param {!Array} arr The array + * @param {function(this: S, T, number, !Array): ?} sortFn The function to call for every element. + * This function takes 3 arguments (the element, the index and the array) and must return a valid object key + * or undefined if the item should not be placed into a bucket. + * @param {S=} opt_obj The object to be used as the value of 'this' within sortFn + * @return {!Object>} + * @template T,S + */ +export const bucket = function(arr, sortFn, opt_obj) { + const buckets = {}; + arr.forEach(function(el, i) { + const bucketKey = sortFn.call(/** @type {?} */ (opt_obj), el, i, arr); + if (bucketKey !== undefined) { + const bucket = buckets[bucketKey] || (buckets[bucketKey] = []); + bucket.push(el); + } + }); + return buckets; +}; + /** * @param {VALUE} a * @param {VALUE} b diff --git a/src/os/data/layertreesearch.js b/src/os/data/layertreesearch.js index d0fd1becb..b60a7ffa8 100644 --- a/src/os/data/layertreesearch.js +++ b/src/os/data/layertreesearch.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.data.LayerTreeSearch'); +import * as osArray from '../array/array.js'; import IGroupable from '../igroupable.js'; import osImplements from '../implements.js'; import FolderManager from '../layer/foldermanager.js'; @@ -13,8 +14,6 @@ import FolderNode from './foldernode.js'; import LayerZOrderGroupBy from './groupby/layerzordergroupby.js'; import LayerNode from './layernode.js'; -const googArray = goog.require('goog.array'); - const {default: ILayer} = goog.requireType('os.layer.ILayer'); const {default: INodeGroupBy} = goog.requireType('os.data.groupby.INodeGroupBy'); const {default: ITreeNode} = goog.requireType('os.structs.ITreeNode'); @@ -141,7 +140,7 @@ export default class LayerTreeSearch extends AbstractGroupByTreeSearch { if (results && results.length > 0) { // if there are no user-created folders, fall back to grouping them automatically var idBuckets = /** @type {!Object>} */ - (googArray.bucket(results, this.getNodeGroup.bind(this))); + (osArray.bucket(results, this.getNodeGroup.bind(this))); results.length = 0; for (var id in idBuckets) { diff --git a/src/os/im/mapping/mappingmanager.js b/src/os/im/mapping/mappingmanager.js index 4c073c8a6..065abafd9 100644 --- a/src/os/im/mapping/mappingmanager.js +++ b/src/os/im/mapping/mappingmanager.js @@ -1,10 +1,10 @@ goog.declareModuleId('os.im.mapping.MappingManager'); +import {bucket} from '../../array/array.js'; import {createElement} from '../../xml.js'; import {DEFAULT_SCORETYPE, reduceMappings} from './mapping.js'; import MappingRegistry from './mappingregistry.js'; -const {bucket} = goog.require('goog.array'); const {expose} = goog.require('goog.debug'); const log = goog.require('goog.log'); diff --git a/src/os/track/track.js b/src/os/track/track.js index 966b410a7..69b1c1ce4 100644 --- a/src/os/track/track.js +++ b/src/os/track/track.js @@ -28,7 +28,6 @@ import UnitManager from '../unit/unitmanager.js'; import TrackField from './trackfield.js'; const Promise = goog.require('goog.Promise'); -const googArray = goog.require('goog.array'); const dispose = goog.require('goog.dispose'); const log = goog.require('goog.log'); const math = goog.require('goog.math'); @@ -1539,7 +1538,7 @@ export const splitIntoTracks = function(options) { var getTrackFn = options.getTrackFn || fn.noop; if (features && bucketFn) { - var buckets = googArray.bucket(features, bucketFn); + var buckets = osArray.bucket(features, bucketFn); for (var id in buckets) { var bucketFeatures = buckets[id]; diff --git a/src/os/ui/im/abstractmapperctrl.js b/src/os/ui/im/abstractmapperctrl.js index 12ffd5c8b..02a87a673 100644 --- a/src/os/ui/im/abstractmapperctrl.js +++ b/src/os/ui/im/abstractmapperctrl.js @@ -1,10 +1,9 @@ goog.declareModuleId('os.ui.im.AbstractMapperCtrl'); +import {bucket} from '../../array/array.js'; import ColumnDefinition from '../../data/columndefinition.js'; import * as osWindow from '../window.js'; -const {bucket} = goog.require('goog.array'); - const {default: Rule} = goog.requireType('os.im.mapping.Rule'); const {default: SlickTreeNode} = goog.requireType('os.ui.slick.SlickTreeNode'); diff --git a/src/os/ui/window.js b/src/os/ui/window.js index 028ed1cc6..fef9be100 100644 --- a/src/os/ui/window.js +++ b/src/os/ui/window.js @@ -1,12 +1,10 @@ goog.declareModuleId('os.ui.window'); -import {forEach} from '../array/array.js'; +import {bucket, forEach} from '../array/array.js'; import {apply} from './ui.js'; import windowSelector from './windowselector.js'; import windowZIndexMax from './windowzindexmax.js'; -const {bucket} = goog.require('goog.array'); - const {Controller: WindowCtrl} = goog.requireType('os.ui.WindowUI'); diff --git a/src/os/user/settings/favoritemanager.js b/src/os/user/settings/favoritemanager.js index 098f19671..1b59b5c53 100644 --- a/src/os/user/settings/favoritemanager.js +++ b/src/os/user/settings/favoritemanager.js @@ -500,9 +500,9 @@ export default class FavoriteManager extends EventTarget { static getTypeInternal_(favs, types) { var result = []; - var bucketFavs = googArray.bucket(favs, function(fav) { + var bucketFavs = favs ? osArray.bucket(favs, function(fav) { return fav['type']; - }); + }) : {}; osArray.forEach(types, function(type) { var favType = bucketFavs[type]; @@ -530,9 +530,9 @@ export default class FavoriteManager extends EventTarget { */ static getFoldersInternal_(favs, opt_ignore) { var result = []; - var bucketFavs = googArray.bucket(favs, function(fav) { + var bucketFavs = favs ? osArray.bucket(favs, function(fav) { return fav['type']; - }); + }) : {}; var folders = bucketFavs[FavoriteType.FOLDER]; if (folders) { diff --git a/src/plugin/arc/query/arcqueryhandler.js b/src/plugin/arc/query/arcqueryhandler.js index af58ae526..4f92a6b37 100644 --- a/src/plugin/arc/query/arcqueryhandler.js +++ b/src/plugin/arc/query/arcqueryhandler.js @@ -1,5 +1,6 @@ goog.declareModuleId('plugin.arc.query.ArcQueryHandler'); +import * as osArray from '../../../os/array/array.js'; import * as jsts from '../../../os/geo/jsts.js'; import QueryHandler from '../../../os/query/queryhandler.js'; import * as osUiFilter from '../../../os/ui/filter/filter.js'; @@ -7,7 +8,6 @@ import ArcFilterModifier from './arcfiltermodifier.js'; import ArcSpatialFormatter from './arcspatialformatter.js'; import ArcSpatialModifier from './arcspatialmodifier.js'; -const googArray = goog.require('goog.array'); const dispose = goog.require('goog.dispose'); const log = goog.require('goog.log'); const googObject = goog.require('goog.object'); @@ -116,7 +116,7 @@ class ArcQueryHandler extends QueryHandler { var activeEntries = this.getActiveEntries(); var entries = activeEntries.entries; - var bucket = googArray.bucket(entries, function(entry) { + var bucket = osArray.bucket(entries, function(entry) { // track which areaIds we've already seen since the expanded entries are inherently duplicative var areaId = entry['areaId']; if (this.includes(entry) && !seenAreas[areaId]) { From c80c3ed458325678b66b839cde78cdd3e4165f6f Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 14:35:31 -0700 Subject: [PATCH 21/23] feat(goog): remove goog.array.sort and others --- src/os/data/histo/sourcehistogram.js | 3 +-- src/os/layer/animationoverlay.js | 3 +-- src/os/layer/config/staticlayerconfig.js | 3 +-- src/os/time/timelinecontroller.js | 3 +-- src/os/ui/areas.js | 5 ++--- src/os/ui/capture/abstractcaptureplugin.js | 4 ++-- src/os/ui/geo/ringoptions.js | 4 +--- src/os/ui/search/facetedsearch.js | 4 ++-- src/os/ui/search/searchbox.js | 5 +---- src/os/unit/baseunit.js | 4 +--- src/os/unit/unitmanager.js | 3 +-- src/os/xt/peer.js | 2 +- src/plugin/descriptor/descriptorsearch.js | 5 +---- src/plugin/suncalc/suncalcui.js | 4 ++-- 14 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/os/data/histo/sourcehistogram.js b/src/os/data/histo/sourcehistogram.js index 97d07e467..ccf1dd75e 100644 --- a/src/os/data/histo/sourcehistogram.js +++ b/src/os/data/histo/sourcehistogram.js @@ -10,7 +10,6 @@ import DataModel from '../xf/datamodel.js'; import ColorBin from './colorbin.js'; import {HistoEventType} from './histogramutils.js'; -const googArray = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const EventTarget = goog.require('goog.events.EventTarget'); const GoogEventType = goog.require('goog.events.EventType'); @@ -605,7 +604,7 @@ export default class SourceHistogram extends EventTarget { })); if (this.sortFn) { - googArray.sort(results, this.sortFn); + results.sort(this.sortFn); } } diff --git a/src/os/layer/animationoverlay.js b/src/os/layer/animationoverlay.js index 3c38bd1aa..2771f7a6a 100644 --- a/src/os/layer/animationoverlay.js +++ b/src/os/layer/animationoverlay.js @@ -4,7 +4,6 @@ import {getMapContainer} from '../map/mapinstance.js'; import AnimationVector from './animationvector.js'; const Disposable = goog.require('goog.Disposable'); -const {clone} = goog.require('goog.array'); const OLVectorSource = goog.require('ol.source.Vector'); const Feature = goog.requireType('ol.Feature'); @@ -64,7 +63,7 @@ export default class AnimationOverlay extends Disposable { } if (options.features != null && Array.isArray(options.features)) { - this.setFeatures(clone(options.features)); + this.setFeatures(Array.from(options.features)); } if (options.map != null) { diff --git a/src/os/layer/config/staticlayerconfig.js b/src/os/layer/config/staticlayerconfig.js index 3eac12376..cc6db9789 100644 --- a/src/os/layer/config/staticlayerconfig.js +++ b/src/os/layer/config/staticlayerconfig.js @@ -5,7 +5,6 @@ import VectorLayer from '../vector.js'; import AbstractLayerConfig from './abstractlayerconfig.js'; import {LayerConfigId} from './layerconfig.js'; -const {clone} = goog.require('goog.array'); const {getLogger} = goog.require('goog.log'); const Logger = goog.requireType('goog.log.Logger'); @@ -48,7 +47,7 @@ export default class StaticLayerConfig extends AbstractLayerConfig { if (Array.isArray(options['data'])) { // make sure the array was created in this context - this.data = options['data'] = options['data'] instanceof Array ? options['data'] : clone(options['data']); + this.data = options['data'] = options['data'] instanceof Array ? options['data'] : Array.from(options['data']); } else { this.data = null; } diff --git a/src/os/time/timelinecontroller.js b/src/os/time/timelinecontroller.js index 1774a3e12..31d1d5831 100644 --- a/src/os/time/timelinecontroller.js +++ b/src/os/time/timelinecontroller.js @@ -11,7 +11,6 @@ import TimelineEventType from './timelineeventtype.js'; import TimeRange from './timerange.js'; const Timer = goog.require('goog.Timer'); -const googArray = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const EventTarget = goog.require('goog.events.EventTarget'); const iter = goog.require('goog.iter'); @@ -441,7 +440,7 @@ export default class TimelineController extends EventTarget { iter.forEach(rangeSet.__iterator__(false), function(value) { values.push(value.getLength()); }); - googArray.sort(values); + values.sort(); return values[0]; } diff --git a/src/os/ui/areas.js b/src/os/ui/areas.js index db5b0ebcf..1a87431d0 100644 --- a/src/os/ui/areas.js +++ b/src/os/ui/areas.js @@ -20,7 +20,6 @@ import Module from './module.js'; import * as CombinatorUI from './query/combinator.js'; import AbstractGroupByTreeSearchCtrl from './slick/abstractgroupbytreesearchctrl.js'; -const {flatten} = goog.require('goog.array'); const GoogEventType = goog.require('goog.events.EventType'); const GoogEvent = goog.requireType('goog.events.Event'); @@ -158,7 +157,7 @@ export class Controller extends AbstractGroupByTreeSearchCtrl { * @return {Array} Array of every area */ allAreas() { - var allAreas = flatten(this.scope['areas'].map(getLeafNodes)); + var allAreas = this.scope['areas'].map(getLeafNodes).flat(); return /** @type {Array} */ (allAreas); } @@ -167,7 +166,7 @@ export class Controller extends AbstractGroupByTreeSearchCtrl { * @return {Array} Array of every selected area */ selectedAreas() { - var selected = flatten(this.scope['selected'].map(getLeafNodes)); + var selected = this.scope['selected'].map(getLeafNodes).flat(); removeDuplicates(selected); return /** @type {Array} */ (selected); diff --git a/src/os/ui/capture/abstractcaptureplugin.js b/src/os/ui/capture/abstractcaptureplugin.js index d4ac46486..f8afc1266 100644 --- a/src/os/ui/capture/abstractcaptureplugin.js +++ b/src/os/ui/capture/abstractcaptureplugin.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.ui.capture.AbstractCapturePlugin'); import AlertEventSeverity from '../../alert/alerteventseverity.js'; import AlertManager from '../../alert/alertmanager.js'; +import {defaultSort} from '../../array/array.js'; import {ID, saveCanvas} from '../../capture/capture.js'; import TimelineRecorder from '../../capture/timelinerecorder.js'; import * as dispatcher from '../../dispatcher.js'; @@ -10,7 +11,6 @@ import TimelineEventType from '../../time/timelineeventtype.js'; import {launchRecordingUI} from './recordingui.js'; const Promise = goog.require('goog.Promise'); -const googArray = goog.require('goog.array'); const log = goog.require('goog.log'); const userAgent = goog.require('goog.userAgent'); @@ -265,5 +265,5 @@ const logger = log.getLogger('os.ui.capture.AbstractCapturePlugin'); * @return {number} The sort order. */ const rendererPrioritySort = function(a, b) { - return googArray.inverseDefaultCompare(a.priority, b.priority); + return -defaultSort(a.priority, b.priority); }; diff --git a/src/os/ui/geo/ringoptions.js b/src/os/ui/geo/ringoptions.js index d55ac2b19..837929a35 100644 --- a/src/os/ui/geo/ringoptions.js +++ b/src/os/ui/geo/ringoptions.js @@ -8,8 +8,6 @@ import {ROOT} from '../../os.js'; import Module from '../module.js'; import {getRingTitle} from './geo.js'; -const {peek} = goog.require('goog.array'); - /** * The ringoptions directive @@ -216,7 +214,7 @@ export class Controller { * @export */ add(opt_update) { - var last = peek(this['options'].rings); + var last = this['options'].rings[this['options'].rings.length - 1]; var radius = (last && last.radius || 0) + this['options'].interval; radius = roundWithPrecision(radius, precision(this['options'].interval)); this['options'].rings.push({'radius': radius, 'units': this['options'].units}); diff --git a/src/os/ui/search/facetedsearch.js b/src/os/ui/search/facetedsearch.js index fc4220a7a..50fbda6a9 100644 --- a/src/os/ui/search/facetedsearch.js +++ b/src/os/ui/search/facetedsearch.js @@ -8,7 +8,6 @@ import SlickTreeNode from '../slick/slicktreenode.js'; import {apply} from '../ui.js'; import FacetNode from './facetnode.js'; -const {sortObjectsByKey} = goog.require('goog.array'); const Delay = goog.require('goog.async.Delay'); const {caseInsensitiveCompare} = goog.require('goog.string'); @@ -176,6 +175,7 @@ export default class Controller { /** * Converts the facets to a proper tree for slick grid + * @suppress {checkTypes} To avoid [] access on a struct. */ onFacetLoad() { var applied = this.getAppliedFacets() || {}; @@ -215,7 +215,7 @@ export default class Controller { catNode.addChild(valueNode); } - sortObjectsByKey(catNode.getChildren(), 'label', caseInsensitiveCompare); + catNode.getChildren().sort((a, b) => caseInsensitiveCompare(a['label'], b['label'])); } } diff --git a/src/os/ui/search/searchbox.js b/src/os/ui/search/searchbox.js index 6bd8552cd..219d933c7 100644 --- a/src/os/ui/search/searchbox.js +++ b/src/os/ui/search/searchbox.js @@ -17,7 +17,6 @@ import FavoriteManager from '../../user/settings/favoritemanager.js'; import Module from '../module.js'; import {TypeaheadEventType, apply} from '../ui.js'; -const googArray = goog.require('goog.array'); const {contains: domContains, getAncestorByClass} = goog.require('goog.dom'); const googEvents = goog.require('goog.events'); const GoogEvent = goog.require('goog.events.Event'); @@ -637,9 +636,7 @@ export class Controller { */ getSearchOptionsGroup(groupName) { const group = this['searchOptionsGroups'][groupName]; - googArray.sort(group, function(a, b) { - return defaultSort(a.getName(), b.getName()); - }); + group.sort((a, b) => defaultSort(a.getName(), b.getName())); return group; } diff --git a/src/os/unit/baseunit.js b/src/os/unit/baseunit.js index 56ac055bf..ed4cf63df 100644 --- a/src/os/unit/baseunit.js +++ b/src/os/unit/baseunit.js @@ -1,7 +1,5 @@ goog.declareModuleId('os.unit.BaseUnit'); -const googArray = goog.require('goog.array'); - const {default: IMultiplier} = goog.requireType('os.unit.IMultiplier'); const {default: IUnit} = goog.requireType('os.unit.IUnit'); @@ -137,7 +135,7 @@ export default class BaseUnit { */ initBestFitCandidates() { this.bestFitCandidates = this.multipliers.filter(this.getIsBestFitCandidate); - googArray.sort(this.bestFitCandidates, function(multA, multB) { // sort from largest to smallest + this.bestFitCandidates.sort((multA, multB) => { // sort from largest to smallest return multA.getMultiplier() < multB.getMultiplier() ? 1 : -1; }); } diff --git a/src/os/unit/unitmanager.js b/src/os/unit/unitmanager.js index d43e67a0d..32bff07e3 100644 --- a/src/os/unit/unitmanager.js +++ b/src/os/unit/unitmanager.js @@ -6,7 +6,6 @@ import {UNITS, UnitSystem} from './unit.js'; import UnitChange from './unitchange.js'; import UnitFactory from './unitfactory.js'; -const googArray = goog.require('goog.array'); const EventTarget = goog.require('goog.events.EventTarget'); const log = goog.require('goog.log'); const {default: SettingChangeEvent} = goog.requireType('os.events.SettingChangeEvent'); @@ -56,7 +55,7 @@ export default class UnitManager extends EventTarget { * @private */ this.systems_ = this.unitFactory_.getSystems(); - googArray.sort(this.systems_); + this.systems_.sort(); Settings.getInstance().listen(UNITS, this.onUnitsChange_, false, this); } diff --git a/src/os/xt/peer.js b/src/os/xt/peer.js index 03aa26683..8e50f9637 100644 --- a/src/os/xt/peer.js +++ b/src/os/xt/peer.js @@ -603,7 +603,7 @@ export default class Peer { // add self peerIds.push(this.getId()); // sort, "smallest" peer ID becomes master - googArray.sort(peerIds); + peerIds.sort(); if (peerIds[0] === this.getId()) { // it's me! this.becomeMaster_(); diff --git a/src/plugin/descriptor/descriptorsearch.js b/src/plugin/descriptor/descriptorsearch.js index 713710d8d..533d1abfd 100644 --- a/src/plugin/descriptor/descriptorsearch.js +++ b/src/plugin/descriptor/descriptorsearch.js @@ -16,7 +16,6 @@ import TagSplit from './facet/tagsplitfacet.js'; import Type from './facet/typefacet.js'; const Promise = goog.require('goog.Promise'); -const googArray = goog.require('goog.array'); const log = goog.require('goog.log'); const {default: IDataDescriptor} = goog.requireType('os.data.IDataDescriptor'); @@ -150,9 +149,7 @@ export default class DescriptorSearch extends AbstractSearch { } } - googArray.sort(results, function(a, b) { - return defaultSort(b.getScore(), a.getScore()); - }); + results.sort((a, b) => defaultSort(b.getScore(), a.getScore())); if (promises.length) { var self = this; diff --git a/src/plugin/suncalc/suncalcui.js b/src/plugin/suncalc/suncalcui.js index 019c37b4e..63dbcdc86 100644 --- a/src/plugin/suncalc/suncalcui.js +++ b/src/plugin/suncalc/suncalcui.js @@ -1,5 +1,6 @@ goog.declareModuleId('plugin.suncalc.SunCalcUI'); +import {defaultSort} from '../../os/array/array.js'; import settings from '../../os/config/settings.js'; import * as geo from '../../os/geo/geo.js'; import * as osMap from '../../os/map/map.js'; @@ -13,7 +14,6 @@ import * as ui from '../../os/ui/ui.js'; import * as osWindow from '../../os/ui/window.js'; import {SettingKey} from './suncalc.js'; -const googArray = goog.require('goog.array'); const color = goog.require('goog.color'); const olProj = goog.require('ol.proj'); @@ -224,7 +224,7 @@ export class Controller { times = times.filter(filter); times.forEach(addTextColor); - googArray.sortObjectsByKey(times, 'time'); + times.sort((a, b) => defaultSort(a['time'], b['time'])); sets.push(times); this.scope_['times'] = times; From 507a8454df56491ec60da1171358755cb426e301 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Thu, 17 Feb 2022 15:18:28 -0700 Subject: [PATCH 22/23] feat(goog): remove goog.array.rotate/extend/reduce --- src/os/track/track.js | 2 +- src/os/ui/timeline/abstracttimelinectrl.js | 5 ++-- src/os/ui/timeline/timelineui.js | 6 ++--- src/os/ui/util/autovheight.js | 3 +-- src/os/user/settings/favoritemanager.js | 28 ++++++++-------------- src/os/xt/peer.js | 9 +++---- 6 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/os/track/track.js b/src/os/track/track.js index 69b1c1ce4..cb777e03e 100644 --- a/src/os/track/track.js +++ b/src/os/track/track.js @@ -1286,7 +1286,7 @@ export const getTimeIndex = function(coordinates, value, stride) { // find the closest timestamp to the current timeline position var index = osArray.binaryStrideSearch(coordinates, value, stride, stride - 1); if (index < 0) { - // if current isn't in the array, goog.array.binarySearch will return (-(insertion point) - 1) + // if current isn't in the array, binarySearch will return (-(insertion point) - 1) index = -index - 1; } diff --git a/src/os/ui/timeline/abstracttimelinectrl.js b/src/os/ui/timeline/abstracttimelinectrl.js index 4a78505cf..2ab8ec807 100644 --- a/src/os/ui/timeline/abstracttimelinectrl.js +++ b/src/os/ui/timeline/abstracttimelinectrl.js @@ -29,7 +29,6 @@ import SelectBrush from './selectbrush.js'; import TileAxis from './tileaxis.js'; import * as timelineUi from './timeline.js'; -const googArray = goog.require('goog.array'); const asserts = goog.require('goog.asserts'); const Delay = goog.require('goog.async.Delay'); const dispose = goog.require('goog.dispose'); @@ -181,7 +180,7 @@ export default class Controller { (Settings.getInstance().get(['ui', 'timelineSettings', 'chartType'], 'line')); var histClassIdx = this.histClasses_.indexOf(histClass); if (histClassIdx > -1) { - googArray.rotate(this.histClasses_, histClassIdx); + this.histClasses_.unshift(...this.histClasses_.splice(-histClassIdx, histClassIdx)); this['histClass'] = hist.CHART_TYPES[this.histClasses_[0]]; } @@ -831,7 +830,7 @@ export default class Controller { * @export */ toggleChartType() { - googArray.rotate(this.histClasses_, 1); + this.histClasses_.unshift(this.histClasses_.pop()); var chartType = this.histClasses_[0]; this['histClass'] = hist.CHART_TYPES[chartType]; diff --git a/src/os/ui/timeline/timelineui.js b/src/os/ui/timeline/timelineui.js index 9c747ed79..d0cc7ebd5 100644 --- a/src/os/ui/timeline/timelineui.js +++ b/src/os/ui/timeline/timelineui.js @@ -19,7 +19,7 @@ import * as timelineUi from './timeline.js'; import TimelineScaleEvent from './timelinescaleevent.js'; const Timer = goog.require('goog.Timer'); -const googArray = goog.require('goog.array'); +const {binarySearch} = goog.require('goog.array'); const Throttle = goog.require('goog.async.Throttle'); const dispose = goog.require('goog.dispose'); const GoogEventType = goog.require('goog.events.EventType'); @@ -1090,7 +1090,7 @@ export class Controller { // for the snap interval, find the scale step that is closest to 10 pixels wide var steps = timelineUi.SNAP_SCALE; - var i = googArray.binarySearch(steps, px10time); + var i = binarySearch(steps, px10time); if (i < 0) { i = Math.min(Math.abs(i + 1), steps.length - 1); @@ -1420,7 +1420,7 @@ export class Controller { static getSnap(target) { // Get the closest item on the snap scale to the target var arr = timelineUi.SNAP_SCALE; - var i = googArray.binarySearch(arr, target); + var i = binarySearch(arr, target); if (i < 0) { i = Math.min(Math.abs(i + 1), arr.length - 1); diff --git a/src/os/ui/util/autovheight.js b/src/os/ui/util/autovheight.js index 24dda4922..d0db8c682 100644 --- a/src/os/ui/util/autovheight.js +++ b/src/os/ui/util/autovheight.js @@ -7,7 +7,6 @@ import {removeResize, resize, waitForAngular} from '../ui.js'; import windowCommonElements from '../windowcommonelements.js'; import windowCommonOptionalElements from '../windowcommonoptionalelements.js'; -const googArray = goog.require('goog.array'); const ViewportSizeMonitor = goog.require('goog.dom.ViewportSizeMonitor'); const GoogEventType = goog.require('goog.events.EventType'); const googObject = goog.require('goog.object'); @@ -238,7 +237,7 @@ export class Controller { // remove resize from common elements var allCommonElements = Array.from(windowCommonElements); - googArray.extend(allCommonElements, windowCommonOptionalElements); + allCommonElements.push(...windowCommonOptionalElements); allCommonElements.forEach(function(sibling) { if (this.resizeFn_) { removeResize($(/** @type {string} */ (sibling)), this.resizeFn_); diff --git a/src/os/user/settings/favoritemanager.js b/src/os/user/settings/favoritemanager.js index 1b59b5c53..e2cdf82c4 100644 --- a/src/os/user/settings/favoritemanager.js +++ b/src/os/user/settings/favoritemanager.js @@ -8,8 +8,6 @@ import * as osObject from '../../object/object.js'; import * as url from '../../url/url.js'; import FavoriteType from './favoritetype.js'; -const googArray = goog.require('goog.array'); - const EventTarget = goog.require('goog.events.EventTarget'); const googString = goog.require('goog.string'); @@ -108,7 +106,7 @@ export default class FavoriteManager extends EventTarget { * Get the favorite's folders * * @param {string} key - * @return {Array} + * @return {!Array} */ getFavoriteFolders(key) { var favFolders = []; @@ -118,10 +116,7 @@ export default class FavoriteManager extends EventTarget { if (folders) { for (var i = 0; i < folders.length; i++) { var folder = folders[i]; - var foundFolders = FavoriteManager.getFavoriteFoldersInternal_(folder, key); - if (foundFolders) { - googArray.extend(favFolders, foundFolders); - } + favFolders.push(...FavoriteManager.getFavoriteFoldersInternal_(folder, key)); } } osArray.removeDuplicates(favFolders); @@ -413,7 +408,7 @@ export default class FavoriteManager extends EventTarget { * * @param {FavoriteSetting} folder * @param {string} key - * @return {Array} - the folder keys the favorite was found in + * @return {!Array} - the folder keys the favorite was found in * @private */ static getFavoriteFoldersInternal_(folder, key) { @@ -426,10 +421,7 @@ export default class FavoriteManager extends EventTarget { if (fav['key'] == key) { favFolders.push(folder['key']); } else if (fav['type'] == FavoriteType.FOLDER) { - var foundFolders = FavoriteManager.getFavoriteFoldersInternal_(fav, key); - if (foundFolders) { - googArray.extend(favFolders, foundFolders); - } + favFolders.push(...FavoriteManager.getFavoriteFoldersInternal_(fav, key)); } } } @@ -494,7 +486,7 @@ export default class FavoriteManager extends EventTarget { * * @param {Array} favs * @param {Array} types - * @return {Array} + * @return {!Array} * @private */ static getTypeInternal_(favs, types) { @@ -507,7 +499,7 @@ export default class FavoriteManager extends EventTarget { osArray.forEach(types, function(type) { var favType = bucketFavs[type]; if (favType) { - googArray.extend(result, favType); + result.push(...favType); } }); @@ -515,7 +507,7 @@ export default class FavoriteManager extends EventTarget { var folders = bucketFavs[FavoriteType.FOLDER]; if (folders) { osArray.forEach(folders, function(folder) { - googArray.extend(result, FavoriteManager.getTypeInternal_(folder['children'], types)); + result.push(...FavoriteManager.getTypeInternal_(folder['children'], types)); }); } @@ -525,7 +517,7 @@ export default class FavoriteManager extends EventTarget { /** * @param {Array} favs * @param {Array=} opt_ignore - ignore this folder key and all child folders - * @return {Array} + * @return {!Array} * @private */ static getFoldersInternal_(favs, opt_ignore) { @@ -544,9 +536,9 @@ export default class FavoriteManager extends EventTarget { } } - googArray.extend(result, folders); + result.push(...folders); osArray.forEach(folders, function(folder) { - googArray.extend(result, FavoriteManager.getFoldersInternal_(folder['children'], opt_ignore)); + result.push(...FavoriteManager.getFoldersInternal_(folder['children'], opt_ignore)); }); } diff --git a/src/os/xt/peer.js b/src/os/xt/peer.js index 8e50f9637..4bc671b82 100644 --- a/src/os/xt/peer.js +++ b/src/os/xt/peer.js @@ -7,7 +7,6 @@ import PeerInfo from './peerinfo.js'; import {isMaster, getMasterKey, getPingKey, getLastPing, cleanupPeer, prepareSendData} from './xt.js'; const Timer = goog.require('goog.Timer'); -const googArray = goog.require('goog.array'); const Deferred = goog.require('goog.async.Deferred'); const Delay = goog.require('goog.async.Delay'); const googEvents = goog.require('goog.events'); @@ -846,9 +845,11 @@ export default class Peer { if (this.waitList_.length) { now = Date.now(); var nextExpiration = now + Peer.PING_INTERVAL; - nextExpiration = googArray.reduce(this.waitList_, function(minExpiration, wait, i, a) { - return Math.min(minExpiration, wait.expiration); - }, nextExpiration); + nextExpiration = this.waitList_.reduce( + function(minExpiration, wait, i, a) { + return Math.min(minExpiration, wait.expiration); + }, + nextExpiration); this.waitListDelay_.start(nextExpiration - now); } } From a334096320e43831290a74d592db28119f280d48 Mon Sep 17 00:00:00 2001 From: Tatiana Smith Date: Fri, 18 Feb 2022 10:21:58 -0700 Subject: [PATCH 23/23] feat(goog): replace goog.isArrayLike and goog.isObject --- src/os/array/array.js | 24 ++++++++++++++++++++--- src/os/config/settings.js | 4 ++-- src/os/file/index.js | 3 ++- src/os/file/mime/jsonsettings.js | 4 +++- src/os/file/mime/jsonstate.js | 3 ++- src/os/layer/image.js | 3 ++- src/os/layer/tile.js | 3 ++- src/os/layer/vector.js | 3 ++- src/os/net/net.js | 4 ++-- src/os/object/object.js | 15 +++++++++++--- src/os/os.js | 3 ++- src/os/source/vectorsource.js | 4 ++-- src/os/state/v2/layerstate.js | 3 ++- src/os/state/v3/layerstate.js | 3 ++- src/os/state/v4/baselayerstate.js | 3 ++- src/os/ui/actionmenu.js | 8 ++++---- src/os/ui/globalmenu.js | 3 ++- src/os/ui/layer/layers.js | 3 ++- src/os/ui/onboarding/onboardingmanager.js | 3 ++- src/os/ui/slick/slickgrid.js | 5 +++-- src/os/ui/slickpropertiesasyncrenderer.js | 3 ++- src/os/ui/state/stateimportui.js | 7 ++++--- src/os/ui/twocolumninfo.js | 3 ++- src/plugin/arc/arcjsonparser.js | 3 ++- src/plugin/file/geojson/geojsonparser.js | 5 +++-- src/plugin/file/geojson/mime.js | 3 ++- src/plugin/file/kml/kml.js | 2 +- src/plugin/heatmap/heatmaplayer.js | 3 ++- src/plugin/openpage/handler.js | 3 ++- 29 files changed, 93 insertions(+), 43 deletions(-) diff --git a/src/os/array/array.js b/src/os/array/array.js index 2855b64d7..db9e24d18 100644 --- a/src/os/array/array.js +++ b/src/os/array/array.js @@ -1,5 +1,7 @@ goog.declareModuleId('os.array'); +import {isObject} from '../object/object.js'; + const googArray = goog.require('goog.array'); const math = goog.require('goog.math'); @@ -144,8 +146,7 @@ export const intersection = function(arr1, arr2) { export const findDuplicates = function(arr, opt_hashFn) { var returnArray = []; var defaultHashFn = function(item) { - return goog.isObject(current) ? 'o' + goog.getUid(current) : - (typeof current).slice(0, 2) + current; + return isObject(current) ? 'o' + goog.getUid(current) : (typeof current).slice(0, 2) + current; }; var hashFn = opt_hashFn || defaultHashFn; @@ -182,7 +183,7 @@ export const removeDuplicates = function(arr, opt_rv, opt_hashFn) { // it checks if an object is also an array before just checking the uid, if it is an array then allow comparison of // the stringified array var defaultHashFn = function(item) { - return goog.isObject(current) ? + return isObject(current) ? Array.isArray(current) ? 'a' + JSON.stringify(current) : 'o' + goog.getUid(current) : @@ -386,6 +387,23 @@ export const bucket = function(arr, sortFn, opt_obj) { return buckets; }; +/** + * Based on the goog.array.isArrayLike method. + * Used to tell if something is an array, NodeList, or other object with a number length property. + * @param {?} val the variable to test + * @return {boolean} if the variable is arraylike + */ +export const isArrayLike = function(val) { + if (val == null) { + return false; + } else if (Array.isArray(val)) { + return true; + } else if (typeof val == 'object' && typeof val.length == 'number') { + return true; + } + return false; +}; + /** * @param {VALUE} a * @param {VALUE} b diff --git a/src/os/config/settings.js b/src/os/config/settings.js index 08f41dca3..a129fb097 100644 --- a/src/os/config/settings.js +++ b/src/os/config/settings.js @@ -673,8 +673,8 @@ export default class Settings extends EventTarget { var val = googObject.getValueByKeys(this.mergedConfig_, keys); if (Array.isArray(val)) { val = Array.from(val); - } else if (goog.isObject(val)) { - val = googObject.clone(val); + } else if (osObject.isObject(val)) { + val = googObject.clone(/** @type {Object} */(val)); } return val !== undefined ? val : opt_default; diff --git a/src/os/file/index.js b/src/os/file/index.js index 1a51e9a6d..4e0e27e33 100644 --- a/src/os/file/index.js +++ b/src/os/file/index.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.file'); +import {isObject} from '../object/object.js'; import {ROOT} from '../os.js'; import OSFile from './file.js'; import * as mimeZip from './mime/zip.js'; @@ -190,7 +191,7 @@ export const isLocal = function(file) { */ export const deserializeFile = function(data) { var file = null; - if (data && goog.isObject(data)) { + if (data && isObject(data)) { file = new OSFile(); file.restore(data); } diff --git a/src/os/file/mime/jsonsettings.js b/src/os/file/mime/jsonsettings.js index a9f07c9ba..b1ad7d8c9 100644 --- a/src/os/file/mime/jsonsettings.js +++ b/src/os/file/mime/jsonsettings.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.file.mime.jsonsettings'); +import {isObject} from '../../object/object.js'; import * as mime from '../mime.js'; import * as jsonMime from './json.js'; @@ -30,7 +31,8 @@ const rootKeys = ['admin', 'user', 'overrides']; export const detect = function(buffer, file, opt_context) { var retVal; - if (opt_context && goog.isObject(opt_context) && Object.keys(opt_context).some((key) => rootKeys.indexOf(key) > -1)) { + if (opt_context && isObject(opt_context) && + Object.keys(/** @type {Object} */ (opt_context) || {}).some((key) => rootKeys.indexOf(key) > -1)) { retVal = opt_context; } diff --git a/src/os/file/mime/jsonstate.js b/src/os/file/mime/jsonstate.js index 911ec61ee..9df909b82 100644 --- a/src/os/file/mime/jsonstate.js +++ b/src/os/file/mime/jsonstate.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.file.mime.jsonstate'); +import {isObject} from '../../object/object.js'; import Tag from '../../state/tag.js'; import * as mime from '../mime.js'; import * as json from './json.js'; @@ -23,7 +24,7 @@ export const TYPE = 'application/vnd.state+json'; export const detect = function(buffer, file, opt_context) { var retVal; - if (opt_context && goog.isObject(opt_context) && Array.isArray(opt_context[Tag.STATE])) { + if (opt_context && isObject(opt_context) && Array.isArray(opt_context[Tag.STATE])) { retVal = opt_context; } diff --git a/src/os/layer/image.js b/src/os/layer/image.js index 14691b33f..a072a738e 100644 --- a/src/os/layer/image.js +++ b/src/os/layer/image.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.layer.Image'); import EventType from '../action/eventtype.js'; +import {isArrayLike} from '../array/array.js'; import {adjustColor, adjustSharpness} from '../color.js'; import * as dispatcher from '../dispatcher.js'; import LayerEvent from '../events/layerevent.js'; @@ -675,7 +676,7 @@ export default class Image extends ImageLayer { case EventType.REFRESH: return true; case EventType.RENAME: - return !!opt_actionArgs && goog.isArrayLike(opt_actionArgs) && opt_actionArgs.length === 1; + return !!opt_actionArgs && isArrayLike(opt_actionArgs) && opt_actionArgs.length === 1; case EventType.REMOVE_LAYER: return this.isRemovable(); default: diff --git a/src/os/layer/tile.js b/src/os/layer/tile.js index b95135455..267d14813 100644 --- a/src/os/layer/tile.js +++ b/src/os/layer/tile.js @@ -3,6 +3,7 @@ goog.declareModuleId('os.layer.Tile'); import '../mixin/tileimagemixin.js'; import '../mixin/urltilemixin.js'; import EventType from '../action/eventtype.js'; +import {isArrayLike} from '../array/array.js'; import * as osColor from '../color.js'; import DataManager from '../data/datamanager.js'; import * as dispatcher from '../dispatcher.js'; @@ -963,7 +964,7 @@ export default class Tile extends OLTileLayer { case EventType.SHOW_DESCRIPTION: return true; case EventType.RENAME: - return !!opt_actionArgs && goog.isArrayLike(opt_actionArgs) && opt_actionArgs.length === 1; + return !!opt_actionArgs && isArrayLike(opt_actionArgs) && opt_actionArgs.length === 1; case EventType.MOST_RECENT: // only enable if descriptor exists and max date is greater than 0 var desc = DataManager.getInstance().getDescriptor(this.getId()); diff --git a/src/os/layer/vector.js b/src/os/layer/vector.js index 947c65ed8..19e063b06 100644 --- a/src/os/layer/vector.js +++ b/src/os/layer/vector.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.layer.Vector'); import ActionEventType from '../action/eventtype.js'; +import {isArrayLike} from '../array/array.js'; import {toRgbArray} from '../color.js'; import DataManager from '../data/datamanager.js'; import IMappingDescriptor from '../data/imappingdescriptor.js'; @@ -996,7 +997,7 @@ export default class Vector extends OLVectorLayer { supportsAction(type, opt_actionArgs) { const source = /** @type {VectorSource} */ (this.getSource()); const isVector = source instanceof VectorSource; - const onlyOneLayer = !!opt_actionArgs && goog.isArrayLike(opt_actionArgs) && opt_actionArgs.length === 1; + const onlyOneLayer = !!opt_actionArgs && isArrayLike(opt_actionArgs) && opt_actionArgs.length === 1; switch (type) { case ActionEventType.GOTO: diff --git a/src/os/net/net.js b/src/os/net/net.js index c2e925268..3a3f8115b 100644 --- a/src/os/net/net.js +++ b/src/os/net/net.js @@ -4,7 +4,7 @@ import {defaultSort} from '../array/array.js'; import {registerClass} from '../classregistry.js'; import {getSettings} from '../config/configinstance.js'; import instanceOf from '../instanceof.js'; -import {merge} from '../object/object.js'; +import {isObject, merge} from '../object/object.js'; import CrossOrigin from './crossorigin.js'; const Uri = goog.require('goog.Uri'); @@ -364,7 +364,7 @@ export const paramsToQueryData = function(params) { qd = /** @type {QueryData} */ (params); } else { // create a new one from the object or an empty one - qd = goog.isObject(params) ? QueryData.createFromMap(params) : null; + qd = (params != null && isObject(params)) ? QueryData.createFromMap(params) : null; } return qd || new QueryData(); diff --git a/src/os/object/object.js b/src/os/object/object.js index 277cb1e8f..03a0bf92c 100644 --- a/src/os/object/object.js +++ b/src/os/object/object.js @@ -132,7 +132,7 @@ export const setValue = function(obj, keys, value) { if (index === lastKeyIndex) { lastLevel[key] = value; } else { - lastLevel[key] = goog.isObject(lastLevel[key]) ? lastLevel[key] : {}; + lastLevel[key] = isObject(lastLevel[key]) ? lastLevel[key] : {}; lastLevel = lastLevel[key]; } }); @@ -158,8 +158,8 @@ export const reduce = function(obj, opt_prefix, opt_delim) { if (isPrimitive(obj) || Array.isArray(obj)) { // write primitives and arrays to the reduced result result[prefix] = obj; - } else if (goog.isObject(obj)) { - if (isEmpty(obj)) { + } else if (isObject(obj)) { + if (isEmpty(/** @type {Object} */ (obj))) { // if the object doesn't contain any keys, write the empty object to the result result[prefix] = obj; } else { @@ -359,3 +359,12 @@ export const unsafeClone = function(obj) { return obj; }; + +/** + * Based on goog.isObject. Returns true if the value is an object - including arrays and functions. + * @param {?} val the variable to test + * @return {boolean} if the variable is an object + */ +export const isObject = function(val) { + return typeof val == 'object' && val != null || typeof val == 'function'; +}; diff --git a/src/os/os.js b/src/os/os.js index 7e0057614..a1a20b0b8 100644 --- a/src/os/os.js +++ b/src/os/os.js @@ -3,6 +3,7 @@ goog.declareModuleId('os'); import './mixin/closuremixin.js'; import './ol/license.js'; import './ol/typedefs.js'; +import {isArrayLike} from './array/array.js'; import * as keys from './metrics/metricskeys.js'; const EventTarget = goog.require('goog.events.EventTarget'); @@ -169,7 +170,7 @@ export const isNumeric = function(obj) { // parseFloat NaNs numeric-cast false positives (null|true|false|"") // ...but misinterprets leading-number strings, particularly hex literals ("0x...") // subtraction forces infinities to NaN - return !goog.isArrayLike(obj) && obj - parseFloat(obj) >= 0; + return !isArrayLike(obj) && obj - parseFloat(obj) >= 0; }; /** diff --git a/src/os/source/vectorsource.js b/src/os/source/vectorsource.js index 691a99c1b..4d8e3ab49 100644 --- a/src/os/source/vectorsource.js +++ b/src/os/source/vectorsource.js @@ -36,7 +36,7 @@ import AnimationOverlay from '../layer/animationoverlay.js'; import LoadingManager from '../load/loadingmanager.js'; import * as osMap from '../map/map.js'; import {getMapContainer} from '../map/mapinstance.js'; -import {getValueExtractor, prune} from '../object/object.js'; +import {getValueExtractor, isObject, prune} from '../object/object.js'; import {getMaxFeatures} from '../ogc/ogc.js'; import {ROOT} from '../os.js'; import {isFloat} from '../string/string.js'; @@ -1002,7 +1002,7 @@ export default class Vector extends OLVectorSource { var field = null; if (typeof value === 'string') { field = value; - } else if (goog.isObject(value)) { + } else if (isObject(value)) { field = /** @type {ColumnDefinition} */ (value)['field']; } diff --git a/src/os/state/v2/layerstate.js b/src/os/state/v2/layerstate.js index 69d65e240..10ee77d15 100644 --- a/src/os/state/v2/layerstate.js +++ b/src/os/state/v2/layerstate.js @@ -8,6 +8,7 @@ import {isLocal} from '../../file/index.js'; import MappingManager from '../../im/mapping/mappingmanager.js'; import LayerConfigManager from '../../layer/config/layerconfigmanager.js'; import {getMapContainer} from '../../map/mapinstance.js'; +import {isObject} from '../../object/object.js'; import {isBoolean, isFloat, isHex} from '../../string/string.js'; import * as osLabel from '../../style/label.js'; import * as osStyle from '../../style/style.js'; @@ -436,7 +437,7 @@ export default class LayerState extends XMLState { } catch (e) { // don't persist it } - } else if (goog.isObject(value) && typeof value !== 'function') { + } else if (isObject(value) && typeof value !== 'function') { // plain objects // create the node for this key and recurse node = appendElement(key, layerEl); diff --git a/src/os/state/v3/layerstate.js b/src/os/state/v3/layerstate.js index 3b9ebc70d..beca3fff0 100644 --- a/src/os/state/v3/layerstate.js +++ b/src/os/state/v3/layerstate.js @@ -10,6 +10,7 @@ import {isLocal} from '../../file/index.js'; import MappingManager from '../../im/mapping/mappingmanager.js'; import LayerConfigManager from '../../layer/config/layerconfigmanager.js'; import {getMapContainer} from '../../map/mapinstance.js'; +import {isObject} from '../../object/object.js'; import VectorSource from '../../source/vectorsource.js'; import {isBoolean, isFloat, isHex} from '../../string/string.js'; import * as osLabel from '../../style/label.js'; @@ -491,7 +492,7 @@ export default class LayerState extends XMLState { } catch (e) { // don't persist it } - } else if (goog.isObject(value) && typeof value !== 'function') { + } else if (isObject(value) && typeof value !== 'function') { // plain objects // create the node for this key and recurse node = appendElement(key, layerEl); diff --git a/src/os/state/v4/baselayerstate.js b/src/os/state/v4/baselayerstate.js index 021ba204f..258c048f8 100644 --- a/src/os/state/v4/baselayerstate.js +++ b/src/os/state/v4/baselayerstate.js @@ -11,6 +11,7 @@ import MappingManager from '../../im/mapping/mappingmanager.js'; import LayerConfigManager from '../../layer/config/layerconfigmanager.js'; import * as osMap from '../../map/map.js'; import {paramsToQueryData} from '../../net/net.js'; +import {isObject} from '../../object/object.js'; import {EPSG4326} from '../../proj/proj.js'; import VectorSource from '../../source/vectorsource.js'; import {isBoolean, isFloat, isHex} from '../../string/string.js'; @@ -626,7 +627,7 @@ export default class BaseLayerState extends XMLState { } catch (e) { // don't persist it } - } else if (goog.isObject(value) && typeof value !== 'function') { + } else if (isObject(value) && typeof value !== 'function') { // plain objects // create the node for this key and recurse node = appendElement(key, layerEl); diff --git a/src/os/ui/actionmenu.js b/src/os/ui/actionmenu.js index 6ad0c4ada..c50f59e94 100644 --- a/src/os/ui/actionmenu.js +++ b/src/os/ui/actionmenu.js @@ -2,7 +2,7 @@ goog.declareModuleId('os.ui.ActionMenuUI'); import Metrics from '../metrics/metrics.js'; -import {setValue} from '../object/object.js'; +import {isObject, setValue} from '../object/object.js'; import {ROOT} from '../os.js'; import EventType from './action/actioneventtype.js'; import MenuItemAction from './action/menuitemaction.js'; @@ -283,7 +283,7 @@ export class Controller { menuItems, new MenuItemAction(action), this.sortByDivisionThenOrder_); - } else if (goog.isObject(value)) { + } else if (isObject(value)) { var division; var keyTokens = key.split('/'); if (keyTokens.length > 1) { @@ -356,7 +356,7 @@ export class Controller { this.timeout(function() { element.removeClass('right-menu'); - if (goog.isObject(pos)) { + if (isObject(pos)) { var x = pos.left || pos.x; var y = pos.top || pos.y; var w = element.outerWidth(); @@ -405,7 +405,7 @@ export class Controller { var pos = submenu.offset(); - if (goog.isObject(pos)) { + if (isObject(pos)) { var y = pos.top || pos.y; var h = submenu.outerHeight(); var viewportSize = getViewportSize(); diff --git a/src/os/ui/globalmenu.js b/src/os/ui/globalmenu.js index 8669dba38..700134670 100644 --- a/src/os/ui/globalmenu.js +++ b/src/os/ui/globalmenu.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.ui.GlobalMenuUI'); import * as dispatcher from '../dispatcher.js'; +import {isObject} from '../object/object.js'; import {Controller as ActionMenuCtrl, directive as actionMenuDirective} from './actionmenu.js'; import GlobalMenuEventType from './globalmenueventtype.js'; import Module from './module.js'; @@ -165,7 +166,7 @@ export class Controller extends ActionMenuCtrl { var pos = this.scope['position'] || element.position(); this.timeout(function() { - if (goog.isObject(pos)) { + if (isObject(pos)) { var x = pos.left || pos.right || pos.x; var y = pos.top || pos.bottom || pos.y; var w = element.outerWidth(); diff --git a/src/os/ui/layer/layers.js b/src/os/ui/layer/layers.js index 275521e2c..1731f0ae6 100644 --- a/src/os/ui/layer/layers.js +++ b/src/os/ui/layer/layers.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.ui.layer'); import {instanceOf} from '../../classregistry.js'; +import {isObject} from '../../object/object.js'; import SourceClass from '../../source/sourceclass.js'; import {cloneConfig} from '../../style/label.js'; import {getConfigColor} from '../../style/style.js'; @@ -120,7 +121,7 @@ export const getStyles = function(layer) { export const getStyle = function(layer) { var style = /** @type {TileLayer} */ (layer).getStyle(); - if (goog.isObject(style)) { + if (isObject(style)) { return /** @type {!osx.ogc.TileStyle} */ (style); } diff --git a/src/os/ui/onboarding/onboardingmanager.js b/src/os/ui/onboarding/onboardingmanager.js index 25cc7f7a6..9cf800c6e 100644 --- a/src/os/ui/onboarding/onboardingmanager.js +++ b/src/os/ui/onboarding/onboardingmanager.js @@ -2,6 +2,7 @@ goog.declareModuleId('os.ui.onboarding.OnboardingManager'); import Settings from '../../config/settings.js'; import Request from '../../net/request.js'; +import {isObject} from '../../object/object.js'; import {ROOT} from '../../os.js'; import RouteManager from '../route/routemanager.js'; import OnboardingEvent from './onboardingevent.js'; @@ -104,7 +105,7 @@ export default class OnboardingManager extends EventTarget { request.listenOnce(EventType.SUCCESS, goog.partial(this.onLoad_, show), false, this); request.listenOnce(EventType.ERROR, this.onError_, false, this); request.load(); - } else if (show && goog.isObject(ob)) { + } else if (show && isObject(ob)) { // only display the onboarding if the value isn't the placeholder boolean this.launchOnboarding_(uri, /** @type {OnboardingConfig} */ (ob)); } diff --git a/src/os/ui/slick/slickgrid.js b/src/os/ui/slick/slickgrid.js index 1b84f170d..aea273780 100644 --- a/src/os/ui/slick/slickgrid.js +++ b/src/os/ui/slick/slickgrid.js @@ -6,6 +6,7 @@ import {defaultSort} from '../../array/array.js'; import {killRightButton} from '../../events/events.js'; import {filterFalsey} from '../../fn/fn.js'; import osImplements from '../../implements.js'; +import {isObject} from '../../object/object.js'; import {FLOAT} from '../../string/string.js'; import ActionManager from '../action/actionmanager.js'; import {launchColumnManager} from '../column/column.js'; @@ -1114,7 +1115,7 @@ export class Controller extends Disposable { at: 'left+' + event.clientX + ' top+' + event.clientY, of: windowSelector.CONTAINER }; - } else if (goog.isObject(opt_position)) { + } else if (isObject(opt_position)) { // event was fired on the scope position = opt_position; } @@ -1475,7 +1476,7 @@ export class Controller extends Disposable { // make a new scope var s = this.scope.$new(); - if (goog.isObject(this.scope['rowScope'])) { + if (isObject(this.scope['rowScope'])) { Object.assign(s, this.scope['rowScope']); } diff --git a/src/os/ui/slickpropertiesasyncrenderer.js b/src/os/ui/slickpropertiesasyncrenderer.js index 647641a62..8d8643d37 100644 --- a/src/os/ui/slickpropertiesasyncrenderer.js +++ b/src/os/ui/slickpropertiesasyncrenderer.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.ui.SlickPropertiesAsyncRenderer'); import Fields from '../fields/fields.js'; +import {isObject} from '../object/object.js'; import {inIframe} from '../os.js'; import {launchPropertyInfo} from './propertyinfo.js'; @@ -40,7 +41,7 @@ const SlickPropertiesAsyncRenderer = function(elem, row, dataContext, colDef) { * @param {Object} object */ const processProperty = function(value, index, object) { - if (goog.isObject(value)) { + if (isObject(value)) { delete object[index]; } }; diff --git a/src/os/ui/state/stateimportui.js b/src/os/ui/state/stateimportui.js index 42bb21acd..9b8c15ad8 100644 --- a/src/os/ui/state/stateimportui.js +++ b/src/os/ui/state/stateimportui.js @@ -1,5 +1,6 @@ goog.declareModuleId('os.ui.state.StateImportUI'); +import {isObject} from '../../object/object.js'; import StateParserConfig from '../../parse/stateparserconfig.js'; import Tag from '../../state/tag.js'; import {stringFromXML} from '../../tag/tag.js'; @@ -52,7 +53,7 @@ export default class StateImportUI extends FileImportUI { } else { rawState = loadXml(content); } - } else if (content instanceof Document || goog.isObject(content)) { + } else if (content instanceof Document || isObject(content)) { rawState = content; } } @@ -61,8 +62,8 @@ export default class StateImportUI extends FileImportUI { if (rawState instanceof Document) { this.handleXML(file, rawState, config); - } else if (goog.isObject(rawState)) { - this.handleJSON(file, rawState, config); + } else if (isObject(rawState)) { + this.handleJSON(file, /** @type {Object} */ (rawState), config); } } diff --git a/src/os/ui/twocolumninfo.js b/src/os/ui/twocolumninfo.js index 0535136a5..8bebb2ba3 100644 --- a/src/os/ui/twocolumninfo.js +++ b/src/os/ui/twocolumninfo.js @@ -1,6 +1,7 @@ goog.declareModuleId('os.ui.TwoColumnInfoUI'); import './slick/slickgrid.js'; +import {isObject} from '../object/object.js'; import {ROOT} from '../os.js'; import Module from './module.js'; import SlickGridEvent from './slick/slickgridevent.js'; @@ -123,7 +124,7 @@ export class Controller { if (newVal) { var properties = this.scope_['object']; for (var key in properties) { - if (!goog.isObject(properties[key])) { + if (!isObject(properties[key])) { this.scope_['properties'].push({'id': key, 'field': key, 'value': properties[key]}); } } diff --git a/src/plugin/arc/arcjsonparser.js b/src/plugin/arc/arcjsonparser.js index e27bed35a..ccdac8cdb 100644 --- a/src/plugin/arc/arcjsonparser.js +++ b/src/plugin/arc/arcjsonparser.js @@ -2,6 +2,7 @@ goog.declareModuleId('plugin.arc.ArcJSONParser'); import * as text from '../../os/file/mime/text.js'; import * as geo2 from '../../os/geo/geo2.js'; +import {isObject} from '../../os/object/object.js'; const Disposable = goog.require('goog.Disposable'); const googString = goog.require('goog.string'); @@ -56,7 +57,7 @@ class ArcJSONParser extends Disposable { if (typeof source === 'string') { var json = JSON.parse(source); features = json['features']; - } else if (goog.isObject(source)) { + } else if (isObject(source)) { features = source['features']; } diff --git a/src/plugin/file/geojson/geojsonparser.js b/src/plugin/file/geojson/geojsonparser.js index f553d9878..574bd89ef 100644 --- a/src/plugin/file/geojson/geojsonparser.js +++ b/src/plugin/file/geojson/geojsonparser.js @@ -5,6 +5,7 @@ import * as osFeature from '../../../os/feature/feature.js'; import * as text from '../../../os/file/mime/text.js'; import * as fn from '../../../os/fn/fn.js'; import * as osMap from '../../../os/map/map.js'; +import {isObject} from '../../../os/object/object.js'; const Disposable = goog.require('goog.Disposable'); const googObject = goog.require('goog.object'); @@ -96,10 +97,10 @@ export default class GeoJSONParser extends Disposable { source = text.getText(source) || null; } - if (Array.isArray(source) && source.length == 1 && (typeof source[0] === 'string' || goog.isObject(source[0]))) { + if (Array.isArray(source) && source.length == 1 && (typeof source[0] === 'string' || isObject(source[0]))) { // source likely came from a chaining importer src = source[0]; - } else if (goog.isObject(source)) { + } else if (isObject(source)) { src = source; } else if (source && typeof source === 'string') { // THIN-6240: if the server returns invalid JSON with literal whitespace characters inside tokens, the parser will diff --git a/src/plugin/file/geojson/mime.js b/src/plugin/file/geojson/mime.js index ea9a34b96..ddaa47f19 100644 --- a/src/plugin/file/geojson/mime.js +++ b/src/plugin/file/geojson/mime.js @@ -2,6 +2,7 @@ goog.declareModuleId('plugin.file.geojson.mime'); import * as mime from '../../../os/file/mime.js'; import * as json from '../../../os/file/mime/json.js'; +import {isObject} from '../../../os/object/object.js'; const Promise = goog.require('goog.Promise'); const GeoJSON = goog.require('ol.format.GeoJSON'); @@ -44,7 +45,7 @@ const find_ = function(obj) { for (var key in obj) { if (obj.hasOwnProperty(key)) { var val = obj[key]; - if (goog.isObject(val) || Array.isArray(val)) { + if (isObject(val) || Array.isArray(val)) { var retVal = find_(val); if (retVal) { return retVal; diff --git a/src/plugin/file/kml/kml.js b/src/plugin/file/kml/kml.js index 680590788..a19ba2997 100644 --- a/src/plugin/file/kml/kml.js +++ b/src/plugin/file/kml/kml.js @@ -1050,7 +1050,7 @@ const IconStyleParser_ = function(node, objectStack) { return; } var styleObject = /** @type {Object} */ (objectStack[objectStack.length - 1]); - asserts.assert(goog.isObject(styleObject), 'styleObject should be an Object'); + asserts.assert(osObject.isObject(styleObject), 'styleObject should be an Object'); var IconObject = 'Icon' in object ? object['Icon'] : {}; var src; var href = /** @type {string|undefined} */ (IconObject['href']); diff --git a/src/plugin/heatmap/heatmaplayer.js b/src/plugin/heatmap/heatmaplayer.js index ebf82f558..f30085906 100644 --- a/src/plugin/heatmap/heatmaplayer.js +++ b/src/plugin/heatmap/heatmaplayer.js @@ -1,6 +1,7 @@ goog.declareModuleId('plugin.heatmap.Heatmap'); import EventType from '../../os/action/eventtype.js'; +import {isArrayLike} from '../../os/array/array.js'; import * as color from '../../os/color.js'; import * as dispatcher from '../../os/dispatcher.js'; import LayerEvent from '../../os/events/layerevent.js'; @@ -569,7 +570,7 @@ export default class Heatmap extends VectorLayer { case EventType.IDENTIFY: return true; case EventType.RENAME: - return !!opt_actionArgs && goog.isArrayLike(opt_actionArgs) && opt_actionArgs.length === 1; + return !!opt_actionArgs && isArrayLike(opt_actionArgs) && opt_actionArgs.length === 1; case EventType.REFRESH: return source instanceof RequestSource; default: diff --git a/src/plugin/openpage/handler.js b/src/plugin/openpage/handler.js index 5acb2c359..ffbf50d04 100644 --- a/src/plugin/openpage/handler.js +++ b/src/plugin/openpage/handler.js @@ -3,6 +3,7 @@ goog.declareModuleId('plugin.openpage.Handler'); import CommandProcessor from '../../os/command/commandprocessor.js'; import LayerAdd from '../../os/command/layeraddcmd.js'; import SequenceCommand from '../../os/command/sequencecommand.js'; +import {isObject} from '../../os/object/object.js'; import {TYPE} from './openpage.js'; const googString = goog.require('goog.string'); @@ -36,7 +37,7 @@ export default class Handler { } var cmds = data.filter(function(item) { - return goog.isObject(item); + return isObject(item); }).map(function(config) { config['id'] = config['id'] || googString.getRandomString(); return new LayerAdd(config);