Skip to content

Commit 08200a6

Browse files
authored
refactor(bloc): improve onTransition and onEvent signature (felangel#2241)
1 parent 97f8262 commit 08200a6

File tree

12 files changed

+19
-21
lines changed

12 files changed

+19
-21
lines changed

examples/flutter_complex_list/lib/simple_bloc_observer.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class SimpleBlocObserver extends BlocObserver {
88
}
99

1010
@override
11-
void onTransition(BlocBase bloc, Transition transition) {
11+
void onTransition(Bloc bloc, Transition transition) {
1212
super.onTransition(bloc, transition);
1313
print(transition);
1414
}

examples/flutter_counter/lib/counter_observer.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:bloc/bloc.dart';
66
/// {@endtemplate}
77
class CounterObserver extends BlocObserver {
88
@override
9-
void onTransition(BlocBase bloc, Transition transition) {
9+
void onTransition(Bloc bloc, Transition transition) {
1010
super.onTransition(bloc, transition);
1111
print('${bloc.runtimeType} $transition');
1212
}

examples/flutter_firestore_todos/lib/blocs/simple_bloc_observer.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import 'package:bloc/bloc.dart';
44
// in order to handle transitions and errors from all Blocs.
55
class SimpleBlocObserver extends BlocObserver {
66
@override
7-
void onEvent(BlocBase bloc, Object event) {
7+
void onEvent(Bloc bloc, Object event) {
88
super.onEvent(bloc, event);
99
print(event);
1010
}
1111

1212
@override
13-
void onTransition(BlocBase bloc, Transition transition) {
13+
void onTransition(Bloc bloc, Transition transition) {
1414
super.onTransition(bloc, transition);
1515
print(transition);
1616
}

examples/flutter_infinite_list/lib/simple_bloc_observer.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:bloc/bloc.dart';
22

33
class SimpleBlocObserver extends BlocObserver {
44
@override
5-
void onTransition(BlocBase bloc, Transition transition) {
5+
void onTransition(Bloc bloc, Transition transition) {
66
super.onTransition(bloc, transition);
77
print(transition);
88
}

examples/flutter_shopping_cart/lib/simple_bloc_observer.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:bloc/bloc.dart';
22

33
class SimpleBlocObserver extends BlocObserver {
44
@override
5-
void onEvent(BlocBase bloc, Object? event) {
5+
void onEvent(Bloc bloc, Object? event) {
66
super.onEvent(bloc, event);
77
print('${bloc.runtimeType} $event');
88
}
@@ -14,7 +14,7 @@ class SimpleBlocObserver extends BlocObserver {
1414
}
1515

1616
@override
17-
void onTransition(BlocBase bloc, Transition transition) {
17+
void onTransition(Bloc bloc, Transition transition) {
1818
super.onTransition(bloc, transition);
1919
print(transition);
2020
}

examples/flutter_todos/lib/blocs/simple_bloc_observer.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import 'package:bloc/bloc.dart';
44
// in order to handle transitions and errors from all Blocs.
55
class SimpleBlocObserver extends BlocObserver {
66
@override
7-
void onEvent(BlocBase bloc, Object event) {
7+
void onEvent(Bloc bloc, Object event) {
88
super.onEvent(bloc, event);
99
print(event);
1010
}
1111

1212
@override
13-
void onTransition(BlocBase bloc, Transition transition) {
13+
void onTransition(Bloc bloc, Transition transition) {
1414
super.onTransition(bloc, transition);
1515
print(transition);
1616
}

packages/bloc/CHANGELOG.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
- **BREAKING**: refactor: `Bloc` and `Cubit` extend `BlocBase`
44
- refactor: `void onError(Bloc bloc, Object error, StackTrace stackTrace)` -> `void onError(BlocBase bloc, Object error, StackTrace stackTrace)`
5-
- refactor: `void onEvent(Bloc bloc, Object? event)` -> `void onEvent(BlocBase bloc, Object? event)`
65
- refactor: `void onCreate(Bloc bloc)` -> `void onCreate(BlocBase bloc)`
76
- refactor: `void onClose(Bloc bloc)` -> `void onClose(BlocBase bloc)`
87
- **BREAKING**: refactor: `Transition` event is required
@@ -11,7 +10,6 @@
1110
- `myBloc.map(...)` -> `myBloc.stream.map(...)`
1211
- refactor: deprecate `bloc.listen` in favor of `bloc.stream.listen`
1312
- **BREAKING**: revert: refactor: `Change` and `onChange` removed in favor of `Transition` and `onTransition`
14-
- fix: `toString` on `Transition` excludes null `event`
1513

1614
# 7.0.0-nullsafety.3
1715

packages/bloc/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class MyBlocObserver extends BlocObserver {
292292
}
293293
294294
@override
295-
void onEvent(BlocBase bloc, Object event) {
295+
void onEvent(Bloc bloc, Object event) {
296296
super.onEvent(bloc, event);
297297
print('onEvent -- bloc: ${bloc.runtimeType}, event: $event');
298298
}
@@ -304,7 +304,7 @@ class MyBlocObserver extends BlocObserver {
304304
}
305305
306306
@override
307-
void onTransition(BlocBase bloc, Transition transition) {
307+
void onTransition(Bloc bloc, Transition transition) {
308308
super.onTransition(bloc, transition);
309309
print('onTransition -- bloc: ${bloc.runtimeType}, transition: $transition');
310310
}

packages/bloc/example/main.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SimpleBlocObserver extends BlocObserver {
1010
}
1111

1212
@override
13-
void onEvent(BlocBase bloc, Object? event) {
13+
void onEvent(Bloc bloc, Object? event) {
1414
super.onEvent(bloc, event);
1515
print('onEvent -- bloc: ${bloc.runtimeType}, event: $event');
1616
}
@@ -22,7 +22,7 @@ class SimpleBlocObserver extends BlocObserver {
2222
}
2323

2424
@override
25-
void onTransition(BlocBase bloc, Transition transition) {
25+
void onTransition(Bloc bloc, Transition transition) {
2626
super.onTransition(bloc, transition);
2727
print('onTransition -- bloc: ${bloc.runtimeType}, transition: $transition');
2828
}

packages/bloc/lib/src/bloc_observer.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BlocObserver {
1515
/// and [event].
1616
@protected
1717
@mustCallSuper
18-
void onEvent(BlocBase bloc, Object? event) {}
18+
void onEvent(Bloc bloc, Object? event) {}
1919

2020
/// Called whenever a [Change] occurs in any [bloc]
2121
/// A [change] occurs when a new state is emitted.
@@ -31,7 +31,7 @@ class BlocObserver {
3131
/// [onTransition] is called before a [bloc]'s state has been updated.
3232
@protected
3333
@mustCallSuper
34-
void onTransition(BlocBase bloc, Transition transition) {}
34+
void onTransition(Bloc bloc, Transition transition) {}
3535

3636
/// Called whenever an [error] is thrown in any [Bloc] or [Cubit].
3737
/// The [stackTrace] argument may be [StackTrace.empty] if an error

packages/flutter_bloc/example/lib/main.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import 'package:flutter_bloc/flutter_bloc.dart';
66
/// Custom [BlocObserver] which observes all bloc and cubit instances.
77
class SimpleBlocObserver extends BlocObserver {
88
@override
9-
void onEvent(BlocBase bloc, Object? event) {
9+
void onEvent(Bloc bloc, Object? event) {
1010
super.onEvent(bloc, event);
1111
print(event);
1212
}
1313

1414
@override
15-
void onTransition(BlocBase bloc, Transition transition) {
15+
void onTransition(Bloc bloc, Transition transition) {
1616
super.onTransition(bloc, transition);
1717
print(transition);
1818
}

packages/replay_bloc/example/lib/simple_bloc_observer.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:bloc/bloc.dart';
33
/// Simple [BlocObserver] which just prints to the debug console.
44
class SimpleBlocObserver extends BlocObserver {
55
@override
6-
void onEvent(BlocBase bloc, Object? event) {
6+
void onEvent(Bloc bloc, Object? event) {
77
super.onEvent(bloc, event);
88
print('${bloc.runtimeType} $event');
99
}
@@ -21,7 +21,7 @@ class SimpleBlocObserver extends BlocObserver {
2121
}
2222

2323
@override
24-
void onTransition(BlocBase bloc, Transition transition) {
24+
void onTransition(Bloc bloc, Transition transition) {
2525
super.onTransition(bloc, transition);
2626
print('${bloc.runtimeType} $transition');
2727
}

0 commit comments

Comments
 (0)