-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85f2e49
Showing
14 changed files
with
849 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
.atom/ | ||
.dart_tool/ | ||
.idea | ||
.packages | ||
.pub/ | ||
packages |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
// Verwendet IntelliSense zum Ermitteln möglicher Attribute. | ||
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen. | ||
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Flutter", | ||
"request": "launch", | ||
"type": "dart" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## [0.0.1] - TODO: Add release date. | ||
|
||
* TODO: Describe initial release. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: Add your license here. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# rx_command | ||
|
||
A new flutter package project. | ||
|
||
## Getting Started | ||
|
||
For help getting started with Flutter, view our online [documentation](https://flutter.io/). | ||
|
||
For help on editing package code, view the [documentation](https://flutter.io/developing-packages/). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This is a generated file; do not edit or check into version control. | ||
FLUTTER_ROOT=C:\Entwicklung\Flutter | ||
FLUTTER_APPLICATION_PATH=c:\Entwicklung\FlutterApps\packages\rx_command | ||
FLUTTER_TARGET=lib/main.dart | ||
FLUTTER_BUILD_MODE=debug | ||
FLUTTER_BUILD_DIR=build | ||
SYMROOT=${SOURCE_ROOT}/../build\ios | ||
FLUTTER_FRAMEWORK_DIR=C:\Entwicklung\Flutter\bin\cache\artifacts\engine\ios |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Generated file. Do not edit. | ||
// | ||
|
||
#ifndef GeneratedPluginRegistrant_h | ||
#define GeneratedPluginRegistrant_h | ||
|
||
#import <Flutter/Flutter.h> | ||
|
||
@interface GeneratedPluginRegistrant : NSObject | ||
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry; | ||
@end | ||
|
||
#endif /* GeneratedPluginRegistrant_h */ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Generated file. Do not edit. | ||
// | ||
|
||
#import "GeneratedPluginRegistrant.h" | ||
|
||
@implementation GeneratedPluginRegistrant | ||
|
||
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry { | ||
} | ||
|
||
@end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
library rx_command; | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:rxdart/rxdart.dart'; | ||
|
||
/* | ||
typedef TResult Func<TParam, TResult>(TParam param); | ||
abstract class RxCommandFactory | ||
{ | ||
static RxCommand<TParam, TResult> createSync<TParam, TResult>(Func<TParam, TResult> func) | ||
{ | ||
return new RxCommandSync<TParam,TResult>(func); | ||
} | ||
} | ||
*/ | ||
|
||
typedef void Action(); | ||
typedef void Action1<TParam>(TParam param); | ||
|
||
|
||
typedef TResult Func<TResult>(); | ||
typedef TResult Func1<TParam, TResult>(TParam param); | ||
|
||
typedef Future AsyncAction(); | ||
typedef Future AsyncAction1<TParam>(TParam param); | ||
|
||
|
||
typedef Future<TResult> AsyncFunc<TResult>(); | ||
typedef Future<TResult> AsyncFunc1<TParam, TResult>(TParam param); | ||
|
||
|
||
abstract class RxCommandFactory | ||
{ | ||
|
||
static RxCommand<Unit, Unit> createSync(Action action) | ||
{ | ||
return new RxCommandSync<Unit,Unit>((_) {action(); return Unit.Default;}); | ||
} | ||
|
||
static RxCommand<TParam, Unit> createSync1<TParam>(Action1<TParam> action) | ||
{ | ||
return new RxCommandSync<TParam,Unit>((x) {action(x); return Unit.Default;}); | ||
} | ||
|
||
static RxCommand<Unit, TResult> createSync2<TResult>(Func<TResult> func) | ||
{ | ||
return new RxCommandSync<Unit,TResult>((_) => func()); | ||
} | ||
|
||
static RxCommand<TParam, TResult> createSync4<TParam, TResult>(Func1<TParam,TResult> func) | ||
{ | ||
return new RxCommandSync<TParam,TResult>((x) => func(x)); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
abstract class RxCommand<TParam, TRESULT> | ||
{ | ||
|
||
void execute([TParam param]); | ||
|
||
Observable<TRESULT> get results => _resultsSubject.observable; | ||
BehaviorSubject<TRESULT> _resultsSubject = new BehaviorSubject<TRESULT>(); | ||
|
||
|
||
Observable<bool> get isExecuting => _isExecutingSubject.observable.startWith(false).distinct(); | ||
Observable<bool> canExecute; | ||
Observable<Exception> get thrownExceptions => _thrownExceptionsSubject.observable; | ||
|
||
ReplaySubject<bool> _isExecutingSubject = new ReplaySubject<bool>(maxSize: 1); | ||
ReplaySubject<bool> _canExcuteubject = new ReplaySubject<bool>(maxSize: 1); | ||
ReplaySubject<Exception> _thrownExceptionsSubject = new ReplaySubject<Exception>(maxSize: 1); | ||
|
||
} | ||
|
||
|
||
class RxCommandSync<TParam, TResult> extends RxCommand<TParam, TResult> | ||
{ | ||
|
||
|
||
Func1<TParam, TResult> _func; | ||
|
||
RxCommandSync(Func1<TParam, TResult> func, [Observable<bool> canExecute] ) | ||
{ | ||
|
||
_func = func; | ||
|
||
var canExecuteParam = canExecute == null ? new Observable.just(true) | ||
: canExecute.handleError((error) | ||
{ | ||
if (error is Exception) | ||
{ | ||
_thrownExceptionsSubject.add(error); | ||
} | ||
return false; | ||
}) | ||
.startWith(false); | ||
|
||
|
||
this.canExecute = new Observable(Observable | ||
.combineLatest2(isExecuting, canExecuteParam, (isEx, canEx) => canEx && !isEx) | ||
.distinct().asBroadcastStream()); | ||
|
||
} | ||
|
||
@override | ||
void execute([TParam param]) | ||
{ | ||
canExecute | ||
.where( (can) => can == true) | ||
.doOnEach((_){ | ||
|
||
_isExecutingSubject.add(true); | ||
var result = _func(param); | ||
_isExecutingSubject.add(false); | ||
|
||
if (TResult is Unit ) | ||
{ | ||
_resultsSubject.add(Unit.Default as TResult); | ||
} | ||
_resultsSubject.add(result); | ||
|
||
}) | ||
.handleError((error) | ||
{ | ||
if (error is Exception) | ||
{ | ||
_thrownExceptionsSubject.add(error); | ||
} | ||
print(error.toString()); | ||
|
||
}) | ||
.first; | ||
|
||
} | ||
} | ||
|
||
/* | ||
class RxCommandAsync<TParam, TResult> extends RxCommand<TParam, TResult> | ||
{ | ||
AsyncFunc1<TParam, TResult> _func; | ||
RxCommandSync(AsyncFunc1<TParam, TResult> func, [Observable<bool> canExecute] ) | ||
{ | ||
_func = func; | ||
var canExecuteParam = canExecute == null ? new Observable.just(true) | ||
: canExecute.handleError((error) | ||
{ | ||
if (error is Exception) | ||
{ | ||
_thrownExceptionsSubject.add(error); | ||
} | ||
return false; | ||
}) | ||
.startWith(false); | ||
this.canExecute = new Observable(Observable | ||
.combineLatest2(isExecuting, canExecuteParam, (isEx, canEx) => canEx && !isEx) | ||
.distinct().asBroadcastStream()); | ||
} | ||
@override | ||
void execute([TParam param]) | ||
{ | ||
canExecute | ||
.where( (can) => can == true) | ||
.doOnEach((_){ | ||
_isExecutingSubject.add(true); | ||
var result = _func(param); | ||
_isExecutingSubject.add(false); | ||
if (TResult is Unit ) | ||
{ | ||
_resultsSubject.add(Unit.Default as TResult); | ||
} | ||
_resultsSubject.add(result); | ||
}) | ||
.handleError((error) | ||
{ | ||
if (error is Exception) | ||
{ | ||
_thrownExceptionsSubject.add(error); | ||
} | ||
print(error.toString()); | ||
}) | ||
.first; | ||
} | ||
} | ||
*/ | ||
|
||
/// If you don't want to pass one of the generic parameters e.g. if you passed function has no parameter, just use Unit as Type | ||
class Unit | ||
{ | ||
static Unit get Default => new Unit(); | ||
|
||
bool operator == (o) => o is Unit; | ||
|
||
} | ||
|
||
|
Oops, something went wrong.