wp/wp-includes/js/dist/is-shallow-equal.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 /******/ (function() { // webpackBootstrap
     1 /******/ (() => { // webpackBootstrap
     2 /******/ 	"use strict";
     2 /******/ 	"use strict";
     3 /******/ 	// The require scope
     3 /******/ 	// The require scope
     4 /******/ 	var __webpack_require__ = {};
     4 /******/ 	var __webpack_require__ = {};
     5 /******/ 	
     5 /******/ 	
     6 /************************************************************************/
     6 /************************************************************************/
     7 /******/ 	/* webpack/runtime/define property getters */
     7 /******/ 	/* webpack/runtime/define property getters */
     8 /******/ 	!function() {
     8 /******/ 	(() => {
     9 /******/ 		// define getter functions for harmony exports
     9 /******/ 		// define getter functions for harmony exports
    10 /******/ 		__webpack_require__.d = function(exports, definition) {
    10 /******/ 		__webpack_require__.d = (exports, definition) => {
    11 /******/ 			for(var key in definition) {
    11 /******/ 			for(var key in definition) {
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    14 /******/ 				}
    14 /******/ 				}
    15 /******/ 			}
    15 /******/ 			}
    16 /******/ 		};
    16 /******/ 		};
    17 /******/ 	}();
    17 /******/ 	})();
    18 /******/ 	
    18 /******/ 	
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    20 /******/ 	!function() {
    20 /******/ 	(() => {
    21 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
    21 /******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
    22 /******/ 	}();
    22 /******/ 	})();
    23 /******/ 	
    23 /******/ 	
    24 /******/ 	/* webpack/runtime/make namespace object */
    24 /******/ 	/* webpack/runtime/make namespace object */
    25 /******/ 	!function() {
    25 /******/ 	(() => {
    26 /******/ 		// define __esModule on exports
    26 /******/ 		// define __esModule on exports
    27 /******/ 		__webpack_require__.r = function(exports) {
    27 /******/ 		__webpack_require__.r = (exports) => {
    28 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    28 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    29 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    29 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    30 /******/ 			}
    30 /******/ 			}
    31 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    31 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    32 /******/ 		};
    32 /******/ 		};
    33 /******/ 	}();
    33 /******/ 	})();
    34 /******/ 	
    34 /******/ 	
    35 /************************************************************************/
    35 /************************************************************************/
    36 var __webpack_exports__ = {};
    36 var __webpack_exports__ = {};
    37 // ESM COMPAT FLAG
    37 // ESM COMPAT FLAG
    38 __webpack_require__.r(__webpack_exports__);
    38 __webpack_require__.r(__webpack_exports__);
    39 
    39 
    40 // EXPORTS
    40 // EXPORTS
    41 __webpack_require__.d(__webpack_exports__, {
    41 __webpack_require__.d(__webpack_exports__, {
    42   "default": function() { return /* binding */ isShallowEqual; },
    42   "default": () => (/* binding */ isShallowEqual),
    43   "isShallowEqualArrays": function() { return /* reexport */ isShallowEqualArrays; },
    43   isShallowEqualArrays: () => (/* reexport */ isShallowEqualArrays),
    44   "isShallowEqualObjects": function() { return /* reexport */ isShallowEqualObjects; }
    44   isShallowEqualObjects: () => (/* reexport */ isShallowEqualObjects)
    45 });
    45 });
    46 
    46 
    47 ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/objects.js
    47 ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/objects.js
    48 /**
    48 /**
    49  * Returns true if the two objects are shallow equal, or false otherwise.
    49  * Returns true if the two objects are shallow equal, or false otherwise.
    55  */
    55  */
    56 function isShallowEqualObjects(a, b) {
    56 function isShallowEqualObjects(a, b) {
    57   if (a === b) {
    57   if (a === b) {
    58     return true;
    58     return true;
    59   }
    59   }
    60 
       
    61   const aKeys = Object.keys(a);
    60   const aKeys = Object.keys(a);
    62   const bKeys = Object.keys(b);
    61   const bKeys = Object.keys(b);
    63 
       
    64   if (aKeys.length !== bKeys.length) {
    62   if (aKeys.length !== bKeys.length) {
    65     return false;
    63     return false;
    66   }
    64   }
    67 
       
    68   let i = 0;
    65   let i = 0;
    69 
       
    70   while (i < aKeys.length) {
    66   while (i < aKeys.length) {
    71     const key = aKeys[i];
    67     const key = aKeys[i];
    72     const aValue = a[key];
    68     const aValue = a[key];
    73 
    69     if (
    74     if ( // In iterating only the keys of the first object after verifying
    70     // In iterating only the keys of the first object after verifying
    75     // equal lengths, account for the case that an explicit `undefined`
    71     // equal lengths, account for the case that an explicit `undefined`
    76     // value in the first is implicitly undefined in the second.
    72     // value in the first is implicitly undefined in the second.
    77     //
    73     //
    78     // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
    74     // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
    79     aValue === undefined && !b.hasOwnProperty(key) || aValue !== b[key]) {
    75     aValue === undefined && !b.hasOwnProperty(key) || aValue !== b[key]) {
    80       return false;
    76       return false;
    81     }
    77     }
    82 
       
    83     i++;
    78     i++;
    84   }
    79   }
    85 
       
    86   return true;
    80   return true;
    87 }
    81 }
    88 
    82 
    89 ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/arrays.js
    83 ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/arrays.js
    90 /**
    84 /**
    97  */
    91  */
    98 function isShallowEqualArrays(a, b) {
    92 function isShallowEqualArrays(a, b) {
    99   if (a === b) {
    93   if (a === b) {
   100     return true;
    94     return true;
   101   }
    95   }
   102 
       
   103   if (a.length !== b.length) {
    96   if (a.length !== b.length) {
   104     return false;
    97     return false;
   105   }
    98   }
   106 
       
   107   for (let i = 0, len = a.length; i < len; i++) {
    99   for (let i = 0, len = a.length; i < len; i++) {
   108     if (a[i] !== b[i]) {
   100     if (a[i] !== b[i]) {
   109       return false;
   101       return false;
   110     }
   102     }
   111   }
   103   }
   112 
       
   113   return true;
   104   return true;
   114 }
   105 }
   115 
   106 
   116 ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/index.js
   107 ;// CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/index.js
   117 /**
   108 /**
   119  */
   110  */
   120 
   111 
   121 
   112 
   122 
   113 
   123 
   114 
       
   115 
   124 /**
   116 /**
   125  * @typedef {Record<string, any>} ComparableObject
   117  * @typedef {Record<string, any>} ComparableObject
   126  */
   118  */
   127 
   119 
   128 /**
   120 /**
   129  * Returns true if the two arrays or objects are shallow equal, or false
   121  * Returns true if the two arrays or objects are shallow equal, or false
   130  * otherwise.
   122  * otherwise. Also handles primitive values, just in case.
   131  *
   123  *
   132  * @param {any[]|ComparableObject} a First object or array to compare.
   124  * @param {unknown} a First object or array to compare.
   133  * @param {any[]|ComparableObject} b Second object or array to compare.
   125  * @param {unknown} b Second object or array to compare.
   134  *
   126  *
   135  * @return {boolean} Whether the two values are shallow equal.
   127  * @return {boolean} Whether the two values are shallow equal.
   136  */
   128  */
   137 
       
   138 function isShallowEqual(a, b) {
   129 function isShallowEqual(a, b) {
   139   if (a && b) {
   130   if (a && b) {
   140     if (a.constructor === Object && b.constructor === Object) {
   131     if (a.constructor === Object && b.constructor === Object) {
   141       return isShallowEqualObjects(a, b);
   132       return isShallowEqualObjects(a, b);
   142     } else if (Array.isArray(a) && Array.isArray(b)) {
   133     } else if (Array.isArray(a) && Array.isArray(b)) {
   143       return isShallowEqualArrays(a, b);
   134       return isShallowEqualArrays(a, b);
   144     }
   135     }
   145   }
   136   }
   146 
       
   147   return a === b;
   137   return a === b;
   148 }
   138 }
   149 
   139 
   150 (window.wp = window.wp || {}).isShallowEqual = __webpack_exports__;
   140 (window.wp = window.wp || {}).isShallowEqual = __webpack_exports__;
   151 /******/ })()
   141 /******/ })()