Skip to content

Commit

Permalink
refactor(engine.ts): allow addRule() to accept Rule | RuleConstructor…
Browse files Browse the repository at this point in the history
…Options

BREAKING CHANGE: addRule () now accepts different interface
  • Loading branch information
jsdevtom committed May 16, 2018
1 parent 219e59e commit 10290f3
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/engine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Fact, FactOptions} from './fact'
import {Rule} from './rule'
import {Rule, RuleConstructorOptions} from './rule'
import {Operator} from './operator'
import {Almanac} from './almanac'
import { EventEmitter } from 'events'
Expand Down Expand Up @@ -50,19 +50,13 @@ export class Engine extends EventEmitter {
* @param {string} properties.event.params - parameters to pass to the event listener
* @param {Object} properties.conditions - conditions to evaluate when processing this rule
*/
// TODO-Tom: Move this interface to the rule as RuleConstructorOptions | Rule
// addRule (properties: {
// conditions: ConditionConstructorOptions,
// event: Action,
// priority?: number | string,
// }) {
addRule (properties: Rule) {
addRule (properties: Rule | RuleConstructorOptions) {
if (!properties) throw new Error('Engine: addRule() requires options')
if (!properties.hasOwnProperty('conditions')) throw new Error('Engine: addRule() argument requires "conditions" property')
if (!properties.hasOwnProperty('event')) throw new Error('Engine: addRule() argument requires "event" property')

let rule
if (properties instanceof (Rule as any)) {
let rule: Rule
if (properties instanceof Rule) {
rule = properties
} else {
rule = new Rule(properties as any)
Expand Down

0 comments on commit 10290f3

Please sign in to comment.