shallowequal.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import _typeof from "@babel/runtime/helpers/esm/typeof";
  2. import { toRaw } from 'vue';
  3. function shallowEqual(objA, objB, compare, compareContext) {
  4. var ret = compare ? compare.call(compareContext, objA, objB) : void 0;
  5. if (ret !== void 0) {
  6. return !!ret;
  7. }
  8. if (objA === objB) {
  9. return true;
  10. }
  11. if (_typeof(objA) !== 'object' || !objA || _typeof(objB) !== 'object' || !objB) {
  12. return false;
  13. }
  14. var keysA = Object.keys(objA);
  15. var keysB = Object.keys(objB);
  16. if (keysA.length !== keysB.length) {
  17. return false;
  18. }
  19. var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
  20. // Test for A's keys different from B.
  21. for (var idx = 0; idx < keysA.length; idx++) {
  22. var key = keysA[idx];
  23. if (!bHasOwnProperty(key)) {
  24. return false;
  25. }
  26. var valueA = objA[key];
  27. var valueB = objB[key];
  28. ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
  29. if (ret === false || ret === void 0 && valueA !== valueB) {
  30. return false;
  31. }
  32. }
  33. return true;
  34. }
  35. export default function (value, other, customizer, thisArg) {
  36. return shallowEqual(toRaw(value), toRaw(other), customizer, thisArg);
  37. }