de-lint ObjectUtils

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2017-07-01 14:38:32 +01:00
parent 68fb11d2bf
commit 7da14d7078
No known key found for this signature in database
GPG key ID: 0435A1D4BBD34D64
2 changed files with 14 additions and 13 deletions

View file

@ -130,7 +130,6 @@ src/Markdown.js
src/MatrixClientPeg.js src/MatrixClientPeg.js
src/Modal.js src/Modal.js
src/Notifier.js src/Notifier.js
src/ObjectUtils.js
src/PlatformPeg.js src/PlatformPeg.js
src/Presence.js src/Presence.js
src/ratelimitedfunc.js src/ratelimitedfunc.js

View file

@ -23,8 +23,8 @@ limitations under the License.
* { key: $KEY, val: $VALUE, place: "add|del" } * { key: $KEY, val: $VALUE, place: "add|del" }
*/ */
module.exports.getKeyValueArrayDiffs = function(before, after) { module.exports.getKeyValueArrayDiffs = function(before, after) {
var results = []; const results = [];
var delta = {}; const delta = {};
Object.keys(before).forEach(function(beforeKey) { Object.keys(before).forEach(function(beforeKey) {
delta[beforeKey] = delta[beforeKey] || 0; // init to 0 initially delta[beforeKey] = delta[beforeKey] || 0; // init to 0 initially
delta[beforeKey]--; // keys present in the past have -ve values delta[beforeKey]--; // keys present in the past have -ve values
@ -46,9 +46,9 @@ module.exports.getKeyValueArrayDiffs = function(before, after) {
results.push({ place: "del", key: muxedKey, val: beforeVal }); results.push({ place: "del", key: muxedKey, val: beforeVal });
}); });
break; break;
case 0: // A mix of added/removed keys case 0: {// A mix of added/removed keys
// compare old & new vals // compare old & new vals
var itemDelta = {}; const itemDelta = {};
before[muxedKey].forEach(function(beforeVal) { before[muxedKey].forEach(function(beforeVal) {
itemDelta[beforeVal] = itemDelta[beforeVal] || 0; itemDelta[beforeVal] = itemDelta[beforeVal] || 0;
itemDelta[beforeVal]--; itemDelta[beforeVal]--;
@ -68,9 +68,9 @@ module.exports.getKeyValueArrayDiffs = function(before, after) {
} }
}); });
break; break;
}
default: default:
console.error("Calculated key delta of " + delta[muxedKey] + console.error("Calculated key delta of " + delta[muxedKey] + " - this should never happen!");
" - this should never happen!");
break; break;
} }
}); });
@ -79,8 +79,10 @@ module.exports.getKeyValueArrayDiffs = function(before, after) {
}; };
/** /**
* Shallow-compare two objects for equality: each key and value must be * Shallow-compare two objects for equality: each key and value must be identical
* identical * @param {Object} objA First object to compare against the second
* @param {Object} objB Second object to compare against the first
* @return {boolean} whether the two objects have same key=values
*/ */
module.exports.shallowEqual = function(objA, objB) { module.exports.shallowEqual = function(objA, objB) {
if (objA === objB) { if (objA === objB) {
@ -92,15 +94,15 @@ module.exports.shallowEqual = function(objA, objB) {
return false; return false;
} }
var keysA = Object.keys(objA); const keysA = Object.keys(objA);
var keysB = Object.keys(objB); const keysB = Object.keys(objB);
if (keysA.length !== keysB.length) { if (keysA.length !== keysB.length) {
return false; return false;
} }
for (var i = 0; i < keysA.length; i++) { for (let i = 0; i < keysA.length; i++) {
var key = keysA[i]; const key = keysA[i];
if (!objB.hasOwnProperty(key) || objA[key] !== objB[key]) { if (!objB.hasOwnProperty(key) || objA[key] !== objB[key]) {
return false; return false;
} }