From 3d6f6c858b0cd02a4f1ae370e5ed2286c43c68c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petrus=20Nguy=E1=BB=85n=20Th=C3=A1i=20H=E1=BB=8Dc?= Date: Mon, 2 Sep 2024 20:08:16 +0700 Subject: [PATCH] add class modifiers (#113) --- .../not_replay_value_connectable_stream.dart | 5 +++-- lib/src/not_replay_value_stream/not_replay_value_stream.dart | 2 +- lib/src/not_replay_value_stream/stream_event.dart | 2 +- lib/src/not_replay_value_stream/value_stream_controller.dart | 2 +- lib/src/not_replay_value_stream/value_subject.dart | 2 +- lib/src/operators/done_on_error.dart | 2 +- lib/src/operators/ignore.dart | 2 +- lib/src/operators/void.dart | 2 +- lib/src/single/on_error_resume.dart | 4 ++-- lib/src/single/single.dart | 4 ++-- lib/src/state_stream/state_connectable_stream.dart | 4 ++-- lib/src/state_stream/state_stream.dart | 4 ++-- lib/src/state_stream/state_subject.dart | 2 +- lib/src/utils/default_sink.dart | 2 +- lib/src/utils/stream_sink_wrapper.dart | 2 +- 15 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/src/not_replay_value_stream/not_replay_value_connectable_stream.dart b/lib/src/not_replay_value_stream/not_replay_value_connectable_stream.dart index 0afa4f3..799b3ef 100644 --- a/lib/src/not_replay_value_stream/not_replay_value_connectable_stream.dart +++ b/lib/src/not_replay_value_stream/not_replay_value_connectable_stream.dart @@ -13,8 +13,9 @@ import 'value_subject.dart'; /// a broadcast [Stream], and provides synchronous access to the latest emitted value. /// /// See [NotReplayValueStream]. -class NotReplayValueConnectableStream extends AbstractConnectableStream, NotReplayValueStream> +final class NotReplayValueConnectableStream + extends AbstractConnectableStream, + NotReplayValueStream> with NotReplayValueStreamMixin implements NotReplayValueStream { final ValueSubject _subject; diff --git a/lib/src/not_replay_value_stream/not_replay_value_stream.dart b/lib/src/not_replay_value_stream/not_replay_value_stream.dart index 1d57afa..0d48298 100644 --- a/lib/src/not_replay_value_stream/not_replay_value_stream.dart +++ b/lib/src/not_replay_value_stream/not_replay_value_stream.dart @@ -3,4 +3,4 @@ import 'package:rxdart/rxdart.dart' show ValueStream; /// The marker interface for [ValueStream] classes /// that provide synchronous access to the last emitted item, /// but do not replay the latest value. -abstract class NotReplayValueStream extends ValueStream {} +abstract interface class NotReplayValueStream implements ValueStream {} diff --git a/lib/src/not_replay_value_stream/stream_event.dart b/lib/src/not_replay_value_stream/stream_event.dart index 2d4a430..790ce14 100644 --- a/lib/src/not_replay_value_stream/stream_event.dart +++ b/lib/src/not_replay_value_stream/stream_event.dart @@ -3,7 +3,7 @@ import 'package:rxdart/rxdart.dart' show ErrorAndStackTrace; /// Class that holds latest value and lasted error emitted from Stream. @internal -class StreamEvent { +final class StreamEvent { T _value; ErrorAndStackTrace? _errorAndStacktrace; var _lastEventIsData = false; diff --git a/lib/src/not_replay_value_stream/value_stream_controller.dart b/lib/src/not_replay_value_stream/value_stream_controller.dart index e3d4cc8..7cefa15 100644 --- a/lib/src/not_replay_value_stream/value_stream_controller.dart +++ b/lib/src/not_replay_value_stream/value_stream_controller.dart @@ -21,7 +21,7 @@ import 'stream_event.dart'; /// it has subscribers or not, as well as getting a callback when either of /// these change. @sealed -class ValueStreamController implements StreamController { +final class ValueStreamController implements StreamController { final StreamController _delegate; final StreamEvent _dataOrError; diff --git a/lib/src/not_replay_value_stream/value_subject.dart b/lib/src/not_replay_value_stream/value_subject.dart index 5c04cd3..a89037b 100644 --- a/lib/src/not_replay_value_stream/value_subject.dart +++ b/lib/src/not_replay_value_stream/value_subject.dart @@ -33,7 +33,7 @@ import 'stream_event.dart'; /// subject.add(2); /// subject.close(); @sealed -class ValueSubject extends Subject +final class ValueSubject extends Subject with NotReplayValueStreamMixin implements NotReplayValueStream { final StreamEvent _dataOrError; diff --git a/lib/src/operators/done_on_error.dart b/lib/src/operators/done_on_error.dart index 22da4af..e58671c 100644 --- a/lib/src/operators/done_on_error.dart +++ b/lib/src/operators/done_on_error.dart @@ -2,7 +2,7 @@ import 'dart:async'; import '../utils/default_sink.dart'; -class _DoneOnErrorSink extends BaseEventSink { +final class _DoneOnErrorSink extends BaseEventSink { final bool Function(Object e, StackTrace s) predicate; _DoneOnErrorSink(super.sink, this.predicate); diff --git a/lib/src/operators/ignore.dart b/lib/src/operators/ignore.dart index c2d3441..c76ac9d 100644 --- a/lib/src/operators/ignore.dart +++ b/lib/src/operators/ignore.dart @@ -2,7 +2,7 @@ import 'dart:async'; import '../utils/default_sink.dart'; -class _IgnoreErrorsEventSink extends BaseEventSink { +final class _IgnoreErrorsEventSink extends BaseEventSink { _IgnoreErrorsEventSink(super.sink); @override diff --git a/lib/src/operators/void.dart b/lib/src/operators/void.dart index fec073f..db7a7cf 100644 --- a/lib/src/operators/void.dart +++ b/lib/src/operators/void.dart @@ -2,7 +2,7 @@ import 'dart:async'; import '../utils/default_sink.dart'; -class _AsVoidStreamSink extends BaseEventSink { +final class _AsVoidStreamSink extends BaseEventSink { _AsVoidStreamSink(super.sink); @override diff --git a/lib/src/single/on_error_resume.dart b/lib/src/single/on_error_resume.dart index 4048f36..3d21c0b 100644 --- a/lib/src/single/on_error_resume.dart +++ b/lib/src/single/on_error_resume.dart @@ -3,7 +3,7 @@ import 'dart:async'; import '../utils/default_sink.dart'; import 'single.dart'; -class _OnErrorReturnSingleSink extends BaseEventSink { +final class _OnErrorReturnSingleSink extends BaseEventSink { final T returnValue; _OnErrorReturnSingleSink(super.sink, this.returnValue); @@ -16,7 +16,7 @@ class _OnErrorReturnSingleSink extends BaseEventSink { sink.add(returnValue); } -class _OnErrorReturnWithSingleSink extends BaseEventSink { +final class _OnErrorReturnWithSingleSink extends BaseEventSink { final T Function(Object error, StackTrace stackTrace) itemSupplier; _OnErrorReturnWithSingleSink(super.sink, this.itemSupplier); diff --git a/lib/src/single/single.dart b/lib/src/single/single.dart index 77f30ca..c10be79 100644 --- a/lib/src/single/single.dart +++ b/lib/src/single/single.dart @@ -18,7 +18,7 @@ import 'internal.dart'; /// error done /// ``` @sealed -class Single extends StreamView { +final class Single extends StreamView { /// Underline source Stream. final Stream _stream; @@ -179,7 +179,7 @@ class Single extends StreamView { Single.safe(_stream.asyncMap(convert)); } -class _SingleOrErrorStreamSink extends BaseEventSink { +final class _SingleOrErrorStreamSink extends BaseEventSink { var value = _null; ErrorAndStackTrace? error; diff --git a/lib/src/state_stream/state_connectable_stream.dart b/lib/src/state_stream/state_connectable_stream.dart index b074438..2840726 100644 --- a/lib/src/state_stream/state_connectable_stream.dart +++ b/lib/src/state_stream/state_connectable_stream.dart @@ -12,7 +12,7 @@ import 'state_subject.dart'; /// /// This is a combination of [ConnectableStream], [ValueStream], [ValueSubject] and [Stream.distinct]. @sealed -abstract class StateConnectableStream extends ConnectableStream +sealed class StateConnectableStream extends ConnectableStream implements StateStream { /// Constructs a [Stream] which only begins emitting events when /// the [connect] method is called, this [Stream] acts like a @@ -44,7 +44,7 @@ abstract class StateConnectableStream extends ConnectableStream StateStream refCount(); } -class _StateConnectableStream +final class _StateConnectableStream extends AbstractConnectableStream, StateStream> with StateStreamMixin implements StateConnectableStream { diff --git a/lib/src/state_stream/state_stream.dart b/lib/src/state_stream/state_stream.dart index 2288b68..88cf5bf 100644 --- a/lib/src/state_stream/state_stream.dart +++ b/lib/src/state_stream/state_stream.dart @@ -17,7 +17,7 @@ export '../utils/equality.dart'; /// /// This [Stream] do **not replay** the latest value, see [NotReplayValueStream]. /// This [Stream] always has **no error**. -abstract class StateStream extends NotReplayValueStream { +abstract interface class StateStream implements NotReplayValueStream { /// Determined equality between previous data event and current data event. Equality get equals; @@ -56,7 +56,7 @@ abstract class StateStream extends NotReplayValueStream { } /// A mutable [StateStream] that provides a setter for [value]. -abstract class MutableStateStream implements StateStream { +abstract interface class MutableStateStream implements StateStream { /// Set the [value] of this [MutableStateStream]. /// Also emits the [newValue] to all listeners /// if it is not equal to the current value. diff --git a/lib/src/state_stream/state_subject.dart b/lib/src/state_stream/state_subject.dart index 07978dc..92b9b8e 100644 --- a/lib/src/state_stream/state_subject.dart +++ b/lib/src/state_stream/state_subject.dart @@ -50,7 +50,7 @@ import 'state_stream_mixin.dart'; /// subject.add(3); /// subject.close(); @sealed -class StateSubject extends Subject +final class StateSubject extends Subject with StateStreamMixin implements StateStream, MutableStateStream { T _value; diff --git a/lib/src/utils/default_sink.dart b/lib/src/utils/default_sink.dart index e303007..becffcc 100644 --- a/lib/src/utils/default_sink.dart +++ b/lib/src/utils/default_sink.dart @@ -21,7 +21,7 @@ mixin ForwardingSinkMixin implements ForwardingSink { } /// This [EventSink] class implements all [EventSink] members except [add]. -abstract class BaseEventSink implements EventSink { +abstract base class BaseEventSink implements EventSink { /// The output sink. @protected final EventSink sink; diff --git a/lib/src/utils/stream_sink_wrapper.dart b/lib/src/utils/stream_sink_wrapper.dart index 416b10d..91477ad 100644 --- a/lib/src/utils/stream_sink_wrapper.dart +++ b/lib/src/utils/stream_sink_wrapper.dart @@ -4,7 +4,7 @@ import 'package:meta/meta.dart'; /// A class that exposes only the [StreamSink] interface of an object. @internal -class StreamSinkWrapper implements StreamSink { +final class StreamSinkWrapper implements StreamSink { final StreamSink _target; /// Creates a [StreamSinkWrapper] that wraps [target].