redux-batched-actions icon indicating copy to clipboard operation
redux-batched-actions copied to clipboard

Batch middleware can cause infinite recursion

Open tshelburne opened this issue 7 years ago • 5 comments

original comment: https://github.com/tshelburne/redux-batched-actions/pull/18#issuecomment-364916115

tshelburne avatar Feb 12 '18 17:02 tshelburne

Is there a workaround for this issue?

nikolal avatar Apr 04 '18 08:04 nikolal

batchDispatchMiddleware always causes an infinite loop for me. I can't get the example to work.

import {createStore, applyMiddleware} from 'redux'
import {batchActions, enableBatching, batchDispatchMiddleware} from 'redux-batched-actions'
import {createAction} from 'redux-actions'

const doThing = createAction('DO_THING')
const doOther = createAction('DO_OTHER')

function reducer (state, action) {
  switch (action.type) {
    case 'DO_THING': return 'thing'
    case 'DO_OTHER': return 'other'
    default: return state
  }
}

// Handle bundled actions in reducer
const store = createStore(
  enableBatching(reducer),
  '',
  applyMiddleware(batchDispatchMiddleware)
)

store.dispatch(batchActions([doThing(), doOther()]))
// OR
store.dispatch(batchActions([doThing(), doOther()], 'DO_BOTH'))

image

Versions [email protected] [email protected] [email protected]

dadamssg avatar Apr 20 '18 14:04 dadamssg

@dadamssg @tshelburne @nikolal See my pull request

granttj01 avatar Apr 30 '18 08:04 granttj01

Hey all, apologies for the delay, big releases at work prevented me from checking this stuff out. Gonna take a look.

tshelburne avatar May 02 '18 14:05 tshelburne

@tshelburne thanks for the lib before anything. I came to this issue to say that I couldn't make the lib work by applying the middleware, when I did this, all actions were dispatched normally, one by one, triggering the render, plus the BATCHING_REDUCER.BATCH one. I could put it to work with enableBatching. My attempt to use the middleware was with redux-saga, applying applyMiddleware(sagaMiddleware, batchDispatchMiddleware).

rodgobbi avatar May 21 '18 21:05 rodgobbi