Skip to content

Commit 9465ad1

Browse files
author
Cache Hamm
committed
document allowUndefinedFacts
1 parent 1d2968b commit 9465ad1

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

docs/engine.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The Engine stores and executes rules, emits events, and maintains state.
44

55
## Methods
66

7-
### constructor([Array rules])
7+
### constructor([Array rules], Object [options])
88

99
```js
1010
let Engine = require('json-rules-engine').Engine
@@ -13,8 +13,20 @@ let engine = new Engine()
1313

1414
// initialize with rules
1515
let engine = new Engine([Array rules])
16+
17+
// initialize with options
18+
let options = {
19+
allowUndefinedFacts: false
20+
};
21+
let engine = new Engine([Array rules], options)
1622
```
1723

24+
#### Options
25+
26+
`allowUndefinedFacts` - By default, when a running engine encounters an undefined fact,
27+
an exception is thrown. Turning this option on will cause the engine to treat
28+
undefined facts as falsey conditions. (default: false)
29+
1830
### engine.addFact(String id, Function [definitionFunc], Object [options])
1931

2032
```js

docs/walkthrough.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ More on rules can be found [here](./docs/rules.md)
6161

6262
### Step 3: Define Facts
6363

64-
Facts are constant values or pure functions. Using the current example, if the engine were to be run, it would throw an error: "Undefined fact: 'age'". So let's define some facts!
64+
Facts are constant values or pure functions. Using the current example, if the engine were to be run, it would throw an exception: `Undefined fact:'age'` (note: this behavior can be disable via [engine options](./engine.md#Options)).
65+
66+
Let's define some facts:
6567

6668
```js
6769

src/engine.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Engine extends EventEmitter {
167167
debug(`engine::run runtimeFacts:`, runtimeFacts)
168168
runtimeFacts['success-events'] = new Fact('success-events', SuccessEventFact(), { cache: false })
169169
this.status = RUNNING
170-
let almanac = new Almanac(this.facts, runtimeFacts, this.options)
170+
let almanac = new Almanac(this.facts, runtimeFacts)
171171
let orderedSets = this.prioritizeRules()
172172
let cursor = Promise.resolve()
173173
// for each rule set, evaluate in parallel,

0 commit comments

Comments
 (0)