Closed aliyoge closed 4 years ago
Update:
I solved this problem in this way:
Stream<dynamic> setEventItemsEffect(
Stream<dynamic> actions, EpicStore<AppState> store) {
return actions
.whereType<SetEventItemAction>()
.asyncMap((action) => handleEventItems(action.task)
.then<dynamic>((res) => UpdateTaskAction(task: action.task)
.catchError((_) => SetEventItemFailAction(task: action.task))
);
}
Is there a better way? @brianegan
Hey there -- Futures can only return one type of Object. In your original example, Dart is inferring that you want to create a Future<UpdateTaskAction>
, but if an error occurs you're trying to return a different type: SetEventItemFailAction
. The future cannot do that -- it can only return one type!
Therefore, you have two options:
Object
or dynamic
as a default parent interface -- which is what Redux does, and what you've done!Therefore, the way you've solved it is completely appropriate, but hope this explanation helps you understand why :)
Hey there -- Futures can only return one type of Object. In your original example, Dart is inferring that you want to create a
Future<UpdateTaskAction>
, but if an error occurs you're trying to return a different type:SetEventItemFailAction
. The future cannot do that -- it can only return one type!Therefore, you have two options:
- Make each of these action classes implement a common parent interface
- Use
Object
ordynamic
as a default parent interface -- which is what Redux does, and what you've done!Therefore, the way you've solved it is completely appropriate, but hope this explanation helps you understand why :)
Thank you very much for your explanation.
Here is my code:
When to
catchError
, this code get errorUnhandled Exception: type 'SetEventItemFailAction' is not a subtype of type 'FutureOr<UpdateTaskAction>'
When I change code to this according to #30 :
The error is gone, but the type goes like this.
Action: Instance of '_ControllerStream<dynamic>'
or:
The type goes like this.
Action: Instance of '_ControllerStream<dynamic>'