redux-logic
redux-logic copied to clipboard
processOptions.latest not working with async process function
Hey, I'm new to redux-logic and in this example I'm using it to filter/query some data, which requires some dispatches inside my logic to query data. This is what my logic currently looks like:
export default createLogic({
type: SEARCH,
cancelType: SEARCH_CANCEL,
latest: true,
processOptions: {
dispatchMultiple: true
},
process: async({ getState, action }, dispatch, done) => {
console.log(action.payload.filter)
let resultCount = 0
let { day } = action.payload
while(resultCount < action.payload.count) {
let current = []
try {
current = await dispatch(loadSomething(day)) //loadSomething() is an imported action creator
} catch (e) {
dispatch({
type: SEARCH_ERROR,
payload: e
})
done()
}
current = current.payload
console.log(current)
resultCount += 1
day.add(1, 'd')
}
done()
}
})
It works fine, the async function and awaiting the dispatch don't cause any problems. I also get fine results - BUT the processOptions.latest = true doesn't work. I can see multiple logic middleware instances working at once (I made my querying wait 2.5 seconds to better become visible). This could lead to invalid states - I could fix it by providing additional data in my result dispatch() [not included yet], but I'd like to use the latest option.
Any ideas? Thanks in advance!