Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(bloc): use Object.hashAll #4310

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bloc/lib/src/change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Change<State> {
nextState == other.nextState;

@override
int get hashCode => currentState.hashCode ^ nextState.hashCode;
int get hashCode => Object.hashAll([currentState, nextState]);

@override
String toString() {
Expand Down
4 changes: 1 addition & 3 deletions packages/bloc/lib/src/transition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class Transition<Event, State> extends Change<State> {
nextState == other.nextState;

@override
int get hashCode {
return currentState.hashCode ^ event.hashCode ^ nextState.hashCode;
}
int get hashCode => Object.hashAll([currentState, event, nextState]);

@override
String toString() {
Expand Down
2 changes: 1 addition & 1 deletion packages/bloc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ topics: [bloc, state-management]
funding: [https://github.com/sponsors/felangel]

environment:
sdk: ">=2.12.0 <4.0.0"
sdk: ">=2.14.0 <4.0.0"

dependencies:
meta: ^1.3.0
Expand Down
2 changes: 1 addition & 1 deletion packages/bloc/test/blocs/async/async_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AsyncEvent {
other is AsyncEvent && runtimeType == other.runtimeType;

@override
int get hashCode => runtimeType.hashCode;
int get hashCode => Object.hashAll([runtimeType]);

@override
String toString() => 'AsyncEvent';
Expand Down
3 changes: 1 addition & 2 deletions packages/bloc/test/blocs/async/async_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class AsyncState {
isSuccess == other.isSuccess;

@override
int get hashCode =>
isLoading.hashCode ^ hasError.hashCode ^ isSuccess.hashCode;
int get hashCode => Object.hashAll([isLoading, hasError, isSuccess]);

@override
String toString() =>
Expand Down
14 changes: 8 additions & 6 deletions packages/bloc/test/transition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CounterEvent extends TransitionEvent {
eventData == other.eventData;

@override
int get hashCode => eventData.hashCode;
int get hashCode => Object.hashAll([eventData]);
}

class CounterState extends TransitionState {
Expand All @@ -41,7 +41,7 @@ class CounterState extends TransitionState {
count == other.count;

@override
int get hashCode => count.hashCode;
int get hashCode => Object.hashAll([count]);
}

void main() {
Expand Down Expand Up @@ -78,7 +78,7 @@ void main() {
const change = Change<int>(currentState: 0, nextState: 1);
expect(
change.hashCode,
change.currentState.hashCode ^ change.nextState.hashCode,
Object.hashAll([change.currentState, change.nextState]),
);
});
});
Expand Down Expand Up @@ -196,9 +196,11 @@ void main() {
);
expect(
transition.hashCode,
transition.currentState.hashCode ^
transition.event.hashCode ^
transition.nextState.hashCode,
Object.hashAll([
transition.currentState,
transition.event,
transition.nextState,
]),
);
});
});
Expand Down
Loading