Created
August 16, 2023 16:53
-
-
Save irvine5k/173112b07787e416d5cedfd0f5448eda to your computer and use it in GitHub Desktop.
examplepub/sub
This file contains hidden or 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
import 'dart:async'; | |
void main() { | |
X.eventStream.stream.listen(print); | |
Y.eventStream.stream.listen(print); | |
Main.eventStream.add(XEvent("came from X")); | |
} | |
class Event {} | |
class XEvent extends Event{ | |
XEvent(this.field); | |
final String field; | |
} | |
class YEvent extends Event{ | |
YEvent(this.field); | |
final String field; | |
@override | |
String toString() => "YEvent(field: $field)"; | |
} | |
class Main { | |
static final eventStream = StreamController<Event>()..stream.forEach( | |
(e) { | |
if(e is XEvent) Y.eventStream.add(YEvent(e.field)); | |
}); | |
} | |
class X { | |
static final eventStream = StreamController<Event>(); | |
} | |
class Y { | |
static final eventStream = StreamController<Event>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment