-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(single): add
Single.asNullable()
operator
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'single.dart'; | ||
|
||
/// Adapt this `Single<T>` to be a `Single<T?>`. | ||
extension AsNullableSingleExtension<T extends Object> on Single<T> { | ||
/// Adapt this `Single<T>` to be a `Single<T?>`. | ||
@pragma('vm:prefer-inline') | ||
@pragma('dart2js:tryInline') | ||
Single<T?> asNullable() => this; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:rxdart_ext/rxdart_ext.dart'; | ||
import 'package:test/expect.dart'; | ||
import 'package:test/scaffolding.dart'; | ||
|
||
void main() { | ||
group('Single.asNullable', () { | ||
test('works', () { | ||
final single = Single.value(1); | ||
final asNullable = single.asNullable(); | ||
|
||
expect(asNullable, isA<Single<int?>>()); | ||
expect(asNullable, same(single)); | ||
}); | ||
|
||
test('asNullable with publishState', () async { | ||
final single = Single.value(1); | ||
final stateStream = single.asNullable().publishState(null); | ||
|
||
expect(stateStream, isA<StateConnectableStream<int?>>()); | ||
expect(stateStream.value, null); | ||
|
||
scheduleMicrotask(() => stateStream.connect()); | ||
await expectLater(stateStream, emitsInOrder([1])); | ||
}); | ||
|
||
test('asNullable with publishValueSeeded', () async { | ||
final single = Single.value(1); | ||
final valueStream = single.asNullable().publishValueSeeded(null); | ||
|
||
expect(valueStream, isA<ValueConnectableStream<int?>>()); | ||
expect(valueStream.value, null); | ||
|
||
scheduleMicrotask(() => valueStream.connect()); | ||
await expectLater(valueStream, emitsInOrder([null, 1])); | ||
}); | ||
}); | ||
} |