MCPcopy
hub / github.com/CacheControl/json-rules-engine / addFact

Method addFact

src/almanac.js:100–115  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

_setFactValueMethod · 0.95
debugFunction · 0.85
isConstantMethod · 0.80

Tested by

no test coverage detected