Created
September 15, 2019 19:21
-
-
Save dsrenesanse/aa7d9b8ae2b664789aff77e9c69aa281 to your computer and use it in GitHub Desktop.
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 Bloc { | |
final broadcaster1 = StreamController<Model1>.broadcast(); | |
final broadcaster2 = StreamController<Model2>.broadcast(); | |
Stream<Model1> get stream1 => broadcaster1.stream; | |
Stream<Model2> get stream2 => broadcaster2.stream; | |
Bloc(){ | |
subscribe(); | |
} | |
StreamSubscription _model1Subscription; | |
StreamSubscription _model2Subscription; | |
void subscribe() { | |
_model1Subscription = Store().nextSubstate((AppState state) => state.subState1).listen((state) { | |
final model = Model1(state.value); | |
broadcaster1.add(model); | |
}); | |
_model2Subscription = Store().nextSubstate((AppState state) => state.subState2).listen((state) { | |
final model = Model1(state.value); | |
broadcaster2.add(model); | |
}); | |
} | |
void dispose() { | |
_model1Subscription?.cancel(); | |
_model2Subscription?.cancel(); | |
broadcaster1.close(); | |
broadcaster2.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment