2
|
1 define([ "dojo/_base/declare", "../safe", "../text/format" ], function(declare, safe, format) {
|
0
|
2 return declare(null, {
|
|
3 states : null,
|
|
4
|
|
5 current : null,
|
|
6
|
|
7 constructor : function(opts) {
|
|
8 safe.argumentNotNull(opts, "opts");
|
|
9 safe.argumentNotNull(opts.states, "opts.states");
|
|
10 safe.argumentNotNull(opts.initial, "opts.initial");
|
|
11
|
|
12 this.states = opts.states;
|
|
13 this.current = opts.initial;
|
|
14
|
|
15 if (safe.isNull(this.states[this.current]))
|
|
16 throw new Error("Invalid initial state " + this.current);
|
|
17 },
|
|
18
|
|
19 move : function(input, noThrow) {
|
|
20 safe.argumentNotNull(input, "input");
|
|
21
|
|
22 var next = this.states[this.current][input];
|
|
23 if(safe.isNull(next)) {
|
|
24 if (noThrow)
|
|
25 return false;
|
|
26 else
|
|
27 throw new Error(format("Invalid transition {0}-{1}->?", this.current, input));
|
|
28 } else {
|
|
29 this.current = next;
|
|
30 return true;
|
|
31 }
|
|
32 }
|
|
33 });
|
|
34 }); |