mirror of https://github.com/AMT-Cheif/drift.git
Don't always include identical streams
This commit is contained in:
parent
01db5e2afc
commit
d98449407e
|
@ -118,8 +118,6 @@ class QueryStream<T> {
|
|||
final StreamQueryStore _store;
|
||||
|
||||
StreamController<T> _controller;
|
||||
// caching the stream so that the stream getter always returns the same stream
|
||||
Stream<T> _stream;
|
||||
|
||||
T _lastData;
|
||||
|
||||
|
@ -129,8 +127,7 @@ class QueryStream<T> {
|
|||
onCancel: _onCancel,
|
||||
);
|
||||
|
||||
return _stream ??=
|
||||
_controller.stream.transform(StartWithValueTransformer(_cachedData));
|
||||
return _controller.stream.transform(StartWithValueTransformer(_cachedData));
|
||||
}
|
||||
|
||||
QueryStream(this._fetcher, this._store);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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', () {
|
||||
|
|
Loading…
Reference in New Issue