diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b61565..7ec00fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.2.3 - Jul 22, 2022 + +- Fix: remove `@internal` on `StateStream.asBroadcastStateStream` extension method. +- `Stream.toSingleSubscriptionStream()` now returns a new `Stream` every call + instead of the input stream even if it's a single-subscription Stream. + ## 0.2.2 - Jun 1, 2022 - Revert `path` to `^1.8.0` (because `flutter_test` from Flutter sdk (`>= 2.5.0`) depends on path `1.8.0` or `1.8.1`). diff --git a/README.md b/README.md index e4b4b3c..fdf5aa1 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,13 @@ Liked some of my work? Buy me a coffee (or more likely a beer) ## RxDart compatibility -| **rxdart** | **rxdart_ext** | -|:-----------------------:|:---------------------:| -| `0.26.0` | `below 0.0.1` | -| `from 0.27.0 to 0.27.1` | `from 0.1.0 to 0.1.1` | -| `0.27.2` | `0.1.2` | -| `0.27.3` | `from 0.1.3 to 0.2.0` | -| `from 0.27.4 to 0.27.5` | `from 0.2.1 to 0.2.2` | +| **rxdart** | **rxdart_ext** | +|:------------------------:|:---------------------:| +| `0.26.0` | `below 0.0.1` | +| `from 0.27.0 to 0.27.1` | `from 0.1.0 to 0.1.1` | +| `0.27.2` | `0.1.2` | +| `0.27.3` | `from 0.1.3 to 0.2.0` | +| `from 0.27.4 to 0.27.5` | `from 0.2.1 to 0.2.3` | ## API diff --git a/lib/src/operators/to_single_subscription.dart b/lib/src/operators/to_single_subscription.dart index 4daa281..1833dbd 100644 --- a/lib/src/operators/to_single_subscription.dart +++ b/lib/src/operators/to_single_subscription.dart @@ -3,12 +3,7 @@ import 'dart:async'; /// Converts a broadcast Stream into a single-subscription Stream. extension ToSingleSubscriptionStreamExtension on Stream { /// Converts a broadcast Stream into a single-subscription Stream. - /// If this [Stream] is single-subscription Stream, just return it. Stream toSingleSubscriptionStream() { - if (!isBroadcast) { - return this; - } - StreamSubscription? subscription; final controller = StreamController(sync: true); diff --git a/lib/src/state_stream/as_broadcast.dart b/lib/src/state_stream/as_broadcast.dart index 65a569b..4f7074e 100644 --- a/lib/src/state_stream/as_broadcast.dart +++ b/lib/src/state_stream/as_broadcast.dart @@ -1,7 +1,5 @@ import 'dart:async'; -import 'package:meta/meta.dart'; - import 'state_stream.dart'; import 'state_stream_mixin.dart'; @@ -15,7 +13,6 @@ extension BroadcastStateStreamExtensions on StateStream { /// This is useful for converting a single-subscription stream into a /// broadcast Stream. It's also useful for providing sync access to the latest /// emitted value. - @internal StateStream asBroadcastStateStream() => _AsBroadcastStateStream(this); } diff --git a/pubspec.yaml b/pubspec.yaml index 0e112d9..44a05fc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: rxdart_ext description: Some extension methods and classes built on top of RxDart - RxDart extension. -version: 0.2.2 +version: 0.2.3 homepage: https://github.com/hoc081098/rxdart_ext.git repository: https://github.com/hoc081098/rxdart_ext.git issue_tracker: https://github.com/hoc081098/rxdart_ext/issues diff --git a/test/operators/to_single_subscription_test.dart b/test/operators/to_single_subscription_test.dart index 3a21d23..05c663d 100644 --- a/test/operators/to_single_subscription_test.dart +++ b/test/operators/to_single_subscription_test.dart @@ -20,7 +20,7 @@ void main() { final stream = Stream.value(1); final singleSubscriptionStream = stream.toSingleSubscriptionStream(); - expect(singleSubscriptionStream, stream); + expect(singleSubscriptionStream, isNot(equals(stream))); expect(singleSubscriptionStream.isBroadcast, isFalse); singleSubscriptionStream.listen(null); diff --git a/test/single/single_or_error_test.dart b/test/single/single_or_error_test.dart index 7461b9a..1f4b305 100644 --- a/test/single/single_or_error_test.dart +++ b/test/single/single_or_error_test.dart @@ -79,11 +79,17 @@ void main() { test('from multiple data events Stream (data -> data)', () async { await singleRule( - Stream.fromIterable([1, 2, 3]).singleOrError(), + Stream.fromIterable([1, 2, 3]) + .toSingleSubscriptionStream() // dart 2.18.0: The Stream.fromIterable stream can now be listened to more than once. + .singleOrError(), buildAPIContractViolationErrorWithMessage( 'Stream contains more than one data event.'), ); - broadcastRule(Stream.fromIterable([1, 2, 3]).singleOrError(), false); + broadcastRule( + Stream.fromIterable([1, 2, 3]) + .toSingleSubscriptionStream() // dart 2.18.0: The Stream.fromIterable stream can now be listened to more than once. + .singleOrError(), + false); }); test('from both data and error events Stream (data -> error)', () async {