Skip to content

Commit 8e2e2ce

Browse files
committed
chore: update CHANGELOG for version 0.0.5; add current state parameter to AsyncCubit and ValueCubit build functions
1 parent de9d1f1 commit 8e2e2ce

5 files changed

Lines changed: 26 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ Initial Version of the library.
2020
* Bump flutter_bloc dependency version to 9.0.0
2121
* Bump very_good_analysis from 5.1.0 to 6.0.0
2222
* Bump get_it to 8.0.0
23-
* Discard automatic loading state emission in AsyncCubit internal build
23+
* Discard automatic loading state emission in AsyncCubit internal build
24+
25+
## 0.0.5
26+
* Add current state parameter to build function in AsyncCubit
27+
* Add current state parameter to build function in ValueCubit

example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final todoListFilter =
4343
/// number of uncompleted todos doesn't (such as when editing a todo).
4444
final uncompletedTodosCount = RiveBlocProvider.value(() => ValueCubit<int>(
4545
0,
46-
build: (ref, args) {
46+
build: (ref, args, _) {
4747
return ref
4848
.watch(todoListProvider)
4949
.state
@@ -58,7 +58,7 @@ final uncompletedTodosCount = RiveBlocProvider.value(() => ValueCubit<int>(
5858
/// list unless either the filter of or the todo-list updates.
5959
final filteredTodos =
6060
RiveBlocProvider.value<ValueCubit<List<Todo>>, List<Todo>>(
61-
() => ValueCubit([], build: (ref, args) {
61+
() => ValueCubit([], build: (ref, args, _) {
6262
final filter = ref.watch(todoListFilter).state;
6363
final todos = ref.watch(todoListProvider).state;
6464

lib/src/blocs/async_cubit.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ class AsyncCubit<ValueT extends Object?> extends RiveCubit<AsyncValue<ValueT>>
4949
final FutureOr<ValueT> Function(
5050
RiveBlocRef ref,
5151
Args args,
52+
ValueT? state,
5253
) _asyncFn;
5354

5455
/// Obtains the [Future] associated with the `async` function
5556
/// of this [AsyncCubit].
56-
Future<ValueT> get future async => await _asyncFn(ref, args ?? const Args());
57+
Future<ValueT> get future async => await _asyncFn(
58+
ref,
59+
args ?? const Args(),
60+
state.value,
61+
);
5762

5863
@override
5964
@internal
@@ -63,7 +68,11 @@ class AsyncCubit<ValueT extends Object?> extends RiveCubit<AsyncValue<ValueT>>
6368

6469
// Run the async function and emit the result.
6570
final newState = await AsyncValue.guard(
66-
() async => await _asyncFn(ref, args ?? const Args()),
71+
() async => await _asyncFn(
72+
ref,
73+
args ?? const Args(),
74+
state.value,
75+
),
6776
);
6877
emit(newState);
6978

lib/src/blocs/value_cubit.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ class ValueCubit<T extends Object?> extends RiveCubit<T>
104104
FutureOr<T> Function(
105105
RiveBlocRef ref,
106106
Args args,
107+
T state,
107108
)? build,
108109
}) : _valueFn = build,
109110
super(() => initialState);
110111

111112
final FutureOr<T> Function(
112113
RiveBlocRef ref,
113114
Args args,
115+
T state,
114116
)? _valueFn;
115117

116118
/// Obtains the [Future] associated with the `build` function
@@ -122,7 +124,11 @@ class ValueCubit<T extends Object?> extends RiveCubit<T>
122124
@override
123125
FutureOr<T> build(RiveBlocRef ref, Args? args) {
124126
if (_valueFn == null) return state;
125-
return _valueFn!(ref, args ?? const Args());
127+
return _valueFn!(
128+
ref,
129+
args ?? const Args(),
130+
state,
131+
);
126132
}
127133

128134
/// You can set the [state] value at any time from outside!

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: rive_bloc
22
description: >
33
A Simplified Flutter BLoC API Layer, Deeply Inspired by Riverpod. RiveBloc
44
makes working with BLoC less verbose and less time-consuming.
5-
version: 0.0.4
5+
version: 0.0.5
66
repository: https://github.com/jovazcode/rive_bloc
77
topics:
88
[

0 commit comments

Comments
 (0)