Skip to content

Commit 714bb5d

Browse files
authored
improve performance of Workflow.prototype.can() method fixes #12 (#13)
1 parent 6eb7947 commit 714bb5d

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"import"
55
],
66
"rules":{
7-
"no-param-reassign":"off"
7+
"arrow-body-style": "off",
8+
"no-param-reassign": "off",
9+
"padded-blocks": "off"
810
}
911
}

src/module/workflow.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,11 @@ class Workflow extends EventEmitter {
7979
}
8080

8181
can(subject, transitionName) {
82-
let canTransit = false;
83-
const transitions = this.getEnabledTransitions(subject);
8482

85-
transitions.forEach((transition) => {
86-
if (transition.name === transitionName) {
87-
canTransit = true;
88-
}
89-
});
83+
return this.getEnabledTransitions(subject).some((transition) => {
9084

91-
return canTransit;
85+
return (transition.name === transitionName);
86+
});
9287
}
9388

9489
apply(subject, transitionName) {

0 commit comments

Comments
 (0)