Skip to content

Commit 16a80a7

Browse files
let Rule have both event and ruleEvent
1 parent 933105f commit 16a80a7

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/rule.js

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class Rule extends EventEmitter {
101101
this.ruleEvent = {
102102
type: event.type
103103
}
104+
this.event = this.ruleEvent
104105
if (event.params) this.ruleEvent.params = event.params
105106
return this
106107
}

test/rule.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('Rule', () => {
3030
expect(rule.priority).to.eql(opts.priority)
3131
expect(rule.conditions).to.eql(opts.conditions)
3232
expect(rule.ruleEvent).to.eql(opts.event)
33+
expect(rule.event).to.eql(opts.event)
3334
expect(rule.name).to.eql(opts.name)
3435
})
3536

@@ -52,6 +53,7 @@ describe('Rule', () => {
5253
expect(rule.priority).to.eql(opts.priority)
5354
expect(rule.conditions).to.eql(opts.conditions)
5455
expect(rule.ruleEvent).to.eql(opts.event)
56+
expect(rule.event).to.eql(opts.event)
5557
expect(rule.name).to.eql(opts.name)
5658
})
5759
})
@@ -322,6 +324,7 @@ describe('Rule', () => {
322324
expect(hydratedRule.conditions).to.eql(rule.conditions)
323325
expect(hydratedRule.priority).to.eql(rule.priority)
324326
expect(hydratedRule.ruleEvent).to.eql(rule.ruleEvent)
327+
expect(hydratedRule.event).to.eql(rule.event)
325328
expect(hydratedRule.name).to.eql(rule.name)
326329
})
327330

@@ -333,6 +336,7 @@ describe('Rule', () => {
333336
expect(hydratedRule.conditions).to.eql(rule.conditions)
334337
expect(hydratedRule.priority).to.eql(rule.priority)
335338
expect(hydratedRule.ruleEvent).to.eql(rule.ruleEvent)
339+
expect(hydratedRule.event).to.eql(rule.event)
336340
expect(hydratedRule.name).to.eql(rule.name)
337341
})
338342
})

types/index.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function engineFactory(
2828
export class Engine {
2929
constructor(rules?: Array<RuleProperties>, options?: EngineOptions);
3030

31-
addRule(rule: RuleProperties | Rule): this;
31+
addRule(rule: RuleProperties): this;
3232
removeRule(ruleOrName: Rule | string): boolean;
3333
updateRule(rule: Rule): void;
3434

@@ -171,11 +171,12 @@ export interface RuleResult {
171171
): T extends true ? string : RuleResultSerializable;
172172
}
173173

174-
export class Rule {
174+
export class Rule implements RuleProperties {
175175
constructor(ruleProps: RuleProperties | string);
176176
name: string;
177177
conditions: TopLevelCondition;
178178
ruleEvent: Event;
179+
event: Event
179180
priority: number;
180181
setConditions(conditions: TopLevelCondition): this;
181182
setEvent(event: Event): this;

0 commit comments

Comments
 (0)