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
30 lines (23 loc) • 509 B
JavaScript
/**
* Declarative promise
*/
class DeclarativePromise {
constructor (action) {
action.meta = action.meta || {}
action.meta.then = action.meta.then || []
this.action = action
}
then (success, failure) {
const q = new DeclarativePromise({success, failure})
this.action.meta.then.push(q)
return q
}
toJSON () {
this.action.meta.then = this.action.meta.then.map(then => then.toJSON())
return this.action
}
}
/**
* Exports
*/
export default DeclarativePromise