shallowequal.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _default;
  6. var _vue = require("vue");
  7. function shallowEqual(objA, objB, compare, compareContext) {
  8. let ret = compare ? compare.call(compareContext, objA, objB) : void 0;
  9. if (ret !== void 0) {
  10. return !!ret;
  11. }
  12. if (objA === objB) {
  13. return true;
  14. }
  15. if (typeof objA !== 'object' || !objA || typeof objB !== 'object' || !objB) {
  16. return false;
  17. }
  18. const keysA = Object.keys(objA);
  19. const keysB = Object.keys(objB);
  20. if (keysA.length !== keysB.length) {
  21. return false;
  22. }
  23. const bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
  24. // Test for A's keys different from B.
  25. for (let idx = 0; idx < keysA.length; idx++) {
  26. const key = keysA[idx];
  27. if (!bHasOwnProperty(key)) {
  28. return false;
  29. }
  30. const valueA = objA[key];
  31. const valueB = objB[key];
  32. ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
  33. if (ret === false || ret === void 0 && valueA !== valueB) {
  34. return false;
  35. }
  36. }
  37. return true;
  38. }
  39. function _default(value, other) {
  40. return shallowEqual((0, _vue.toRaw)(value), (0, _vue.toRaw)(other));
  41. }