-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathrule-result.js
48 lines (43 loc) · 1.14 KB
/
rule-result.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
import deepClone from 'clone'
export default class RuleResult {
constructor (conditions, event, priority, name) {
this.conditions = deepClone(conditions)
this.event = deepClone(event)
this.priority = deepClone(priority)
this.name = deepClone(name)
this.result = null
}
setResult (result) {
this.result = result
}
resolveEventParams (almanac) {
if (this.event.params !== null && typeof this.event.params === 'object') {
const updates = []
for (const key in this.event.params) {
if (Object.prototype.hasOwnProperty.call(this.event.params, key)) {
updates.push(
almanac
.getValue(this.event.params[key])
.then((val) => (this.event.params[key] = val))
)
}
}
return Promise.all(updates)
}
return Promise.resolve()
}
toJSON (stringify = true) {
const props = {
conditions: this.conditions.toJSON(false),
event: this.event,
priority: this.priority,
name: this.name,
result: this.result
}
if (stringify) {
return JSON.stringify(props)
}
return props
}
}