Last active
December 12, 2018 15:59
-
-
Save nhancv/c802d06fdd137c503a57f27e1fbc0270 to your computer and use it in GitHub Desktop.
Bloc base
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 'package:rxdart/rxdart.dart'; | |
| class Bloc<I, O> { | |
| var subject = BehaviorSubject<I>(); | |
| Function(Observable<I> event) business = | |
| (Observable<I> event) => Observable<O>.empty(); | |
| void push(I event) => subject.add(event); | |
| Stream<O> stream() => business(subject); | |
| void dispose() { | |
| subject.close(); | |
| } | |
| static Bloc build<I, O>(Function(Observable<I> event) business) { | |
| var blocUnit = Bloc<I, O>(); | |
| blocUnit.business = business; | |
| return blocUnit; | |
| } | |
| } |
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 'package:bflutter/bloc.dart'; | |
| import 'package:rxdart/rxdart.dart'; | |
| class BlocDefault<I> extends Bloc<I, I> { | |
| BlocDefault() { | |
| this.business = (Observable<I> event) => event; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment