From d98449407e1f170487fd0a1990d29d7b3ddeb93e Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 5 Jul 2019 07:58:23 +0200 Subject: [PATCH] Don't always include identical streams --- moor/lib/src/runtime/executor/stream_queries.dart | 5 +---- moor/pubspec.yaml | 2 +- moor/test/streams_test.dart | 15 +++++++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/moor/lib/src/runtime/executor/stream_queries.dart b/moor/lib/src/runtime/executor/stream_queries.dart index bd8f84ac..5d75c977 100644 --- a/moor/lib/src/runtime/executor/stream_queries.dart +++ b/moor/lib/src/runtime/executor/stream_queries.dart @@ -118,8 +118,6 @@ class QueryStream { final StreamQueryStore _store; StreamController _controller; - // caching the stream so that the stream getter always returns the same stream - Stream _stream; T _lastData; @@ -129,8 +127,7 @@ class QueryStream { onCancel: _onCancel, ); - return _stream ??= - _controller.stream.transform(StartWithValueTransformer(_cachedData)); + return _controller.stream.transform(StartWithValueTransformer(_cachedData)); } QueryStream(this._fetcher, this._store); diff --git a/moor/pubspec.yaml b/moor/pubspec.yaml index 5af62950..576a402b 100644 --- a/moor/pubspec.yaml +++ b/moor/pubspec.yaml @@ -1,6 +1,6 @@ name: moor description: Moor is a safe and reactive persistence library for Dart applications -version: 1.5.1 +version: 1.5.1+1 repository: https://github.com/simolus3/moor homepage: https://moor.simonbinder.eu/ issue_tracker: https://github.com/simolus3/moor/issues diff --git a/moor/test/streams_test.dart b/moor/test/streams_test.dart index 3771f97f..844e9518 100644 --- a/moor/test/streams_test.dart +++ b/moor/test/streams_test.dart @@ -43,11 +43,18 @@ void main() { verify(executor.runSelect(any, any)).called(2); }); - test('equal statements yield identical streams', () { - final firstStream = (db.select(db.users).watch())..listen((_) {}); - final secondStream = (db.select(db.users).watch())..listen((_) {}); + test('streams emit cached data when a new listener attaches', () async { + when(executor.runSelect(any, any)).thenAnswer((_) => Future.value([])); - expect(identical(firstStream, secondStream), true); + final first = (db.select(db.users).watch()); + expect(first, emits(isEmpty)); + + clearInteractions(executor); + + final second = (db.select(db.users).watch()); + expect(second, emits(isEmpty)); + + verifyZeroInteractions(executor); }); group('stream keys', () {