Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Less googs #1426

Open
wants to merge 24 commits into
base: upgrade
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fe79c02
build(deps): bump follow-redirects from 1.14.7 to 1.14.8
dependabot[bot] Feb 14, 2022
1b8959e
Merge pull request #1425 from ngageoint/dependabot/npm_and_yarn/follo…
jsalankey Feb 15, 2022
14a2f8d
feat(goog): remove goog.window
smithtb Feb 10, 2022
20c9ad0
feat(goog): remove goog.ui.ColorPicker
smithtb Feb 10, 2022
fd09908
feat(goog): remove goog.typeOf
smithtb Feb 11, 2022
7847add
feat(goog): remove goog.array.every
smithtb Feb 11, 2022
7a040d1
feat(goog): remove goog.array.forEachRight
smithtb Feb 11, 2022
1b15437
feat(goog): remove goog.array.equals
smithtb Feb 15, 2022
5641390
feat(goog): remove goog.array.moveItem
smithtb Feb 16, 2022
3d6429f
feat(goog): remove goog.array.insertAt
smithtb Feb 16, 2022
42f970e
feat(goog): remove goog.array.insert
smithtb Feb 16, 2022
2e0d710
feat(goog): remove goog.array.forEach
smithtb Feb 16, 2022
2d41e58
feat(goog): remove goog.array.clone
smithtb Feb 16, 2022
8ea4859
feat(goog): remove goog.array.defaultCompare and more insert
smithtb Feb 16, 2022
4dadc78
feat(goog): remove goog.array.filter
smithtb Feb 17, 2022
2aaaeed
feat(goog): remove more goog.array.equals
smithtb Feb 17, 2022
620f18b
feat(goog): remove goog.array.some
smithtb Feb 17, 2022
9b26658
feat(goog): remove goog.array.removeDuplicates
smithtb Feb 17, 2022
e1aeb32
feat(goog): remove more goog.array functions
smithtb Feb 17, 2022
110392f
feat(goog): remove more goog.array.remove functions
smithtb Feb 17, 2022
087423f
feat(goog): replace goog.array.bucket with new os.array version
smithtb Feb 17, 2022
c80c3ed
feat(goog): remove goog.array.sort and others
smithtb Feb 17, 2022
507a845
feat(goog): remove goog.array.rotate/extend/reduce
smithtb Feb 17, 2022
a334096
feat(goog): replace goog.isArrayLike and goog.isObject
smithtb Feb 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 60 additions & 9 deletions src/os/array/array.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -22,7 +24,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;
}

Expand Down Expand Up @@ -69,7 +71,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]);
};

/**
Expand All @@ -82,7 +84,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]);
};

/**
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) :
Expand Down Expand Up @@ -239,7 +240,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);
};

/**
Expand Down Expand Up @@ -307,7 +308,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).
*
Expand All @@ -332,7 +333,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);
Expand Down Expand Up @@ -362,3 +363,53 @@ export const binaryStrideSearch = function(arr, target, stride, offset, opt_comp
// ~left is a shorthand for -left - 1.
return found ? left : ~left;
};

/**
* Based on the goog.array.bucket method. Splits an array into disjoint buckets according to a splitting function.
*
* @param {!Array<T>} arr The array
* @param {function(this: S, T, number, !Array<T>): ?} 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<!Array<T>>}
* @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;
};

/**
* 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
* @return {number}
* @template VALUE
*/
export const defaultSort = (a, b) => {
return a > b ? 1 : a < b ? -1 : 0;
};
8 changes: 4 additions & 4 deletions src/os/arraybuf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
goog.declareModuleId('os.arraybuf');

goog.require('goog.array');


/**
* The Byte Order Marker (BOM) sequence.
Expand Down Expand Up @@ -36,8 +34,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;
}
Expand Down Expand Up @@ -108,8 +107,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);
}

Expand Down
23 changes: 20 additions & 3 deletions src/os/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*/
goog.declareModuleId('os.color');

goog.require('goog.array');
goog.require('goog.color');
goog.require('goog.color.Rgb');
goog.require('goog.math');
goog.require('goog.math.Matrix');

import {defaultSort} from './array/array.js';

/**
* @typedef {{
Expand Down Expand Up @@ -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<GradientColor>}
*/
Expand Down Expand Up @@ -575,7 +588,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);
};

/**
Expand All @@ -600,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;
};

/**
Expand Down
3 changes: 1 addition & 2 deletions src/os/command/commandprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
});
}
Expand Down
7 changes: 4 additions & 3 deletions src/os/config/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');


Expand Down Expand Up @@ -83,7 +82,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);
Expand Down Expand Up @@ -151,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 || [];
Expand Down
33 changes: 16 additions & 17 deletions src/os/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -432,8 +431,8 @@ export default class Settings extends EventTarget {

log.fine(logger, 'Saving settings...');

var keysToDelete = googArray.clone(osConfigNamespace.getObsoleteKeys());
googArray.insertArrayAt(keysToDelete, osConfigNamespace.keysToDelete.slice());
var keysToDelete = Array.from(osConfigNamespace.getObsoleteKeys());
keysToDelete.unshift(...osConfigNamespace.keysToDelete.slice());

if (opt_settingsToOverwrite != null) {
userPrefsToPersist = opt_settingsToOverwrite;
Expand Down Expand Up @@ -552,8 +551,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) {
Expand Down Expand Up @@ -673,9 +672,9 @@ export default class Settings extends EventTarget {
if (this.loaded_) {
var val = googObject.getValueByKeys(this.mergedConfig_, keys);
if (Array.isArray(val)) {
val = googArray.clone(val);
} else if (goog.isObject(val)) {
val = googObject.clone(val);
val = Array.from(val);
} else if (osObject.isObject(val)) {
val = googObject.clone(/** @type {Object} */(val));
}

return val !== undefined ? val : opt_default;
Expand Down Expand Up @@ -750,12 +749,12 @@ 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 {
} 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);
Expand All @@ -780,8 +779,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_) {
Expand Down Expand Up @@ -812,14 +811,14 @@ 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('.');
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));
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/os/config/storage/baselocalsettingsstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/os/config/storage/settingsstorageloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}

Expand Down
Loading