Try class
An alias for Call effect. It makes try/catch/finally code blocks more readable.
It is useful to catch errors during effect resolve and instruct finally blocks. It is not possible to catch effect resolve errors by standart try/catch blocks. Try effect must be used to handle those errors and finally code blocks.
Example
In the following example, there is a simple checkout saga function.
It tries to checkout the cart. If fails it dispatches a CheckoutFailure
action.
import 'package:redux_saga/redux_saga.dart';
import 'Api.dart';
//...
checkout() sync* {
yield Try(() sync* {
var cart = Result<Cart>();
yield Select(selector: getCart, result: cart);
yield Call(buyProductsAPI, args: [cart.value]);
yield Put(CheckoutSuccess(cart.value));
}, Catch: (e, s) sync* {
yield Put(CheckoutFailure(error));
});
}
- Inheritance
Constructors
Properties
- args → List?
-
Arguments of the function to call
finalinherited
- Catch → Function?
-
A Generator function or a normal function to invoke for uncaught errors.
finalinherited
- Finally → Function?
-
A Generator function or a normal function to invoke in any case after call.
finalinherited
- fn → Function
-
A Generator function or a normal function to call.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String?
-
Meta name of function
finalinherited
-
namedArgs
→ Map<
Symbol, dynamic> ? -
Named arguments of the function to call
finalinherited
- result ↔ Result?
-
Result after effect is resolved.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getDefinition(
) → Map< String, dynamic> -
Returns all properties of effect as a dictionary object
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited