|
3 | 3 | * [Overview](#overview)
|
4 | 4 | * [Methods](#methods)
|
5 | 5 | * [almanac.factValue(Fact fact, Object params, String path) -> Promise](#almanacfactvaluefact-fact-object-params-string-path---promise)
|
| 6 | + * [almanac.addFact(String id, Function [definitionFunc], Object [options])](#almanacaddfactstring-id-function-definitionfunc-object-options) |
6 | 7 | * [almanac.addRuntimeFact(String factId, Mixed value)](#almanacaddruntimefactstring-factid-mixed-value)
|
7 | 8 | * [almanac.getEvents(String outcome) -> Events[]](#almanacgeteventsstring-outcome---events)
|
8 | 9 | * [almanac.getResults() -> RuleResults[]](#almanacgetresults---ruleresults)
|
@@ -33,8 +34,28 @@ almanac
|
33 | 34 | .then( value => console.log(value))
|
34 | 35 | ```
|
35 | 36 |
|
| 37 | +### almanac.addFact(String id, Function [definitionFunc], Object [options]) |
| 38 | + |
| 39 | +Sets a fact in the almanac. Used in conjunction with rule and engine event emissions. |
| 40 | + |
| 41 | +```js |
| 42 | +// constant facts: |
| 43 | +engine.addFact('speed-of-light', 299792458) |
| 44 | + |
| 45 | +// facts computed via function |
| 46 | +engine.addFact('account-type', function getAccountType(params, almanac) { |
| 47 | + // ... |
| 48 | +}) |
| 49 | + |
| 50 | +// facts with options: |
| 51 | +engine.addFact('account-type', function getAccountType(params, almanac) { |
| 52 | + // ... |
| 53 | +}, { cache: false, priority: 500 }) |
| 54 | +``` |
| 55 | + |
36 | 56 | ### almanac.addRuntimeFact(String factId, Mixed value)
|
37 | 57 |
|
| 58 | +**Deprecated** Use `almanac.addFact` instead |
38 | 59 | Sets a constant fact mid-run. Often used in conjunction with rule and engine event emissions.
|
39 | 60 |
|
40 | 61 | ```js
|
|
0 commit comments