npm redux-saga 0.7.0

latest releases: 1.3.0, 1.2.3, 1.2.2...
8 years ago

Features

This release adds new support to dynamically running Sagas after the applyMiddleware phase.

In previous releases, the library provided the runSaga method to start Sagas dynamically. However, there were some issues due to how runSaga was implemented (related issues #48, #76)

In this release, the library provides a new method (thanks to @gaearon) to attach Sagas dynamically to the Store.

Migration

(see API docs for detailed infos)

Before

In previous releases, you had to create a storeIO and passes it to runSaga

configureStore.js

import createSagaMiddleware from 'redux-saga'
import reducer from './path/to/reducer'
import startupSagas from './path/to/sagas'

export default function configureStore(initialState) {
  // Note: passing middleware as the last argument to createStore requires redux@>=3.1.0
  return createStore(
    reducer,
    initialState,
    applyMiddleware(/* other middleware, */createSagaMiddleware(...startupSagas ))
  )
}

someModule.js

import {runSaga, storeIO} from 'redux-saga'
import configureStore from './configureStore '

import dynamicSaga from './path/to/dynamicSaga'

const store = configureStore()
const task = runSaga(
  dynamicSaga(store.getState),
  storeIO(store)
)

After

Starting from this release, you export the saga middleware itself and uses its run method

configureStore.js

import createSagaMiddleware from 'redux-saga'
import reducer from './path/to/reducer'
import startupSagas from './path/to/sagas'

// export the middleware
export const sagaMiddleware = createSagaMiddleware(...startupSagas)

export default function configureStore(initialState) {
  // Note: passing middleware as the last argument to createStore requires redux@>=3.1.0
  return createStore(
    reducer,
    initialState,
    applyMiddleware(/* other middleware, */ sagaMiddleware)
  )
}

someModule.js

import { sagaMiddleware } from './configureStore'
import dynamicSaga from './path/to/dynamicSaga'

sagaMiddleware.run(dynamicSaga)

Other changes

  • Task descriptor enhanced with a new cancel method
  • Throw an Error if the Saga was provided an undefined action
  • The documentation is now using GitBook thanks to @cef62

Don't miss a new redux-saga release

NewReleases is sending notifications on new releases.