-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
577 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,53 @@ | ||
# 0.1.0 | ||
# 0.2.0 | ||
|
||
Initial Version of the library. | ||
Add `EquatableMixin` and `EquatableMixinBase` | ||
|
||
- Includes the ability to extend `Equatable` and not have to override `==` and `hashCode`. | ||
# 0.1.10 | ||
|
||
# 0.1.1 | ||
Enhancements to `toString` override | ||
|
||
Minor Updates to Documentation. | ||
# 0.1.9 | ||
|
||
# 0.1.2 | ||
equatable has 0 dependencies | ||
|
||
Additional Updates to Documentation. | ||
# 0.1.8 | ||
|
||
- Logo Added | ||
Support `Iterable` props | ||
|
||
# 0.1.3 | ||
# 0.1.7 | ||
|
||
Bug Fixes | ||
Added `toString` override | ||
|
||
# 0.1.4 | ||
# 0.1.6 | ||
|
||
Performance Optimizations | ||
Documentation Updates | ||
|
||
- Performance Tests | ||
|
||
# 0.1.5 | ||
|
||
Additional Performance Optimizations & Documentation Updates | ||
|
||
# 0.1.6 | ||
# 0.1.4 | ||
|
||
Documentation Updates | ||
Performance Optimizations | ||
|
||
- Performance Tests | ||
# 0.1.3 | ||
|
||
# 0.1.7 | ||
Bug Fixes | ||
|
||
Added `toString` override | ||
# 0.1.2 | ||
|
||
# 0.1.8 | ||
Additional Updates to Documentation. | ||
|
||
Support `Iterable` props | ||
- Logo Added | ||
|
||
# 0.1.9 | ||
# 0.1.1 | ||
|
||
equatable has 0 dependencies | ||
Minor Updates to Documentation. | ||
|
||
# 0.1.10 | ||
# 0.1.0 | ||
|
||
Enhancements to `toString` override | ||
Initial Version of the library. | ||
|
||
- Includes the ability to extend `Equatable` and not have to override `==` and `hashCode`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
library equatable; | ||
|
||
export './src/equatable.dart'; | ||
export './src/equatable_mixin.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import './equatable_utils.dart'; | ||
|
||
/// You must define the [EquatableMixinBase] on the class | ||
/// which you want to make Equatable. | ||
/// `class EquatableDateTime extends DateTime with EquatableMixinBase, EquatableMixin { ... }` | ||
/// This exposes the `props` getter which can then be overridden to include custom props in subclasses. | ||
/// The `props` getter is used to override `==` and `hashCode` in the [EquatableMixin]. | ||
mixin EquatableMixinBase on Object { | ||
List get props => []; | ||
|
||
@override | ||
String toString() => super.toString(); | ||
} | ||
|
||
/// You must define the [EquatableMixin] on the class | ||
/// which you want to make Equatable and the class | ||
/// must also be a descendent of [EquatableMixinBase]. | ||
/// [EquatableMixin] does the override of the `==` operator as well as `hashCode`. | ||
mixin EquatableMixin on EquatableMixinBase { | ||
@override | ||
bool operator ==(Object other) { | ||
return identical(this, other) || | ||
other is EquatableMixin && | ||
runtimeType == other.runtimeType && | ||
equals(props, other.props); | ||
} | ||
|
||
@override | ||
int get hashCode => runtimeType.hashCode ^ mapPropsToHashCode(props); | ||
|
||
@override | ||
String toString() => props.isNotEmpty ? props.toString() : super.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
int mapPropsToHashCode(List props) { | ||
int hashCode = 0; | ||
|
||
props.forEach((prop) { | ||
hashCode = hashCode ^ prop.hashCode; | ||
}); | ||
|
||
return hashCode; | ||
} | ||
|
||
bool equals(dynamic list1, dynamic list2) { | ||
if (identical(list1, list2)) return true; | ||
if (list1 == null || list2 == null) return false; | ||
int length = list1.length; | ||
if (length != list2.length) return false; | ||
for (int i = 0; i < length; i++) { | ||
if (list1[i] is Iterable) { | ||
if (!equals(list1[i], list2[i])) return false; | ||
} else { | ||
if (list1[i] != list2[i]) return false; | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
name: equatable | ||
description: An abstract class that helps to implement equality without needing to explicitly override == and hashCode. | ||
version: 0.1.10 | ||
version: 0.2.0 | ||
author: felix.angelov <[email protected]> | ||
homepage: https://github.com/felangel/equatable | ||
|
||
environment: | ||
sdk: ">=2.0.0-dev.28.0 <3.0.0" | ||
sdk: ">=2.1.0 <3.0.0" | ||
|
||
dev_dependencies: | ||
test: ">=1.3.0 <2.0.0" | ||
|
Oops, something went wrong.