Skip to content

Commit b3c083d

Browse files
author
Cache Hamm
committed
Update docs to reference successEvents
1 parent 4ec0051 commit b3c083d

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ let facts = {
8686
// Run the engine to evaluate
8787
engine
8888
.run(facts)
89-
.then(results => {
90-
// 'results' is an object containing successful events, and an Almanac instance containing facts
91-
results.events.map(event => console.log(event.params.message))
89+
.then(runResult => {
90+
runResult.successResults.map(result => console.log(result.event.params.message))
9291
})
9392

9493
/*
@@ -171,8 +170,8 @@ engine.addFact('account-information', function (params, almanac) {
171170
let facts = { accountId: 'lincoln' }
172171
engine
173172
.run(facts)
174-
.then((results) => {
175-
console.log(facts.accountId + ' is a ' + results.events.map(event => event.params.message))
173+
.then((runResult) => {
174+
console.log(facts.accountId + ' is a ' + runResult.successResults.map(result => result.event.params.message))
176175
})
177176
.catch(err => console.log(err.stack))
178177

docs/almanac.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ When a rule evalutes truthy and its ```event``` is called, new facts may be defi
110110
111111
```js
112112
engine.on('success', (event, almanac) => {
113-
// Handle the event using a fact value to process
114-
// Retrieve user's account info and make an api call using the results
115-
almanac
116-
.factValue('account-information', event.params.accountId)
117-
.then(info => {
118-
return request.post({ url: `http://my-service/toggle?funded=${!info.funded}`)
119-
})
113+
// Retrieve user's account info based on the event params
114+
const info = await almanac.factValue('account-information', event.params.accountId)
115+
116+
// make an api call using the results
117+
await request.post({ url: `http://my-service/toggle?funded=${!info.funded}`)
118+
119+
// engine execution continues when promise returned to 'success' callback resolves
120120
})
121121
```
122122

docs/engine.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Engine stores and executes rules, emits events, and maintains state.
1111
* [engine.removeRule(Rule instance)](#engineremoverulerule-instance)
1212
* [engine.addOperator(String operatorName, Function evaluateFunc(factValue, jsonValue))](#engineaddoperatorstring-operatorname-function-evaluatefuncfactvalue-jsonvalue)
1313
* [engine.removeOperator(String operatorName)](#engineremoveoperatorstring-operatorname)
14-
* [engine.run([Object facts], [Object options]) -> Promise ({ events: Events, almanac: Almanac})](#enginerunobject-facts-object-options---promise--events-events-almanac-almanac)
14+
* [engine.run([Object facts], [Object options]) -> Promise ({ events: Events, almanac: Almanac, successResults: [], failureResults: []})](#enginerunobject-facts-object-options---promise--events-events-almanac-almanac-successresults--failureresults-)
1515
* [engine.stop() -> Engine](#enginestop---engine)
1616
* [engine.on('success', Function(Object event, Almanac almanac, RuleResult ruleResult))](#engineonsuccess-functionobject-event-almanac-almanac-ruleresult-ruleresult)
1717
* [engine.on('failure', Function(Object event, Almanac almanac, RuleResult ruleResult))](#engineonfailure-functionobject-event-almanac-almanac-ruleresult-ruleresult)
@@ -156,24 +156,25 @@ engine.removeOperator('startsWithLetter');
156156

157157

158158

159-
### engine.run([Object facts], [Object options]) -> Promise ({ events: Events, almanac: Almanac})
159+
### engine.run([Object facts], [Object options]) -> Promise ({ events: Events, almanac: Almanac, successResults: [], failureResults: []})
160160

161161
Runs the rules engine. Returns a promise which resolves when all rules have been run.
162162

163163
```js
164164
// run the engine
165-
engine.run()
165+
await engine.run()
166166

167167
// with constant facts
168-
engine.run({ userId: 1 })
169-
170-
// returns rule events that were triggered
171-
engine
172-
.run({ userId: 1 })
173-
.then(function(results) {
174-
console.log(results.events)
175-
// almanac available via results.almanac to interact with as defined in Almanac docs
176-
})
168+
await engine.run({ userId: 1 })
169+
170+
// results
171+
const runResult = await engine.run({ userId: 1 })
172+
173+
/**
174+
* runResult.almanac: Almanac instance for the run
175+
* runResult.successEvents: rule results for successful rules
176+
* runResult.failureEvents: rule results for failed rules
177+
*/
177178
```
178179
Link to the [Almanac documentation](./almanac.md)
179180

docs/walkthrough.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ engine.run({ userId: 1 }); // any time a rule condition requires 'userId', '1'
163163

164164
// run() returns a promise
165165
engine.run({ userId: 4 }).then((results) => {
166-
console.log('all rules executed; the following events were triggered: ', results.events)
166+
console.log('all rules executed; the following events were triggered: ', results.successResults.map(result => JSON.stringify(result.event)))
167167
});
168168
```
169169
Helper methods (for this example)

0 commit comments

Comments
 (0)