1 | /**
|
2 | * Declarative promise
|
3 | */
|
4 |
|
5 | class 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 |
|
29 | export default DeclarativePromise
|