mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 14:45:35 +00:00
Continued porting to react, approaching beta
This commit is contained in:
49
src/app/utils/UtilityFunctions.js
Normal file
49
src/app/utils/UtilityFunctions.js
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
/**
|
||||
* Wraps the callback/context menu handler such that the default
|
||||
* operation can proceed if the SHIFT key is held while right-clicked
|
||||
* @param {Function} cb Callback for contextMenu
|
||||
* @return {Function} Wrapped contextmenu handler
|
||||
*/
|
||||
export function wrapCtxMenu(cb) {
|
||||
return (event) => {
|
||||
if (!event.getModifierState('Shift')) {
|
||||
event.preventDefault();
|
||||
cb.call(null, event);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares A and B and return true using strict comparison (===)
|
||||
* @param {any} objA A
|
||||
* @param {any} objB B
|
||||
* @return {boolean} true if A === B OR A properties === B properties
|
||||
*/
|
||||
export function shallowEqual(objA, objB) {
|
||||
if (objA === objB) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (typeof objA !== 'object' || objA === null ||
|
||||
typeof objB !== 'object' || objB === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let keysA = Object.keys(objA);
|
||||
let keysB = Object.keys(objB);
|
||||
|
||||
if (keysA.length !== keysB.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Test for A's keys different from B.
|
||||
let bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
|
||||
for (let i = 0; i < keysA.length; i++) {
|
||||
if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user