shallowEqual.js 717 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = shallowEqual;
  4. function is(x, y) {
  5. if (x === y) {
  6. return x !== 0 || y !== 0 || 1 / x === 1 / y;
  7. } else {
  8. return x !== x && y !== y;
  9. }
  10. }
  11. function shallowEqual(objA, objB) {
  12. if (is(objA, objB)) return true;
  13. if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
  14. return false;
  15. }
  16. var keysA = Object.keys(objA);
  17. var keysB = Object.keys(objB);
  18. if (keysA.length !== keysB.length) return false;
  19. for (var i = 0; i < keysA.length; i++) {
  20. if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
  21. return false;
  22. }
  23. }
  24. return true;
  25. }