Skip to content

Commit cf58637

Browse files
author
Julien Sanchez
committed
Fix event return codes and tests
1 parent 1180b8a commit cf58637

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

state-machine.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@
106106
return this.error(name, from, to, args, StateMachine.Error.INVALID_TRANSITION, "event " + name + " inappropriate in current state " + this.current);
107107

108108
if (false === StateMachine.beforeEvent(this, name, from, to, args))
109-
return StateMachine.CANCELLED;
109+
return StateMachine.Result.CANCELLED;
110110

111111
if (from === to) {
112112
StateMachine.afterEvent(this, name, from, to, args);
113-
return StateMachine.NOTRANSITION;
113+
return StateMachine.Result.NOTRANSITION;
114114
}
115115

116116
// prepare a transition method for use EITHER lower down, or by caller if they want an async transition (indicated by an ASYNC return value from leaveState)
@@ -121,6 +121,7 @@
121121
StateMachine.enterState( fsm, name, from, to, args);
122122
StateMachine.changeState(fsm, name, from, to, args);
123123
StateMachine.afterEvent( fsm, name, from, to, args);
124+
return StateMachine.Result.SUCCEEDED;
124125
};
125126
this.transition.cancel = function() { // provide a way for caller to cancel async transition if desired (issue #22)
126127
fsm.transition = null;
@@ -130,15 +131,14 @@
130131
var leave = StateMachine.leaveState(this, name, from, to, args);
131132
if (false === leave) {
132133
this.transition = null;
133-
return StateMachine.CANCELLED;
134+
return StateMachine.Result.CANCELLED;
134135
}
135-
else if ("async" === leave) {
136-
return StateMachine.ASYNC;
136+
else if (StateMachine.ASYNC === leave) {
137+
return StateMachine.Result.ASYNC;
137138
}
138139
else {
139140
if (this.transition)
140-
this.transition(); // in case user manually called transition() but forgot to return ASYNC
141-
return StateMachine.SUCCEEDED;
141+
return this.transition(); // in case user manually called transition() but forgot to return ASYNC
142142
}
143143

144144
};

test/test_basics.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,16 @@ test("event return values (github issue #12) ", function() {
448448

449449
equals(fsm.current, 'stopped', "initial state should be stopped");
450450

451-
equals(fsm.prepare(), StateMachine.SUCCEEDED, "expected event to have SUCCEEDED");
451+
equals(fsm.prepare(), StateMachine.Result.SUCCEEDED, "expected event to have SUCCEEDED");
452452
equals(fsm.current, 'ready', "prepare event should transition from stopped to ready");
453453

454-
equals(fsm.fake(), StateMachine.CANCELLED, "expected event to have been CANCELLED");
454+
equals(fsm.fake(), StateMachine.Result.CANCELLED, "expected event to have been CANCELLED");
455455
equals(fsm.current, 'ready', "cancelled event should not cause a transition");
456456

457-
equals(fsm.start(), StateMachine.ASYNC, "expected event to cause an ASYNC transition");
457+
equals(fsm.start(), StateMachine.Result.ASYNC, "expected event to cause an ASYNC transition");
458458
equals(fsm.current, 'ready', "async transition hasn't happened yet");
459459

460-
equals(fsm.transition(), StateMachine.SUCCEEDED, "expected async transition to have SUCCEEDED");
460+
equals(fsm.transition(), StateMachine.Result.SUCCEEDED, "expected async transition to have SUCCEEDED");
461461
equals(fsm.current, 'running', "async transition should now be complete");
462462

463463
});

0 commit comments

Comments
 (0)