Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Created April 9, 2021 08:55
Show Gist options
  • Save xsahil03x/b4bf34ccd19227800774c641d6cef90f to your computer and use it in GitHub Desktop.
Save xsahil03x/b4bf34ccd19227800774c641d6cef90f to your computer and use it in GitHub Desktop.
Streamable
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