UNPKG

509 BJavaScriptView Raw
1/**
2 * Declarative promise
3 */
4
5class DeclarativePromise {
6 constructor (action) {
7 action.meta = action.meta || {}
8 action.meta.then = action.meta.then || []
9
10 this.action = action
11 }
12
13 then (success, failure) {
14 const q = new DeclarativePromise({success, failure})
15 this.action.meta.then.push(q)
16 return q
17 }
18
19 toJSON () {
20 this.action.meta.then = this.action.meta.then.map(then => then.toJSON())
21 return this.action
22 }
23}
24
25/**
26 * Exports
27 */
28
29export default DeclarativePromise