我想拥有一个BLoC类,其中两个输入(接收器)中的一个或两个都更新时,流输出需要更新。
当任何一个接收器更新/不同时,如何连接Steam触发?
import 'package:escapemodels/src/bloc/blocbase.dart';
import 'package:rxdart/rxdart.dart';
class MathAddBloc implements BlocBase {
final Sink<int> x;
final Sink<int> y;
final Stream<int> addxy;
factory MathAddBloc() {
final x = PublishSubject<int>();
final y = PublishSubject<int>();
// This is the part that I am confused about - I can figure how to trigger when one Sink/Observable changes but not when either one is updated.
final addxy = x
.distinct()
.switchMap<int>((int x) => (x + y.last))
.startWith(0);
return MathAddBloc._(x,y, addxy);
}
MathAddBloc._(this.x, this.y, this.addxy);
void dispose() {
x.close();
y.close();
}
}