Skip to content

Commit

Permalink
Update to change DendencyConfig identity method to member hashing.
Browse files Browse the repository at this point in the history
This also paves the way to a future enhancement where dependency type aliases utilise the hash instead of an incrementing int - which will make them stable across changes to the dependency list
  • Loading branch information
adam-langley-minrisk committed Mar 17, 2024
1 parent b5b9a4d commit 93a3a9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion injectable_generator/lib/code_builder/builder_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension _InjectedDependencyX on InjectedDependency {
@visibleForTesting
Set<DependencyConfig> sortDependencies(Iterable<DependencyConfig> it) {
// sort dependencies alphabetically by all the various attributes that may make them unique
final deps = it.toList()..sortBy((e) => e.toString());
final deps = it.toList()..sortBy<num>((e) => e.identityHash);
// sort dependencies by their register order
final List<DependencyConfig> sorted = [];
_sortByDependents(deps, sorted);
Expand Down
12 changes: 11 additions & 1 deletion injectable_generator/lib/models/dependency_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DependencyConfig {
final int orderPosition;
final String? scope;

const DependencyConfig({
DependencyConfig({
required this.type,
required this.typeImpl,
this.injectableType = InjectableType.factory,
Expand Down Expand Up @@ -144,6 +144,16 @@ class DependencyConfig {
postConstructReturnsSelf.hashCode ^
scope.hashCode;

late final int identityHash = type.identity.hashCode ^
typeImpl.identity.hashCode ^
injectableType.hashCode ^
instanceName.hashCode ^
orderPosition.hashCode ^
scope.hashCode ^
const ListEquality().hash(dependencies) ^
const ListEquality().hash(dependsOn) ^
const ListEquality().hash(environments);

factory DependencyConfig.fromJson(Map<dynamic, dynamic> json) {
ModuleConfig? moduleConfig;
DisposeFunctionConfig? disposeFunction;
Expand Down

0 comments on commit 93a3a9b

Please sign in to comment.