Skip to main content

Effect


Introduction

FetchEffect is basically a set of reducers reacting to the request lifecycle. We can assign it to the builder and it's effectKey has to be the same as command's effect key so we can match it. It's strength lays in the possibilities of cooperation with the persistent queues. Imagine that we always want to trigger some logic when the request is successful, but we also use the persistent storages to save or ongoing requests. When our app gets relaunched there is no possibility to persist functions and logic - so the effect comes with the solution. We can assign it on builder creation so it will instantly match all the ongoing requests from previous sessions.


Purpose

  • Persistence of the request side-effects
  • Lifecycle manipulation and possibility to hook in

EffectKey

Key needed to match the Effect with the command where it's stored. It is automatically generated like other keys in the command, but we can set up custom values for easier usage and matching.


Parameters

Configuration options

Name Type Description
effectKey string It should match effectKey on the command for which given effect should be triggered.
onError (response: ClientResponseErrorType<ExtractError<T>>, command: CommandInstance) => void Callback that will be executed when response is failed
onFinished (response: ClientResponseType<ResponseType, ExtractError<T>>, command: CommandInstance) => void Callback that will be executed when response is finished
onStart (command: CommandInstance) => void Callback that will be executed when request starts
onSuccess (response: ClientResponseSuccessType<ResponseType>, command: CommandInstance) => void Callback that will be executed when response is successful
onTrigger (command: CommandInstance) => void Callback that will be executed when request gets triggered