Created
April 9, 2021 08:55
-
-
Save xsahil03x/b4bf34ccd19227800774c641d6cef90f to your computer and use it in GitHub Desktop.
Streamable
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
class Streamable<T> extends Subject<T> implements ValueStream<T> { | |
Streamable(this._subject) : super(_subject, _subject); | |
final BehaviorSubject<T> _subject; | |
@override | |
Subject<R> createForwardingSubject<R>({ | |
void Function()? onListen, | |
void Function()? onCancel, | |
bool sync = false, | |
}) => | |
_subject.createForwardingSubject( | |
onListen: onListen, | |
onCancel: onCancel, | |
sync: sync, | |
); | |
@override | |
ErrorAndStackTrace? get errorAndStackTrace => _subject.errorAndStackTrace; | |
@override | |
ValueWrapper<T>? get valueWrapper => _subject.valueWrapper; | |
} | |
class GeneralClass<T> extends Streamable<T> { | |
GeneralClass() : super(BehaviorSubject<T>()); | |
} | |
void main() { | |
test('GeneralClassTest', () async { | |
final general2 = GeneralClass<String>(); | |
expect(general2, isA<Stream>()); | |
// should emit haha, hoho, hehe | |
expectLater( | |
general2, | |
emitsInOrder(['haha', 'hoho', 'hehe']), | |
); | |
general2 | |
..add('haha') // Adding haha | |
..add('hoho') // Adding hoho | |
..add('hehe'); // Adding hehe | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment