Skip to content

Commit

Permalink
fix: revert EquatableMixin == to use Object (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Jun 14, 2021
1 parent 0ba67c7 commit 859b195
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
2 changes: 1 addition & 1 deletion lib/src/equatable_mixin.dart
Expand Up @@ -16,7 +16,7 @@ mixin EquatableMixin {
bool? get stringify => null;

@override
bool operator ==(Object? other) {
bool operator ==(Object other) {
return identical(this, other) ||
other is EquatableMixin &&
runtimeType == other.runtimeType &&
Expand Down
43 changes: 0 additions & 43 deletions test/equatable_mixin_test.dart
Expand Up @@ -122,32 +122,6 @@ class IterableWithFlag<T> extends Iterable<T> with EquatableMixin {
Iterator<T> get iterator => list.iterator;
}

class LegacyEqualityOverride {
const LegacyEqualityOverride(this.x);

final int x;

@override
bool operator ==(dynamic o) {
if (identical(this, o)) return true;

return o is LegacyEqualityOverride && o.x == x;
}

@override
int get hashCode => x.hashCode;
}

class LegacyEqualityOverrideEquatable extends LegacyEqualityOverride
with EquatableMixin {
LegacyEqualityOverrideEquatable(int x, this.y) : super(x);

final int y;

@override
List<Object?> get props => [x, y];
}

void main() {
late bool globalStringify;

Expand Down Expand Up @@ -701,21 +675,4 @@ void main() {
expect(instanceA == instanceB, isFalse);
});
});

group('LegacyEqualityOverride', () {
test('should be equal when different instances have same values', () {
final instanceA = LegacyEqualityOverrideEquatable(0, 1);
final instanceB = LegacyEqualityOverrideEquatable(0, 1);

expect(instanceA == instanceB, isTrue);
});

test('should not be equal when different instances have different values',
() {
final instanceA = LegacyEqualityOverrideEquatable(0, 0);
final instanceB = LegacyEqualityOverrideEquatable(0, 1);

expect(instanceA == instanceB, isFalse);
});
});
}

0 comments on commit 859b195

Please sign in to comment.