Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
let Rule have both event and ruleEvent
  • Loading branch information
emilefokkemanavara committed Dec 18, 2024
commit 16a80a7af4e610b51c8f7d348a0ac56bb2d9beca
1 change: 1 addition & 0 deletions src/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Rule extends EventEmitter {
this.ruleEvent = {
type: event.type
}
this.event = this.ruleEvent
if (event.params) this.ruleEvent.params = event.params
return this
}
Expand Down
4 changes: 4 additions & 0 deletions test/rule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Rule', () => {
expect(rule.priority).to.eql(opts.priority)
expect(rule.conditions).to.eql(opts.conditions)
expect(rule.ruleEvent).to.eql(opts.event)
expect(rule.event).to.eql(opts.event)
expect(rule.name).to.eql(opts.name)
})

Expand All @@ -52,6 +53,7 @@ describe('Rule', () => {
expect(rule.priority).to.eql(opts.priority)
expect(rule.conditions).to.eql(opts.conditions)
expect(rule.ruleEvent).to.eql(opts.event)
expect(rule.event).to.eql(opts.event)
expect(rule.name).to.eql(opts.name)
})
})
Expand Down Expand Up @@ -322,6 +324,7 @@ describe('Rule', () => {
expect(hydratedRule.conditions).to.eql(rule.conditions)
expect(hydratedRule.priority).to.eql(rule.priority)
expect(hydratedRule.ruleEvent).to.eql(rule.ruleEvent)
expect(hydratedRule.event).to.eql(rule.event)
expect(hydratedRule.name).to.eql(rule.name)
})

Expand All @@ -333,6 +336,7 @@ describe('Rule', () => {
expect(hydratedRule.conditions).to.eql(rule.conditions)
expect(hydratedRule.priority).to.eql(rule.priority)
expect(hydratedRule.ruleEvent).to.eql(rule.ruleEvent)
expect(hydratedRule.event).to.eql(rule.event)
expect(hydratedRule.name).to.eql(rule.name)
})
})
Expand Down
5 changes: 3 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function engineFactory(
export class Engine {
constructor(rules?: Array<RuleProperties>, options?: EngineOptions);

addRule(rule: RuleProperties | Rule): this;
addRule(rule: RuleProperties): this;
removeRule(ruleOrName: Rule | string): boolean;
updateRule(rule: Rule): void;

Expand Down Expand Up @@ -171,11 +171,12 @@ export interface RuleResult {
): T extends true ? string : RuleResultSerializable;
}

export class Rule {
export class Rule implements RuleProperties {
constructor(ruleProps: RuleProperties | string);
name: string;
conditions: TopLevelCondition;
ruleEvent: Event;
event: Event
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last thing, we should mark one of these as deprecated.
No reason to remove it until a v8 but we should be starting that process.

Copy link
Contributor Author

@emilefokkemanavara emilefokkemanavara Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we'll deprecate ruleEvent, right? (Because we want a Rule to still implement RuleOptions RuleProperties)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct.

priority: number;
setConditions(conditions: TopLevelCondition): this;
setEvent(event: Event): this;
Expand Down
Loading