Sagas
Kea has support for sagas via the kea-saga
plugin.
Read more about Sagas on the redux-saga homepage.
Breaking changes with 1.0
If you're upgrading from 0.x, please read this regarding the breaking change of automatically binding actions to dispatch in Kea.
#
InstallationFirst install the kea-saga
and redux-saga
packages:
Then you install the plugin:
#
UsageFirst, read the docs on the redux-saga homepage to learn how sagas work.
Adding kea-saga
will give your logic stores access to the keys: start
, stop
, takeEvery
, takeLatest
, workers
, sagas
.
function * () {}
#
start: Saga that is started whenever the component is connected or the saga exported from this component starts
Note: sagas are started before your wrapped component's componentDidMount
. Actions
dispatched before this lifecycle method will not be seen inside start
.
function * () {}
#
stop: Saga that is started whenever the component is disconnected or the saga exported from this component is cancelled
This function is called right before your wrapped component's componentWillUnmount
lifecycle method.
({ actions }) => ({})
#
takeEvery: Run the following workers every time the action is dispatched
Note: sagas are started before your wrapped component's componentDidMount
. Actions dispatched
before this lifecycle method will not be seen by takeEvery
.
({ actions }) => ({})
#
takeLatest: Run the following workers every time the action is dispatched, cancel the previous worker if still running
Note: sagas are started before your wrapped component's componentDidMount
. Actions dispatched
before this lifecycle method will not be seen by takeLatest
.
{}
#
workers: An object of workers which you may reference in other sagas.
[]
#
sagas: Array of sagas that get exported with this component's saga
autoConnect
#
Note about The current saga plugin (v2.0.0) does not support autoConnect
. That means if you want to call otherLogic.actions.something()
inside a saga, you must first make sure otherLogic
is connected to your logic: