You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not using Promises for http requests in my project, basically because I want to have the chance to cancel ongoing requests, so I tweaked redial making it able to support plain old callbacks.
// createRequestAction.jsimportsendRequestfrom'./sendRequest'constdefaultTypes=['REQUEST','SUCCESS','ERROR']exportdefault(config,callback)=>(dispatch)=>{consttypeSuffixes=config.typeSuffixes||defaultTypesconst[REQUEST,SUCCESS,ERROR]=(config.typeSuffixes||{}).typeSuffixes||typeSuffixesdispatch({type: `${config.type}_${REQUEST}`,meta: config})// the thunk returns the request, so I can abort it if neededreturnsendRequest(config,(err,res)=>{if(err||!res.ok){dispatch({type: `${config.type}_${ERROR}`,err: true,payload: err,meta: config})}else{dispatch({type: `${config.type}_${SUCCESS}`,meta: {...config,status: res.status},payload: res.body})}if(typeofcallback==='function'){callback(err)}})}
The implementation allows me to use superagent rather than other http clients Promise based.
I'm not sure this is something worth considering,but it's working pretty well for me and I wanted to share with you to get your feedback.
Thanks
The text was updated successfully, but these errors were encountered:
Sorry, finally got around to having a proper look at this. It looks like a pretty straightforward change. Would you like to submit a PR with tests for this?
I'm not using Promises for http requests in my project, basically because I want to have the chance to cancel ongoing requests, so I tweaked redial making it able to support plain old callbacks.
In my fork you can see what I changed (please note it's just a prototype)
https://github.com/vesparny/redial/blob/cb/src/trigger.js
That change allows hooks like:
dispatching a thunk, that invokes the callback when data has been loaded.
The implementation allows me to use
superagent
rather than other http clients Promise based.I'm not sure this is something worth considering,but it's working pretty well for me and I wanted to share with you to get your feedback.
Thanks
The text was updated successfully, but these errors were encountered: