How to use fast-equals - 10 common examples

To help you get started, we’ve selected a few fast-equals examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DestinyItemManager / DIM / src / app / storage / sync.service.ts View on Github external
async set(value: Partial, PUT = false): Promise {
    if (!cached) {
      throw new Error('Must call get at least once before setting');
    }

    if (!PUT && deepEqual(_.pick(cached, Object.keys(value)), value)) {
      if ($featureFlags.debugSync) {
        console.log(_.pick(cached, Object.keys(value)), value);
        console.log('Skip save, already got it');
      }
      return;
    }

    // use replace to override the data. normally we're doing a PATCH
    if (PUT) {
      // update our data
      cached = copy(value) as DimData;
    } else {
      Object.assign(cached, copy(value));
    }

    for (const adapter of adapters) {
github planttheidea / react-local-redux / src / connectLocal.js View on Github external
props,
      state,
    } = instance;

    if (typeof actionCreators === 'function' && (!pure || !areOwnPropsEqual(props, nextProps))) {
      instance.actionCreators = getActionCreators(actionCreators, __store.dispatch, nextProps);
    }

    if (!pure) {
      return true;
    }

    return (
      !areOwnPropsEqual(props, nextProps)
      || !areStatesEqual(state, nextState)
      || !shallowEqual(context, nextContext)
      || !areMergedPropsEqual(
        // eslint workaround
        mergeProps(state, wrappedActionCreators, props),
        mergeProps(nextState, instance.actionCreators, nextProps)
      )
    );
  };
