Skip to content

Commit 10290f3

Browse files
committed
refactor(engine.ts): allow addRule() to accept Rule | RuleConstructorOptions
BREAKING CHANGE: addRule () now accepts different interface
1 parent 219e59e commit 10290f3

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/engine.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Fact, FactOptions} from './fact'
2-
import {Rule} from './rule'
2+
import {Rule, RuleConstructorOptions} from './rule'
33
import {Operator} from './operator'
44
import {Almanac} from './almanac'
55
import { EventEmitter } from 'events'
@@ -50,19 +50,13 @@ export class Engine extends EventEmitter {
5050
* @param {string} properties.event.params - parameters to pass to the event listener
5151
* @param {Object} properties.conditions - conditions to evaluate when processing this rule
5252
*/
53-
// TODO-Tom: Move this interface to the rule as RuleConstructorOptions | Rule
54-
// addRule (properties: {
55-
// conditions: ConditionConstructorOptions,
56-
// event: Action,
57-
// priority?: number | string,
58-
// }) {
59-
addRule (properties: Rule) {
53+
addRule (properties: Rule | RuleConstructorOptions) {
6054
if (!properties) throw new Error('Engine: addRule() requires options')
6155
if (!properties.hasOwnProperty('conditions')) throw new Error('Engine: addRule() argument requires "conditions" property')
6256
if (!properties.hasOwnProperty('event')) throw new Error('Engine: addRule() argument requires "event" property')
6357

64-
let rule
65-
if (properties instanceof (Rule as any)) {
58+
let rule: Rule
59+
if (properties instanceof Rule) {
6660
rule = properties
6761
} else {
6862
rule = new Rule(properties as any)

0 commit comments

Comments
 (0)