* Add a fact definition to the engine. Facts are called by rules as they are evaluated. * @param {object|Fact} id - fact identifier or instance of Fact * @param {function} definitionFunc - function to be called when computing the fact value for a given rule * @param {Object} options - opti
(id, valueOrMethod, options)
| 160 | * @param {Object} options - options to initialize the fact with. used when "id" is not a Fact instance |
| 161 | */ |
| 162 | addFact (id, valueOrMethod, options) { |
| 163 | let factId = id |
| 164 | let fact |
| 165 | if (id instanceof Fact) { |
| 166 | factId = id.id |
| 167 | fact = id |
| 168 | } else { |
| 169 | fact = new Fact(id, valueOrMethod, options) |
| 170 | } |
| 171 | debug(`engine::addFact id:${factId}`) |
| 172 | this.facts.set(factId, fact) |
| 173 | return this |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Remove a fact definition to the engine. Facts are called by rules as they are evaluated. |