Skip to content

Instantly share code, notes, and snippets.

@nhancv
Last active December 12, 2018 15:59
Show Gist options
  • Select an option

  • Save nhancv/c802d06fdd137c503a57f27e1fbc0270 to your computer and use it in GitHub Desktop.

Select an option

Save nhancv/c802d06fdd137c503a57f27e1fbc0270 to your computer and use it in GitHub Desktop.
Bloc base
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;
}
}
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