mattkrick / redux-optimistic-ui

a reducer enhancer to enable type-agnostic optimistic updates
MIT License
693 stars 36 forks source link

How to imeplemet with Redux-saga #40

Closed nirmalrepo closed 6 years ago

nirmalrepo commented 6 years ago

Trying to implement the module with redux saga. If any one has already done that, please give me a ping

nirmalrepo commented 6 years ago

Integrated Optimistic UI with Redux Saga,

I've used COMMIT and REVERT as meta attribute when we call to success and failure actions as a yield call. So that I could get the transaction Id. ` const action = yield take(actionTypes.FEED_POST_VOTE_REQUEST) let meta, payload const { nextPayload } = action.payload const transactionID = action.meta.optimistic.id

const result = yield call(postVote, nextPayload)
if (result.sucess) {
  nextPayload.votes = result.voteResult.data.voteCount
  payload = yield call(getFeedListWithModifiedPostVote, nextPayload)
  meta = { optimistic: { type: COMMIT, id: transactionID } }
  yield put(feedPostVoteSuccess(payload, meta))
} else {
  meta = { optimistic: { type: REVERT, id: transactionID } }
  yield put(feedPostVoteFailure(meta))
  yield call(handleError, result.err)
}`

In addition register the optimisticMiddleware prior to the sagaMiddleware