You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.
SideEffectors are objects or systems that react to actions, but are allowed to produce side effects. Unlike reducers, SideEffectors cannot modify state directly, however they can dispatch actions.
SideEffectors should have two method "hooks" into the Store:
PreEffect: called immediately when an action is dispatched, before reduction.
PostEffect: called after reduction.
Each hook is passed the action that was dispatched, the current state, and an IActionDispatcher.
Architecturally, SideEffectors reduce burden on components by being responsible for side effects, especially asynchrony. For example, a component doesn't need to care about the details of requesting a remote resource, it just needs to care about displaying it.
Here's an example flow for the use case where clicking a button should load a remote image and display it in a component:
Button is clicked and dispatches a ButtonClicked action.
A SideEffector hooks on the ButtonClicked action and initiates a web request for the resource.
Reducer takes the ButtonClicked action and updates state to indicate that the image component is in the 'loading' state.
The image component observes the 'loading' state and displays a loading icon.
The SideEffector receives a response with the requested resource and dispatches another action: ImageLoaded, with the image included.
Reducer takes the ImageLoaded action and updates the image component state to 'loaded' and adds the image to the state.
The image component observes the 'loaded' state, gets the image, and displays it.
The text was updated successfully, but these errors were encountered:
SideEffectors
are objects or systems that react to actions, but are allowed to produce side effects. Unlike reducers,SideEffectors
cannot modify state directly, however they can dispatch actions.SideEffectors
should have two method "hooks" into theStore
:PreEffect
: called immediately when an action is dispatched, before reduction.PostEffect
: called after reduction.Each hook is passed the action that was dispatched, the current state, and an
IActionDispatcher
.Architecturally,
SideEffectors
reduce burden on components by being responsible for side effects, especially asynchrony. For example, a component doesn't need to care about the details of requesting a remote resource, it just needs to care about displaying it.Here's an example flow for the use case where clicking a button should load a remote image and display it in a component:
ButtonClicked
action.ButtonClicked
action and initiates a web request for the resource.ButtonClicked
action and updates state to indicate that the image component is in the 'loading' state.ImageLoaded
, with the image included.ImageLoaded
action and updates the image component state to 'loaded' and adds the image to the state.The text was updated successfully, but these errors were encountered: