Effect
Introduction
FetchEffect
is basically a set of reducers reacting to the request lifecycle. You can assign it to the Builder;
its effectKey
has to be the same as the command's effect key so you can match it.
The strength of FetchEffect
lies in cooperation options with persistent queues. Imagine that you always want to
trigger some logic when the request is successful, but you must also use persistent storage to save ongoing requests.
But when the app gets relaunched, there is no way to persist functions and logic. Here, the effect is the solution. We
can assign it on Builder creation so that it will instantly match all ongoing requests from previous sessions.
Purpose
- Persists request side-effects
- Manipulates the lifecycle and allows hooking in
EffectKey
A key needed to match the Effect with the command where it's stored. This is automatically generated (like other keys in the command), but you can set up custom values for easier usage and matching.
Parameters
Configuration options
{
effectKey: string;
onError: (response: ClientResponseErrorType<ExtractError<T>>, command: CommandInstance) => void;
onFinished: (response: ClientResponseType<ResponseType, ExtractError<T>>, command: CommandInstance) => void;
onStart: (command: CommandInstance) => void;
onSuccess: (response: ClientResponseSuccessType<ResponseType>, command: CommandInstance) => void;
onTrigger: (command: CommandInstance) => void;
}