Don't always include identical streams

This commit is contained in:
Simon Binder 2019-07-05 07:58:23 +02:00
parent 01db5e2afc
commit d98449407e
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 13 additions and 9 deletions

View File

@ -118,8 +118,6 @@ class QueryStream<T> {
final StreamQueryStore _store; final StreamQueryStore _store;
StreamController<T> _controller; StreamController<T> _controller;
// caching the stream so that the stream getter always returns the same stream
Stream<T> _stream;
T _lastData; T _lastData;
@ -129,8 +127,7 @@ class QueryStream<T> {
onCancel: _onCancel, onCancel: _onCancel,
); );
return _stream ??= return _controller.stream.transform(StartWithValueTransformer(_cachedData));
_controller.stream.transform(StartWithValueTransformer(_cachedData));
} }
QueryStream(this._fetcher, this._store); QueryStream(this._fetcher, this._store);

View File

@ -1,6 +1,6 @@
name: moor name: moor
description: Moor is a safe and reactive persistence library for Dart applications 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 repository: https://github.com/simolus3/moor
homepage: https://moor.simonbinder.eu/ homepage: https://moor.simonbinder.eu/
issue_tracker: https://github.com/simolus3/moor/issues issue_tracker: https://github.com/simolus3/moor/issues

View File

@ -43,11 +43,18 @@ void main() {
verify(executor.runSelect(any, any)).called(2); verify(executor.runSelect(any, any)).called(2);
}); });
test('equal statements yield identical streams', () { test('streams emit cached data when a new listener attaches', () async {
final firstStream = (db.select(db.users).watch())..listen((_) {}); when(executor.runSelect(any, any)).thenAnswer((_) => Future.value([]));
final secondStream = (db.select(db.users).watch())..listen((_) {});
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', () { group('stream keys', () {