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;
|
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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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', () {
|
||||||
|
|
Loading…
Reference in New Issue