Skip to content

Commit

Permalink
Update PR based on feedback
Browse files Browse the repository at this point in the history
  - Deprecate ignoreElements
  - Update docs for TimerInterval and TimeStamped
  - Update docs for flatMap
  • Loading branch information
brianegan committed Nov 29, 2019
1 parent e28e32f commit a1c8235
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 47 deletions.
6 changes: 2 additions & 4 deletions lib/src/transformers/flat_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ extension FlatMapExtension<T> on Stream<T> {
/// ### Example
///
/// RangeStream(4, 1)
/// .flatMap((i) =>
/// TimerStream(i, Duration(minutes: i))
/// .flatMap((i) => TimerStream(i, Duration(minutes: i))
/// .listen(print); // prints 1, 2, 3, 4
Stream<S> flatMap<S>(Stream<S> mapper(T value)) =>
transform(FlatMapStreamTransformer<T, S>(mapper));
Expand All @@ -129,8 +128,7 @@ extension FlatMapExtension<T> on Stream<T> {
/// ### Example
///
/// RangeStream(1, 4)
/// .flatMapIterable((i) =>
/// Stream.fromIterable([[]i])
/// .flatMapIterable((i) => Stream.fromIterable([[i]])
/// .listen(print); // prints 1, 2, 3, 4
Stream<S> flatMapIterable<S>(Stream<Iterable<S>> mapper(T value)) =>
transform(FlatMapStreamTransformer<T, Iterable<S>>(mapper))
Expand Down
2 changes: 2 additions & 0 deletions lib/src/transformers/ignore_elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'dart:async';
/// ErrorStream(Exception())
/// ])
/// .listen(print, onError: print); // prints Exception
@Deprecated('Use the drain method from the Stream class instead')
class IgnoreElementsStreamTransformer<T> extends StreamTransformerBase<T, T> {
final StreamTransformer<T, T> _transformer;

Expand Down Expand Up @@ -55,5 +56,6 @@ extension IgnoreElementsExtension<T> on Stream<T> {
/// Stream.error(Exception())
/// ])
/// .listen(print, onError: print); // prints Exception
@Deprecated('Use the drain method from the Stream class instead')
Stream<T> ignoreElements() => transform(IgnoreElementsStreamTransformer<T>());
}
5 changes: 2 additions & 3 deletions lib/src/transformers/time_interval.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ class TimeInterval<T> {
}
}

/// Extends the Stream class with the ability to wrap each item emitted by the
/// source Stream in a [Timestamped] object that includes the emitted item
/// and the time when the item was emitted.
/// Extends the Stream class with the ability to record the time interval
/// between consecutive values in an stream
extension TimeIntervalExtension<T> on Stream<T> {
/// Records the time interval between consecutive values in a Stream sequence.
///
Expand Down
4 changes: 3 additions & 1 deletion lib/src/transformers/timestamp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class Timestamped<T> {
}
}

/// Extends the Stream class with the ability to
/// Extends the Stream class with the ability to wrap each item emitted by the
/// source Stream in a [Timestamped] object that includes the emitted item and
/// the time when the item was emitted.
extension TimeStampExtension<T> on Stream<T> {
/// Wraps each item emitted by the source Stream in a [Timestamped] object
/// that includes the emitted item and the time when the item was emitted.
Expand Down
8 changes: 4 additions & 4 deletions test/streams/sequence_equals_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ void main() {
});

test('Rx.sequenceEqual.asBroadcastStream', () async {
final stream = Rx.sequenceEqual(Stream.fromIterable(const [1, 2, 3, 4, 5]),
final future = Rx.sequenceEqual(Stream.fromIterable(const [1, 2, 3, 4, 5]),
Stream.fromIterable(const [1, 2, 3, 4, 5]))
.asBroadcastStream()
.ignoreElements();
.drain<void>();

// listen twice on same stream
await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.sequenceEqual.error.shouldThrowA', () {
Expand Down
8 changes: 4 additions & 4 deletions test/transformers/backpressure/debounce_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ void main() {
});

test('Rx.debounce.asBroadcastStream', () async {
final stream = _getStream()
final future = _getStream()
.asBroadcastStream()
.debounce((_) => Stream<void>.fromFuture(
Future<void>.delayed(const Duration(milliseconds: 200))))
.ignoreElements();
.drain<void>();

await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.debounce.error.shouldThrowA', () async {
Expand Down
8 changes: 4 additions & 4 deletions test/transformers/backpressure/debounce_time_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ void main() {
});

test('Rx.debounceTime.asBroadcastStream', () async {
final stream = _getStream()
final future = _getStream()
.asBroadcastStream()
.debounceTime(const Duration(milliseconds: 200))
.ignoreElements();
.drain<void>();

await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.debounceTime.error.shouldThrowA', () async {
Expand Down
8 changes: 5 additions & 3 deletions test/transformers/backpressure/sample_time_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ void main() {
.asBroadcastStream());

await expectLater(
_getStream().transform(transformer).ignoreElements(), emitsDone);
_getStream().transform(transformer).drain<void>(),
completes,
);
await expectLater(
_getStream().transform(transformer).ignoreElements(),
emitsDone,
_getStream().transform(transformer).drain<void>(),
completes,
);
});

Expand Down
8 changes: 4 additions & 4 deletions test/transformers/backpressure/throttle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ void main() {
});

test('Rx.throttle.asBroadcastStream', () async {
final stream = _stream()
final future = _stream()
.asBroadcastStream()
.throttle(
(_) => Stream<void>.periodic(const Duration(milliseconds: 250)))
.ignoreElements();
.drain<void>();

// listen twice on same stream
await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.throttle.error.shouldThrowA', () async {
Expand Down
8 changes: 4 additions & 4 deletions test/transformers/backpressure/throttle_time_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ void main() {
});

test('Rx.throttleTime.asBroadcastStream', () async {
final stream = _stream()
final future = _stream()
.asBroadcastStream()
.throttleTime(const Duration(milliseconds: 250))
.ignoreElements();
.drain<void>();

// listen twice on same stream
await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.throttleTime.error.shouldThrowA', () async {
Expand Down
8 changes: 4 additions & 4 deletions test/transformers/backpressure/window_count_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ void main() {
});

test('Rx.windowCount.asBroadcastStream', () async {
final stream = Stream.fromIterable(const [1, 2, 3, 4])
final future = Stream.fromIterable(const [1, 2, 3, 4])
.asBroadcastStream()
.windowCount(2)
.ignoreElements();
.drain<void>();

// listen twice on same stream
await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.windowCount.error.shouldThrowA', () async {
Expand Down
8 changes: 4 additions & 4 deletions test/transformers/backpressure/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ void main() {
});

test('Rx.window.asBroadcastStream', () async {
final stream = getStream(4)
final future = getStream(4)
.asBroadcastStream()
.window(Stream<Null>.periodic(const Duration(milliseconds: 160))
.take(10)
.asBroadcastStream())
.ignoreElements();
.drain<void>();

// listen twice on same stream
await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.window.error.shouldThrowA', () async {
Expand Down
8 changes: 4 additions & 4 deletions test/transformers/backpressure/window_test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ void main() {
});

test('Rx.windowTest.asBroadcastStream', () async {
final stream = Stream.fromIterable(const [1, 2, 3, 4])
final future = Stream.fromIterable(const [1, 2, 3, 4])
.asBroadcastStream()
.windowTest((i) => i % 2 == 0)
.ignoreElements();
.drain<void>();

// listen twice on same stream
await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.windowTest.error.shouldThrowA', () async {
Expand Down
8 changes: 4 additions & 4 deletions test/transformers/backpressure/window_time_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ void main() {
});

test('Rx.windowTime.asBroadcastStream', () async {
final stream = getStream(4)
final future = getStream(4)
.asBroadcastStream()
.windowTime(const Duration(milliseconds: 160))
.ignoreElements();
.drain<void>();

// listen twice on same stream
await expectLater(stream, emitsDone);
await expectLater(stream, emitsDone);
await expectLater(future, completes);
await expectLater(future, completes);
});

test('Rx.windowTime.error.shouldThrowA', () async {
Expand Down
5 changes: 5 additions & 0 deletions test/transformers/ignore_elements_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void main() {
test('Rx.ignoreElements', () async {
var hasReceivedEvent = false;

// ignore: deprecated_member_use_from_same_package
_getStream().ignoreElements().listen((_) {
hasReceivedEvent = true;
},
Expand All @@ -30,6 +31,7 @@ void main() {
});

test('Rx.ignoreElements.reusable', () async {
// ignore: deprecated_member_use_from_same_package
final transformer = IgnoreElementsStreamTransformer<int>();
var hasReceivedEvent = false;

Expand All @@ -49,6 +51,7 @@ void main() {
});

test('Rx.ignoreElements.asBroadcastStream', () async {
// ignore: deprecated_member_use_from_same_package
final stream = _getStream().asBroadcastStream().ignoreElements();

// listen twice on same stream
Expand All @@ -61,6 +64,7 @@ void main() {
test('Rx.ignoreElements.pause.resume', () async {
var hasReceivedEvent = false;

// ignore: deprecated_member_use_from_same_package
_getStream().ignoreElements().listen((_) {
hasReceivedEvent = true;
},
Expand All @@ -72,6 +76,7 @@ void main() {
});

test('Rx.ignoreElements.error.shouldThrow', () async {
// ignore: deprecated_member_use_from_same_package
final streamWithError = Stream<void>.error(Exception()).ignoreElements();

streamWithError.listen(null,
Expand Down

0 comments on commit a1c8235

Please sign in to comment.