Skip to content

Latest commit

 

History

History
 
 

redux-dynostore-redux-saga

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@redux-dynostore/redux-saga

build status npm version npm downloads License: BSD-3-Clause

Enhancer and handler for dynamically running sagas.

Usage

Include dynamic enhancer with redux-dynostore:

import dynostore from '@redux-dynostore/core'
import { dynamicSagas } from '@redux-dynostore/redux-saga'

const sagaMiddlware = createSagaMiddleware()

const store = createStore(reducer, compose(
  applyMiddleware(sagaMiddlware),
  dynostore(dynamicSagas(sagaMiddlware))
)

Run the saga when the dynamic component mounts:

import dynamic from '@redux-dynostore/react-redux'
import { runSaga } from '@redux-dynostore/redux-saga'

export default dynamic('identifier', runSaga(mySaga))(MyComponent)

Manually running sagas

If you aren't using react, or want to run a saga outside of the component lifecycle, the store now has an runSagas function that can be used to run sagas if you only have access to the store:

store.runSagas({ dynamicSaga })

Multiple sagas can be run as well:

store.runSagas({ dynamicSaga1, dynamicSaga2 })

Sagas can also be provided in a nested structure, but this only provides simplified identifier creation:

store.runSagas({ 'some/path/to': dynamicSaga })
store.runSagas({
  some: {
    path: {
      to: {
        dynamicSaga
      }
    }
  }
})

Both the above examples are equivalent to calling:

store.runSagas({ 'some.path.to': dynamicSaga })

Cancelling sagas

If you need to dynamically cancel a saga, the cancelSagas function that can be used:

store.cancelSagas(['dynamicSaga'])

Multiple sagas can be cancelled at the same time as well:

store.cancelSagas(['dynamicSaga1', 'dynamicSaga2'])

Note: only sagas that were added using an the runSagas function can be cancelled. Static sagas cannot be cancelled.