npm redux-saga 0.6.0

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

This release include a new generator driver core that doesnt rely on promises. This should get rid of annoying issues related to Saga missing events.

The new implementation uses only callback notification to handle synchronous actions. It means now even when you dispatch multiple actions concecutively in a synchrnous way, Sagas waiting for those action wont miss anyone. It means also that Saga starts immediately and do not miss actions fired at startup (no more requestAnimationFrame tricks are required).

For more background see the explanation on this issue. This release should fixe #50 and #55

Other Changes

  • Uncaught SagaCancellationExceptions are no longer bubbled to parents. This was necessary to make yield cancel(...) have true non blocking semantics. Once we cancel a task, we move immediately to the next step. If the cancelled task omits to catch its cancellation error, a warning message will be printed on the console (only in dev mode).
  • Fixed 'Infinite loop when using take('*')' (#61)
  • Uncaught cancellation exception are logged into the console only in dev mode (process.env.NODE_ENV set to 'development')
  • Monitor actions are also dispatched only in dev mode
  • new function createMockTask to mock results of fork effects. With this function, it is now possible to test generators using fork like this
import test from 'tape';
import { take, fork, cancel } from 'redux-saga'
import { createMockTask } from 'redux-saga/lib/testUtils'

const types = { GET_DATA: 'GET_DATA'}

function callApi() { ... }

export function* getData () {
  let task
  while (true) {
    let { data } = yield take(types.GET_DATA)
    task && task.isRunning() ? yield cancel(task) : null
    task = yield fork(callApi, data)
  }
}

test('getData', assert => {

  const it = getData()

  assert.deepEqual( it.next().value, take(types.GET_DATA) )

  const mockData = {data: 'xyz'}
  const mockAction = {type: types.GET_DATA, data: mockData }

  // resume the generator with mockAction
  // since task is null, we expect yield null
  assert.deepEqual( it.next(mockAction).value, fork(callApi, mockData ) )

  // mock fork result
  const mockTask = createMockTask()

  // resume the generator with mock task
  assert.deepEqual( it.next(mockTask).value, take(types.GET_DATA) )

  // simulate a task ending
  mockTask.setRunning(false)

  // now expect a cancel
  assert.deepEqual( it.next(mockAction).value, cancel(mockTask) )

  assert.end()
})

Don't miss a new redux-saga release

NewReleases is sending notifications on new releases.