mpv 0.1.0+2 mpv: ^0.1.0+2 copied to clipboard
mpv like mvp, but for flutter, and has mechanism for unsubscribing from the result from future or stream
MVP #
As in MVP there is Presenter and View
Example #
Presenter implements logic and returns the result through subject
class SamplePresenter extends Presenter<SampleView> {
SamplePresenter(SampleView view) : super(view) {
view.counter.add(CounterState(count));
}
}
mixin SampleView implements View {
final counter = BehaviorSubject<CounterState>();
@override
close() {
counter.close();
}
}
state implements view and has presenter
class _SampleWidgetState
extends StateWithPresenter<SampleWidget, SamplePresenter> with SampleView {
@override
SamplePresenter createPresenter() {
return SamplePresenter(this);
}
}
There is also a mechanism for unsubscribing from the result from future or stream
Example Cancelable #
Future future;
CancelableFuture cancelableFuture = CancelableFuture(future);
cancelableFuture.then((value) {
print(value);
});
cancelableFuture.cancelable.cancel();
The presenter has futures in map, that will be canceled if the view is closed or if future with the same key
You can add your requests in this map using the method cancelable
cancelable(cancelKey,Future.delayed(Duration(seconds: 1)))
.then((_) {})