wp/wp-includes/js/dist/is-shallow-equal.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    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 = 343);
    85 /******/ 	return __webpack_require__(__webpack_require__.s = 423);
    86 /******/ })
    86 /******/ })
    87 /************************************************************************/
    87 /************************************************************************/
    88 /******/ ({
    88 /******/ ({
    89 
    89 
    90 /***/ 343:
    90 /***/ 423:
    91 /***/ (function(module, exports, __webpack_require__) {
    91 /***/ (function(module, exports, __webpack_require__) {
    92 
    92 
    93 "use strict";
    93 "use strict";
    94 
    94 
    95 
    95 
    96 /**
    96 /**
    97  * Internal dependencies;
    97  * Internal dependencies;
    98  */
    98  */
    99 var isShallowEqualObjects = __webpack_require__( 344 );
    99 var isShallowEqualObjects = __webpack_require__( 424 );
   100 var isShallowEqualArrays = __webpack_require__( 345 );
   100 var isShallowEqualArrays = __webpack_require__( 425 );
   101 
   101 
   102 var isArray = Array.isArray;
   102 var isArray = Array.isArray;
       
   103 
       
   104 /**
       
   105  * @typedef {Record<string, any>} ComparableObject
       
   106  */
   103 
   107 
   104 /**
   108 /**
   105  * Returns true if the two arrays or objects are shallow equal, or false
   109  * Returns true if the two arrays or objects are shallow equal, or false
   106  * otherwise.
   110  * otherwise.
   107  *
   111  *
   108  * @param {(Array|Object)} a First object or array to compare.
   112  * @param {any[]|ComparableObject} a First object or array to compare.
   109  * @param {(Array|Object)} b Second object or array to compare.
   113  * @param {any[]|ComparableObject} b Second object or array to compare.
   110  *
   114  *
   111  * @return {boolean} Whether the two values are shallow equal.
   115  * @return {boolean} Whether the two values are shallow equal.
   112  */
   116  */
   113 function isShallowEqual( a, b ) {
   117 function isShallowEqual( a, b ) {
   114 	if ( a && b ) {
   118 	if ( a && b ) {
   127 module.exports.isShallowEqualArrays = isShallowEqualArrays;
   131 module.exports.isShallowEqualArrays = isShallowEqualArrays;
   128 
   132 
   129 
   133 
   130 /***/ }),
   134 /***/ }),
   131 
   135 
   132 /***/ 344:
   136 /***/ 424:
   133 /***/ (function(module, exports, __webpack_require__) {
   137 /***/ (function(module, exports, __webpack_require__) {
   134 
   138 
   135 "use strict";
   139 "use strict";
   136 
   140 
   137 
   141 
   138 var keys = Object.keys;
   142 var keys = Object.keys;
   139 
   143 
   140 /**
   144 /**
   141  * Returns true if the two objects are shallow equal, or false otherwise.
   145  * Returns true if the two objects are shallow equal, or false otherwise.
   142  *
   146  *
   143  * @param {Object} a First object to compare.
   147  * @param {import('.').ComparableObject} a First object to compare.
   144  * @param {Object} b Second object to compare.
   148  * @param {import('.').ComparableObject} b Second object to compare.
   145  *
   149  *
   146  * @return {boolean} Whether the two objects are shallow equal.
   150  * @return {boolean} Whether the two objects are shallow equal.
   147  */
   151  */
   148 function isShallowEqualObjects( a, b ) {
   152 function isShallowEqualObjects( a, b ) {
   149 	var aKeys, bKeys, i, key;
   153 	var aKeys, bKeys, i, key, aValue;
   150 
   154 
   151 	if ( a === b ) {
   155 	if ( a === b ) {
   152 		return true;
   156 		return true;
   153 	}
   157 	}
   154 
   158 
   161 
   165 
   162 	i = 0;
   166 	i = 0;
   163 
   167 
   164 	while ( i < aKeys.length ) {
   168 	while ( i < aKeys.length ) {
   165 		key = aKeys[ i ];
   169 		key = aKeys[ i ];
   166 		if ( a[ key ] !== b[ key ] ) {
   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 		) {
   167 			return false;
   181 			return false;
   168 		}
   182 		}
   169 
   183 
   170 		i++;
   184 		i++;
   171 	}
   185 	}
   176 module.exports = isShallowEqualObjects;
   190 module.exports = isShallowEqualObjects;
   177 
   191 
   178 
   192 
   179 /***/ }),
   193 /***/ }),
   180 
   194 
   181 /***/ 345:
   195 /***/ 425:
   182 /***/ (function(module, exports, __webpack_require__) {
   196 /***/ (function(module, exports, __webpack_require__) {
   183 
   197 
   184 "use strict";
   198 "use strict";
   185 
   199 
   186 
   200 
   187 /**
   201 /**
   188  * Returns true if the two arrays are shallow equal, or false otherwise.
   202  * Returns true if the two arrays are shallow equal, or false otherwise.
   189  *
   203  *
   190  * @param {Array} a First array to compare.
   204  * @param {any[]} a First array to compare.
   191  * @param {Array} b Second array to compare.
   205  * @param {any[]} b Second array to compare.
   192  *
   206  *
   193  * @return {boolean} Whether the two arrays are shallow equal.
   207  * @return {boolean} Whether the two arrays are shallow equal.
   194  */
   208  */
   195 function isShallowEqualArrays( a, b ) {
   209 function isShallowEqualArrays( a, b ) {
   196 	var i;
   210 	var i;