wp/wp-includes/js/dist/is-shallow-equal.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    80 /******/ 	// __webpack_public_path__
    80 /******/ 	// __webpack_public_path__
    81 /******/ 	__webpack_require__.p = "";
    81 /******/ 	__webpack_require__.p = "";
    82 /******/
    82 /******/
    83 /******/
    83 /******/
    84 /******/ 	// Load entry module and return exports
    84 /******/ 	// Load entry module and return exports
    85 /******/ 	return __webpack_require__(__webpack_require__.s = 423);
    85 /******/ 	return __webpack_require__(__webpack_require__.s = "waYt");
    86 /******/ })
    86 /******/ })
    87 /************************************************************************/
    87 /************************************************************************/
    88 /******/ ({
    88 /******/ ({
    89 
    89 
    90 /***/ 423:
    90 /***/ "waYt":
    91 /***/ (function(module, exports, __webpack_require__) {
    91 /***/ (function(module, __webpack_exports__, __webpack_require__) {
    92 
    92 
    93 "use strict";
    93 "use strict";
    94 
    94 // ESM COMPAT FLAG
    95 
    95 __webpack_require__.r(__webpack_exports__);
    96 /**
    96 
    97  * Internal dependencies;
    97 // EXPORTS
    98  */
    98 __webpack_require__.d(__webpack_exports__, "isShallowEqualObjects", function() { return /* reexport */ isShallowEqualObjects; });
    99 var isShallowEqualObjects = __webpack_require__( 424 );
    99 __webpack_require__.d(__webpack_exports__, "isShallowEqualArrays", function() { return /* reexport */ isShallowEqualArrays; });
   100 var isShallowEqualArrays = __webpack_require__( 425 );
   100 __webpack_require__.d(__webpack_exports__, "default", function() { return /* binding */ isShallowEqual; });
   101 
   101 
   102 var isArray = Array.isArray;
   102 // CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/objects.js
       
   103 /**
       
   104  * Returns true if the two objects are shallow equal, or false otherwise.
       
   105  *
       
   106  * @param {import('.').ComparableObject} a First object to compare.
       
   107  * @param {import('.').ComparableObject} b Second object to compare.
       
   108  *
       
   109  * @return {boolean} Whether the two objects are shallow equal.
       
   110  */
       
   111 function isShallowEqualObjects(a, b) {
       
   112   if (a === b) {
       
   113     return true;
       
   114   }
       
   115 
       
   116   const aKeys = Object.keys(a);
       
   117   const bKeys = Object.keys(b);
       
   118 
       
   119   if (aKeys.length !== bKeys.length) {
       
   120     return false;
       
   121   }
       
   122 
       
   123   let i = 0;
       
   124 
       
   125   while (i < aKeys.length) {
       
   126     const key = aKeys[i];
       
   127     const aValue = a[key];
       
   128 
       
   129     if ( // In iterating only the keys of the first object after verifying
       
   130     // equal lengths, account for the case that an explicit `undefined`
       
   131     // value in the first is implicitly undefined in the second.
       
   132     //
       
   133     // Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
       
   134     aValue === undefined && !b.hasOwnProperty(key) || aValue !== b[key]) {
       
   135       return false;
       
   136     }
       
   137 
       
   138     i++;
       
   139   }
       
   140 
       
   141   return true;
       
   142 }
       
   143 
       
   144 // CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/arrays.js
       
   145 /**
       
   146  * Returns true if the two arrays are shallow equal, or false otherwise.
       
   147  *
       
   148  * @param {any[]} a First array to compare.
       
   149  * @param {any[]} b Second array to compare.
       
   150  *
       
   151  * @return {boolean} Whether the two arrays are shallow equal.
       
   152  */
       
   153 function isShallowEqualArrays(a, b) {
       
   154   if (a === b) {
       
   155     return true;
       
   156   }
       
   157 
       
   158   if (a.length !== b.length) {
       
   159     return false;
       
   160   }
       
   161 
       
   162   for (let i = 0, len = a.length; i < len; i++) {
       
   163     if (a[i] !== b[i]) {
       
   164       return false;
       
   165     }
       
   166   }
       
   167 
       
   168   return true;
       
   169 }
       
   170 
       
   171 // CONCATENATED MODULE: ./node_modules/@wordpress/is-shallow-equal/build-module/index.js
       
   172 /**
       
   173  * Internal dependencies
       
   174  */
       
   175 
       
   176 
       
   177 
   103 
   178 
   104 /**
   179 /**
   105  * @typedef {Record<string, any>} ComparableObject
   180  * @typedef {Record<string, any>} ComparableObject
   106  */
   181  */
   107 
   182 
   112  * @param {any[]|ComparableObject} a First object or array to compare.
   187  * @param {any[]|ComparableObject} a First object or array to compare.
   113  * @param {any[]|ComparableObject} b Second object or array to compare.
   188  * @param {any[]|ComparableObject} b Second object or array to compare.
   114  *
   189  *
   115  * @return {boolean} Whether the two values are shallow equal.
   190  * @return {boolean} Whether the two values are shallow equal.
   116  */
   191  */
   117 function isShallowEqual( a, b ) {
   192 
   118 	if ( a && b ) {
   193 function isShallowEqual(a, b) {
   119 		if ( a.constructor === Object && b.constructor === Object ) {
   194   if (a && b) {
   120 			return isShallowEqualObjects( a, b );
   195     if (a.constructor === Object && b.constructor === Object) {
   121 		} else if ( isArray( a ) && isArray( b ) ) {
   196       return isShallowEqualObjects(a, b);
   122 			return isShallowEqualArrays( a, b );
   197     } else if (Array.isArray(a) && Array.isArray(b)) {
   123 		}
   198       return isShallowEqualArrays(a, b);
   124 	}
   199     }
   125 
   200   }
   126 	return a === b;
   201 
       
   202   return a === b;
   127 }
   203 }
   128 
   204 
   129 module.exports = isShallowEqual;
       
   130 module.exports.isShallowEqualObjects = isShallowEqualObjects;
       
   131 module.exports.isShallowEqualArrays = isShallowEqualArrays;
       
   132 
       
   133 
       
   134 /***/ }),
       
   135 
       
   136 /***/ 424:
       
   137 /***/ (function(module, exports, __webpack_require__) {
       
   138 
       
   139 "use strict";
       
   140 
       
   141 
       
   142 var keys = Object.keys;
       
   143 
       
   144 /**
       
   145  * Returns true if the two objects are shallow equal, or false otherwise.
       
   146  *
       
   147  * @param {import('.').ComparableObject} a First object to compare.
       
   148  * @param {import('.').ComparableObject} b Second object to compare.
       
   149  *
       
   150  * @return {boolean} Whether the two objects are shallow equal.
       
   151  */
       
   152 function isShallowEqualObjects( a, b ) {
       
   153 	var aKeys, bKeys, i, key, aValue;
       
   154 
       
   155 	if ( a === b ) {
       
   156 		return true;
       
   157 	}
       
   158 
       
   159 	aKeys = keys( a );
       
   160 	bKeys = keys( b );
       
   161 
       
   162 	if ( aKeys.length !== bKeys.length ) {
       
   163 		return false;
       
   164 	}
       
   165 
       
   166 	i = 0;
       
   167 
       
   168 	while ( i < aKeys.length ) {
       
   169 		key = aKeys[ i ];
       
   170 		aValue = a[ key ];
       
   171 
       
   172 		if (
       
   173 			// In iterating only the keys of the first object after verifying
       
   174 			// equal lengths, account for the case that an explicit `undefined`
       
   175 			// value in the first is implicitly undefined in the second.
       
   176 			//
       
   177 			// Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
       
   178 			( aValue === undefined && ! b.hasOwnProperty( key ) ) ||
       
   179 			aValue !== b[ key ]
       
   180 		) {
       
   181 			return false;
       
   182 		}
       
   183 
       
   184 		i++;
       
   185 	}
       
   186 
       
   187 	return true;
       
   188 }
       
   189 
       
   190 module.exports = isShallowEqualObjects;
       
   191 
       
   192 
       
   193 /***/ }),
       
   194 
       
   195 /***/ 425:
       
   196 /***/ (function(module, exports, __webpack_require__) {
       
   197 
       
   198 "use strict";
       
   199 
       
   200 
       
   201 /**
       
   202  * Returns true if the two arrays are shallow equal, or false otherwise.
       
   203  *
       
   204  * @param {any[]} a First array to compare.
       
   205  * @param {any[]} b Second array to compare.
       
   206  *
       
   207  * @return {boolean} Whether the two arrays are shallow equal.
       
   208  */
       
   209 function isShallowEqualArrays( a, b ) {
       
   210 	var i;
       
   211 
       
   212 	if ( a === b ) {
       
   213 		return true;
       
   214 	}
       
   215 
       
   216 	if ( a.length !== b.length ) {
       
   217 		return false;
       
   218 	}
       
   219 
       
   220 	for ( i = 0; i < a.length; i++ ) {
       
   221 		if ( a[ i ] !== b[ i ] ) {
       
   222 			return false;
       
   223 		}
       
   224 	}
       
   225 
       
   226 	return true;
       
   227 }
       
   228 
       
   229 module.exports = isShallowEqualArrays;
       
   230 
       
   231 
   205 
   232 /***/ })
   206 /***/ })
   233 
   207 
   234 /******/ });
   208 /******/ });