-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Under the hood right now Remote Data uses fetch directly, but in many real world apps (like the one I'd like to use this in!) this is a problem, because we use our own API client that has special headers, etc, etc set up.
Rather than pass all this into RemoteData it would be much better if along with calling fetch you could also give it a promise that should resolve or error accordingly.
Doing this would:
- give you a
RemoteDatathat's immediately in thePENDINGstate (and not fire anonChangefor theNOT_ASKED=>PENDINGtransition - If the promise resolves, we go to
SUCCESSand provide whatever the promise resolved with as the data - If it rejects, we go to
FAILUREand provide the error data.
I think this should be a new method on RemoteData ? Could be something like:
// 1
import RemoteData from 'remote-data-js'
const myPromise = myHttpClient.get('/foo')
const customRemote = RemoteData.fromPromise(myPromise, {
onChange: newRemote => {
// either succeeded with the data or failed
}
})
customRemote.isPending() => true
// OR:
const customRemote = RemoteData.fromPromise(myPromise).onChange(fn)Metadata
Metadata
Assignees
Labels
No labels