declarative-promise
Version:
Behaves kinda like the es6 Promise api, but it doesn't actually *do* anything. It just produces a description of what is to be done, by someone else. At the moment, it's designed to work with the [redux-fetch](https://github.com/ashaffer/redux-fetch) mi
43 lines (30 loc) • 880 B
Markdown
Produce declarative specifications of your promise chains. Designed to be used in conjunction with [redux-effects](https://github.com/redux-effects/redux-effects)
`npm install declarative-promise`
From an async action creator:
```javascript
import DeclarativePromise from 'declarative-promise'
function getUrl (url) {
return new DeclarativePromise({
type: 'EFFECT',
payload: {
type: 'FETCH',
url
}
})
}
```
From application-level code:
```javascript
import getUrl from 'get-url'
import {createAction} from 'redux-actions'
const gotGoogle = createAction('GOT_GOOGLE')
function fetchGoogle () {
return getUrl('http://www.google.com')
.then(gotGoogle)
.toJSON()
}
```
Note the `.tojSON()` at the end. That is essential, it de-sugars the declarative promise back to a plain JS object.