UNPKG

@playcanvas/react

Version:

A React renderer for PlayCanvas – build interactive 3D applications using React's declarative paradigm.

55 lines 1.84 kB
/** * Simple deep equality check for two objects * @param {Record<string, unknown>} a - The first object * @param {Record<string, unknown>} b - The second object * @returns {boolean} True if the objects are equal, false otherwise */ export function deepEqual(a, b) { if (a === b) return true; if (typeof a !== 'object' || typeof b !== 'object' || a == null || b == null) return false; const aKeys = Object.keys(a); const bKeys = Object.keys(b); if (aKeys.length !== bKeys.length) return false; return aKeys.every(key => deepEqual(a[key], b[key])); } function hasEqualsMethod(obj) { return typeof obj === 'object' && obj !== null && 'equals' in obj && typeof obj.equals === 'function'; } export const shallowEquals = (objA, objB) => { // If the two objects are the same object, return true if (objA === objB) { return true; } // If either is not an object (null or primitives), return false if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { return false; } // Get the keys of both objects const keysA = Object.keys(objA); const keysB = Object.keys(objB); // If the number of keys is different, the objects are not equal if (keysA.length !== keysB.length) { return false; } // Check if all keys and their values are equal for (let i = 0; i < keysA.length; i++) { const key = keysA[i]; const propA = objA[key]; const propB = objB[key]; // If the object has an equality operator, use this if (hasEqualsMethod(propA)) { return propA.equals(propB); } else if (propA !== propB) { return false; } } return true; }; //# sourceMappingURL=compare.js.map