react.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. // do not edit .js files directly - edit src/index.jst
  3. var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
  4. module.exports = function equal(a, b) {
  5. if (a === b) return true;
  6. if (a && b && typeof a == 'object' && typeof b == 'object') {
  7. if (a.constructor !== b.constructor) return false;
  8. var length, i, keys;
  9. if (Array.isArray(a)) {
  10. length = a.length;
  11. if (length != b.length) return false;
  12. for (i = length; i-- !== 0;)
  13. if (!equal(a[i], b[i])) return false;
  14. return true;
  15. }
  16. if ((a instanceof Map) && (b instanceof Map)) {
  17. if (a.size !== b.size) return false;
  18. for (i of a.entries())
  19. if (!b.has(i[0])) return false;
  20. for (i of a.entries())
  21. if (!equal(i[1], b.get(i[0]))) return false;
  22. return true;
  23. }
  24. if ((a instanceof Set) && (b instanceof Set)) {
  25. if (a.size !== b.size) return false;
  26. for (i of a.entries())
  27. if (!b.has(i[0])) return false;
  28. return true;
  29. }
  30. if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
  31. length = a.length;
  32. if (length != b.length) return false;
  33. for (i = length; i-- !== 0;)
  34. if (a[i] !== b[i]) return false;
  35. return true;
  36. }
  37. if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
  38. if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
  39. if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
  40. keys = Object.keys(a);
  41. length = keys.length;
  42. if (length !== Object.keys(b).length) return false;
  43. for (i = length; i-- !== 0;)
  44. if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
  45. for (i = length; i-- !== 0;) {
  46. var key = keys[i];
  47. if (key === '_owner' && a.$$typeof) {
  48. // React-specific: avoid traversing React elements' _owner.
  49. // _owner contains circular references
  50. // and is not needed when comparing the actual elements (and not their owners)
  51. continue;
  52. }
  53. if (!equal(a[key], b[key])) return false;
  54. }
  55. return true;
  56. }
  57. // true if both NaN, false otherwise
  58. return a!==a && b!==b;
  59. };