* Add a rule definition to the engine * @param {object|Rule} properties - rule definition. can be JSON representation, or instance of Rule * @param {integer} properties.priority (>1) - higher runs sooner. * @param {Object} properties.event - event to fire when rule evaluates as successful
(properties)
| 43 | * @param {Object} properties.conditions - conditions to evaluate when processing this rule |
| 44 | */ |
| 45 | addRule (properties) { |
| 46 | if (!properties) throw new Error('Engine: addRule() requires options') |
| 47 | |
| 48 | let rule |
| 49 | if (properties instanceof Rule) { |
| 50 | rule = properties |
| 51 | } else { |
| 52 | if (!Object.prototype.hasOwnProperty.call(properties, 'event')) throw new Error('Engine: addRule() argument requires "event" property') |
| 53 | if (!Object.prototype.hasOwnProperty.call(properties, 'conditions')) throw new Error('Engine: addRule() argument requires "conditions" property') |
| 54 | rule = new Rule(properties) |
| 55 | } |
| 56 | rule.setEngine(this) |
| 57 | this.rules.push(rule) |
| 58 | this.prioritizedRules = null |
| 59 | return this |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * update a rule in the engine |