src/utils/shallow-equal.js
function shallowEqual(objA, objB, options = {}) {
  if (is(objA, objB)) {
    return true;
  }

  if ((typeof objA === 'undefined' ? 'undefined' : _typeof(objA)) !== 'object' || objA === null || (typeof objB === 'undefined' ? 'undefined' : _typeof(objB)) !== 'object' || objB === null) {
    return false;
  }

  if(objA instanceof Date && objB instanceof Date) {
    return objA === objB;
  }

  const keysA = Object.keys(objA);
  const keysB = Object.keys(objB);

  if (keysA.length !== keysB.length) {
    return false;
  }

  const {
    omitKeys,
    deepKeys,
  } = options;

  // Test for A's keys different from B.
  for (let i = 0; i < keysA.length; i++) {
    // if key is an omitted key, skip comparison
    if (omitKeys && omitKeys.length && ~omitKeys.indexOf(keysA[i])) continue;


    if (deepKeys && deepKeys.length && ~deepKeys.indexOf(keysA[i])) {
      const result = shallowEqual(objA[keysA[i]], objB[keysA[i]]);

      if (!result) return false;
    } else if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
      return false;
    }
  }

  return true;
}
function shallowEqual(objA, objB, options = {}) {
  if (is(objA, objB)) {
    return true;
  }

  if ((typeof objA === 'undefined' ? 'undefined' : _typeof(objA)) !== 'object' || objA === null || (typeof objB === 'undefined' ? 'undefined' : _typeof(objB)) !== 'object' || objB === null) {
    return false;
  }

  if(objA instanceof Date && objB instanceof Date) {
    return objA === objB;
  }

  const keysA = Object.keys(objA);
  const keysB = Object.keys(objB);

  if (keysA.length !== keysB.length) {
    return false;
  }

  const {
    omitKeys,
    deepKeys,
  } = options;

  // Test for A's keys different from B.
  for (let i = 0; i < keysA.length; i++) {
    // if key is an omitted key, skip comparison
    if (omitKeys && omitKeys.length && ~omitKeys.indexOf(keysA[i])) continue;


    if (deepKeys && deepKeys.length && ~deepKeys.indexOf(keysA[i])) {
      const result = shallowEqual(objA[keysA[i]], objB[keysA[i]]);

      if (!result) return false;
    } else if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
      return false;
    }
  }

  return true;
}
function shallowEqual ( objA , objB , options = { } ) { if ( is ( objA , objB ) ) { return true ; } if ( ( typeof objA === 'undefined' ? 'undefined' : _typeof ( objA ) ) !== 'object' || objA === null || ( typeof objB === 'undefined' ? 'undefined' : _typeof ( objB ) ) !== 'object' || objB === null ) { return false ; } if ( objA instanceof Date && objB instanceof Date ) { return objA === objB ; } const keysA = Object . keys ( objA ) ; const keysB = Object . keys ( objB ) ; if ( keysA . length !== keysB . length ) { return false ; } const { omitKeys , deepKeys , } = options ; // Test for A's keys different from B. for ( let i = 0 ; i < keysA . length ; i ++ ) { // if key is an omitted key, skip comparison if ( omitKeys && omitKeys . length && ~ omitKeys . indexOf ( keysA [ i ] ) ) continue ; if ( deepKeys && deepKeys . length && ~ deepKeys . indexOf ( keysA [ i ] ) ) { const result = shallowEqual ( objA [ keysA [ i ] ] , objB [ keysA [ i ] ] ) ; if ( ! result ) return false ; } else if ( ! hasOwnProperty . call ( objB , keysA [ i ] ) || ! is ( objA [ keysA [ i ] ] , objB [ keysA [ i ] ] ) ) { return false ; } } return true ; }
Performs equality by iterating through keys on an object and returning false
when any key has values which are not strictly equal between the arguments.
Returns true when the values of all keys are strictly equal.
Performs equality by iterating through keys on an object and returning false when any key has values which are not strictly equal between the arguments . Returns true when the values of all keys are strictly equal .