Skip to content

4.1.0

Compare
Choose a tag to compare
@alexreardon alexreardon released this 11 Dec 23:27
· 142 commits to master since this release

🛑This release has been deprecated

New feature: index provided to equality function #42

🛑This feature has been removed and replaced with a new custom equality pattern

Thanks @nihgwu for submitting this one!

If you are not providing your own custom equality function then there nothing to see here 👍

Custom equality functions are now provided with a third argument: the index of the argument.

-type EqualityFn = (newValue: mixed, oldValue: mixed) => boolean;
+type EqualityFn = (newValue: mixed, oldValue: mixed, index: number) => boolean;

This can be useful if you want to do different types of checking depending on the order of the argument.

import memoizeOne from 'memoize-one';
import deepEqual from 'lodash.isEqual';

const myEqualFn = (newArg, lastArg, index) => {
  // use deep equal for first arg
  if(index === 0) {
    return deepEqual(newArg, lastArg);
  }
  // use shallow equal for all other arguments
  return newArg === lastArg;
}

const fn = (...args) => {
  console.log('called with', ...args);
};
const memoized = memoizeOne(fn, myEqualFn);

memoized({hello: 'world'}, 5);
// console.log('called with', {hello: 'world'}, 5);

memoized({hello: 'world'}, 5);
// no call to console.log

This resulted in a feature release

Engineering health

  • Upgraded to flow 0.88
  • Upgraded all flow-typed lib definitions
  • Upgraded all dev dependencies