github planttheidea / inline-loops.macro / __tests__ / __runtime__ / map.js View on Github external
return isEven;
        }),
        DECREMENTING_ARRAY_RESULT,
      ),
    },
    object: {
      false: isEqual(
        mapObject(Object.assign({}, OBJECT), value => {
          const isEven = value % 2 === 0;

          return isEven;
        }),
        BAD_OBJECT_RESULT,
      ),
      true: isEqual(
        mapObject(Object.assign({}, OBJECT), value => {
          const isEven = value % 2 === 0;

          return isEven;
        }),
        OBJECT_RESULT,
      ),
    },
    standard: {
      false: isEqual(
        map([].concat(ARRAY), value => {
          const isEven = value % 2 === 0;

          return isEven;
        }),
        BAD_ARRAY_RESULT,
github planttheidea / inline-loops.macro / __tests__ / __runtime__ / reduce.js View on Github external
object: {
      false: isEqual(
        reduceObject(OBJECT, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        BAD_OBJECT_RESULT,
      ),
      true: isEqual(
        reduceObject(OBJECT, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        OBJECT_RESULT,
      ),
    },
    standard: {
      false: isEqual(
        reduce(ARRAY, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        BAD_ARRAY_RESULT,
      ),
      true: isEqual(
        reduce(ARRAY, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        ARRAY_RESULT,
      ),
    },
  },
  inlinedArrowReturn: {
    decrementing: {
      false: isEqual(
        reduceRight(
          ARRAY,
          (total, value) => {
            return value % 2 === 0 ? total + value : total;
          },
          10,
        ),
        BAD_DECREMENTING_ARRAY_RESULT,
github planttheidea / inline-loops.macro / __tests__ / __runtime__ / reduce-no-initialValue.js View on Github external
),
      true: isEqual(
        reduceRight(ARRAY, function(total, value) {
          return value % 2 === 0 ? total + value : total;
        }),
        DECREMENTING_ARRAY_RESULT,
      ),
    },
    object: {
      false: isEqual(
        reduceObject(OBJECT, function(total, value) {
          return value % 2 === 0 ? total + value : total;
        }),
        BAD_OBJECT_RESULT,
      ),
      true: isEqual(
        reduceObject(OBJECT, function(total, value) {
          return value % 2 === 0 ? total + value : total;
        }),
        OBJECT_RESULT,
      ),
    },
    standard: {
      false: isEqual(
        reduce(ARRAY, (total, value) => {
          return value % 2 === 0 ? total + value : total;
        }),
        BAD_ARRAY_RESULT,
      ),
      true: isEqual(
        reduce(ARRAY, (total, value) => {
          return value % 2 === 0 ? total + value : total;
github planttheidea / inline-loops.macro / __tests__ / __runtime__ / reduce.js View on Github external
decrementing: {
      false: isEqual(
        reduceRight(ARRAY, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        BAD_DECREMENTING_ARRAY_RESULT,
      ),
      true: isEqual(
        reduceRight(ARRAY, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        DECREMENTING_ARRAY_RESULT,
      ),
    },
    object: {
      false: isEqual(
        reduceObject(OBJECT, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        BAD_OBJECT_RESULT,
      ),
      true: isEqual(
        reduceObject(OBJECT, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        OBJECT_RESULT,
      ),
    },
    standard: {
      false: isEqual(
        reduce(ARRAY, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        BAD_ARRAY_RESULT,
      ),
      true: isEqual(
        reduce(ARRAY, (total, value) => (value % 2 === 0 ? total + value : total), 10),
        ARRAY_RESULT,
      ),
    },
  },
  inlinedArrowReturn: {
github planttheidea / inline-loops.macro / __tests__ / __runtime__ / filter.js View on Github external
decrementing: {
      false: isEqual(filterRight(ARRAY, isEven), BAD_DECREMENTING_ARRAY_RESULT),
      true: isEqual(filterRight(ARRAY, isEven), DECREMENTING_ARRAY_RESULT),
    },
    object: {
      false: isEqual(filterObject(OBJECT, isEven), BAD_OBJECT_RESULT),
      true: isEqual(filterObject(OBJECT, isEven), OBJECT_RESULT),
    },
    standard: {
      false: isEqual(filter(ARRAY, isEven), BAD_ARRAY_RESULT),
      true: isEqual(filter(ARRAY, isEven), ARRAY_RESULT),
    },
  },
  inlinedArrowExpression: {
    decrementing: {
      false: isEqual(filterRight(ARRAY, value => value % 2 === 0), BAD_DECREMENTING_ARRAY_RESULT),
      true: isEqual(filterRight(ARRAY, value => value % 2 === 0), DECREMENTING_ARRAY_RESULT),
    },
    object: {
      false: isEqual(filterObject(OBJECT, value => value % 2 === 0), BAD_OBJECT_RESULT),
      true: isEqual(filterObject(OBJECT, value => value % 2 === 0), OBJECT_RESULT),
    },
    standard: {
      false: isEqual(filter(ARRAY, value => value % 2 === 0), BAD_ARRAY_RESULT),
      true: isEqual(filter(ARRAY, value => value % 2 === 0), ARRAY_RESULT),
    },
  },
  inlinedArrowReturn: {
    decrementing: {
      false: isEqual(
        filterRight(ARRAY, value => {
          return value % 2 === 0;
github planttheidea / inline-loops.macro / __tests__ / __runtime__ / map.js View on Github external
const ARRAY_RESULT = ARRAY.map(isEven);

const BAD_DECREMENTING_ARRAY_RESULT = [...BAD_ARRAY_RESULT].reverse();
const DECREMENTING_ARRAY_RESULT = [...ARRAY_RESULT].reverse();

const BAD_OBJECT_RESULT = Object.assign({}, OBJECT);
const OBJECT_RESULT = Object.keys(OBJECT).reduce((evenObject, key) => {
  evenObject[key] = isEven(OBJECT[key]);

  return evenObject;
}, {});

module.exports = {
  cached: {
    decrementing: {
      false: isEqual(mapRight(ARRAY, isEven), BAD_DECREMENTING_ARRAY_RESULT),
      true: isEqual(mapRight(ARRAY, isEven), DECREMENTING_ARRAY_RESULT),
    },
    object: {
      false: isEqual(mapObject(OBJECT, isEven), BAD_OBJECT_RESULT),
      true: isEqual(mapObject(OBJECT, isEven), OBJECT_RESULT),
    },
    standard: {
      false: isEqual(map(ARRAY, isEven), BAD_ARRAY_RESULT),
      true: isEqual(map(ARRAY, isEven), ARRAY_RESULT),
    },
  },
  inlinedArrowExpression: {
    decrementing: {
      false: isEqual(mapRight(ARRAY, value => value % 2 === 0), BAD_DECREMENTING_ARRAY_RESULT),
      true: isEqual(mapRight(ARRAY, value => value % 2 === 0), DECREMENTING_ARRAY_RESULT),
    },
github planttheidea / inline-loops.macro / __tests__ / __runtime__ / reduce-no-initialValue.js View on Github external
object: {
      false: isEqual(
        reduceObject(OBJECT, (total, value) => {
          return value % 2 === 0 ? total + value : total;
        }),
        BAD_OBJECT_RESULT,
      ),
      true: isEqual(
        reduceObject(OBJECT, (total, value) => {
          return value % 2 === 0 ? total + value : total;
        }),
        OBJECT_RESULT,
      ),
    },
    standard: {
      false: isEqual(
        reduce(ARRAY, (total, value) => {
          return value % 2 === 0 ? total + value : total;
        }),
        BAD_ARRAY_RESULT,
      ),
      true: isEqual(
        reduce(ARRAY, (total, value) => {
          return value % 2 === 0 ? total + value : total;
        }),
        ARRAY_RESULT,
      ),
    },
  },
  inlinedFunctionReturn: {
    decrementing: {
      false: isEqual(
github planttheidea / fast-copy / DEV_ONLY / App.js View on Github external
'nan',
  'nil',
  'number',
  'promise',
  'string',
  'symbol',
  'undef',
  'weakmap',
  'weakset',
];

const newObject = copy(object);

console.log(object, newObject);

console.log('is equal object', sameValueZeroEqual(object, newObject));
console.log('is shallowEqual object', shallowEqual(object, newObject));
console.log('is deepEqual object', deepEqual(object, newObject));

console.log('lodash copy', _.cloneDeep(object));
console.log('clone copy', clone(object));
console.log('deepclone copy', deepClone(object));

Object.keys(object).forEach((key) => {
  console.group(key);
  console.log(`new object has key ${key}`, Object.prototype.hasOwnProperty.call(newObject, key));

  if (~primitiveKeys.indexOf(key)) {
    console.log(`is ${key} equal`, sameValueZeroEqual(object[key], newObject[key]));
  } else {
    console.log(`is ${key} not equal`, !sameValueZeroEqual(object[key], newObject[key]));
    console.log(`is ${key} equivalent`, deepEqual(object[key], newObject[key]));

fast-equals

A blazing fast equality comparison, either shallow or deep

MIT
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis