Skip to content

Commit

Permalink
fix(doOn): related ReactiveX/rxdart#683
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Apr 20, 2023
1 parent fa12272 commit 54273b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/src/operators/do_on.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ extension DoOnStreamExtensions<T> on Stream<T> {
void Function()? done,
void Function(Notification<T> notification)? each,
}) =>
transform(
DoStreamTransformer(
onListen: listen,
onCancel: cancel,
onPause: pause,
onResume: resume,
onData: data,
onError: error,
onDone: done,
onEach: each,
),
);
DoStreamTransformer(
onListen: listen,
onCancel: cancel,
onPause: pause,
onResume: resume,
onData: data,
onError: error,
onDone: done,
onEach: each,
).bind(this);
}
17 changes: 17 additions & 0 deletions test/operators/do_on_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:rxdart_ext/rxdart_ext.dart';
import 'package:test/test.dart';

import '../utils.dart';

void main() {
group('doOn', () {
test('works', () async {
Expand Down Expand Up @@ -33,5 +35,20 @@ void main() {

await delay(10000);
});

test('nullable', () {
nullableTest<String?>(
(s) => s.doOn(
listen: () {},
cancel: () {},
pause: () {},
resume: () {},
data: (v) {},
error: (e, s) {},
done: () {},
each: (n) {},
),
);
});
});
}
3 changes: 3 additions & 0 deletions test/utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
void unawaited(Future<void> future) {}

void nullableTest<R>(Stream<R> Function(Stream<String?> s) transform) =>
transform(Stream<String>.fromIterable(['1', '2', '3']));

/// Generates a hash code for multiple [objects].
int hashObjects(Iterable<int> objects) =>
_finish(objects.fold(0, (h, i) => _combine(h, i.hashCode)));
Expand Down

0 comments on commit 54273b8

Please sign in to comment.