* 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)
| 98 | * @param {Object} options - options to initialize the fact with. used when "id" is not a Fact instance |
| 99 | */ |
| 100 | addFact (id, valueOrMethod, options) { |
| 101 | let factId = id |
| 102 | let fact |
| 103 | if (id instanceof Fact) { |
| 104 | factId = id.id |
| 105 | fact = id |
| 106 | } else { |
| 107 | fact = new Fact(id, valueOrMethod, options) |
| 108 | } |
| 109 | debug(`almanac::addFact id:${factId}`) |
| 110 | this.factMap.set(factId, fact) |
| 111 | if (fact.isConstant()) { |
| 112 | this._setFactValue(fact, {}, fact.value) |
| 113 | } |
| 114 | return this |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Adds a constant fact during runtime. Can be used mid-run() to add additional information |
nothing calls this directly
no test coverage detected