diff --git a/packages/neon_framework/lib/src/utils/stream_listenable.dart b/packages/neon_framework/lib/src/utils/stream_listenable.dart deleted file mode 100644 index 5c5a11b00cd..00000000000 --- a/packages/neon_framework/lib/src/utils/stream_listenable.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'dart:async'; - -import 'package:flutter/foundation.dart'; -import 'package:rxdart/rxdart.dart'; - -/// Listenable Stream -/// -/// A class that implements [Listenable] for a stream. -/// Objects need to be manually disposed. -class StreamListenable extends ChangeNotifier { - /// Listenable Stream - StreamListenable(Stream stream) { - if (stream is! BehaviorSubject) { - notifyListeners(); - } - - _addSubscription(stream); - } - - /// Listenable for multiple Streams. - /// - /// Notifies it's listeners on every event emitted by any of the streams. - StreamListenable.multiListenable(Iterable> streams) { - streams.forEach(_addSubscription); - } - - void _addSubscription(Stream stream) { - _subscriptions.add( - stream.asBroadcastStream().listen((_) { - notifyListeners(); - }), - ); - } - - final List> _subscriptions = []; - - @override - void dispose() { - for (final subscription in _subscriptions) { - unawaited(subscription.cancel()); - } - - super.dispose(); - } -} diff --git a/packages/neon_framework/test/stream_listenable_test.dart b/packages/neon_framework/test/stream_listenable_test.dart deleted file mode 100644 index 9621caea81b..00000000000 --- a/packages/neon_framework/test/stream_listenable_test.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'dart:async'; - -import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:neon_framework/src/utils/stream_listenable.dart'; -import 'package:neon_framework/testing.dart'; -import 'package:rxdart/rxdart.dart'; - -void main() { - group('StreamListenable', () { - test('stream', () async { - final stream = BehaviorSubject(); - final callback = MockCallbackFunction(); - - StreamListenable(stream).addListener(callback.call); - - verifyNever(callback.call); - - stream.value = true; - await Future.delayed(const Duration(milliseconds: 100)); - verify(callback.call).called(1); - - stream.value = true; - await Future.delayed(const Duration(milliseconds: 100)); - verify(callback.call).called(1); - - unawaited(stream.close()); - }); - - test('multiStream', () async { - final stream = BehaviorSubject(); - final stream2 = BehaviorSubject(); - final callback = MockCallbackFunction(); - - StreamListenable.multiListenable({ - stream, - stream2, - }).addListener(callback.call); - - verifyNever(callback.call); - - stream.value = true; - await Future.delayed(const Duration(milliseconds: 100)); - verify(callback.call).called(1); - - stream2.value = 3; - await Future.delayed(const Duration(milliseconds: 100)); - verify(callback.call).called(1); - - unawaited(stream.close()); - unawaited(stream2.close()); - }); - - test('dispose', () { - final controller = StreamController(); - - final listenable = StreamListenable(controller.stream); - - expect(controller.hasListener, true); - - listenable.dispose(); - - expect(controller.isClosed, false); - unawaited(controller.close()); - }); - }); -}