getDiff method

  1. @visibleForTesting
Map<String, String> getDiff(
  1. Equatable other
)
inherited

Returns a map of properties that differ between this object and another.

Implementation

@visibleForTesting
Map<String, String> getDiff(Equatable other) {
  final diff = <String, String>{};

  // Return empty map if no differences
  if (this == other) return diff;

  final otherProps = other.props;

  // Handle different props lengths
  if (props.length != otherProps.length) {
    diff['props.length'] =
        'this: ${props.length}, other: ${otherProps.length}';

    return diff;
  }

  final length = props.length;

  for (int i = 0; i < length; i++) {
    final unit1 = props[i];
    final unit2 = otherProps[i];

    final differences = compareObjects(unit1, unit2);
    if (differences.isNotEmpty) {
      final propName =
          unit1?.runtimeType.toString() ??
          unit2?.runtimeType.toString() ??
          'N/A';
      diff[propName] = differences.toString();
    }
  }

  return diff;
}