Mercurial > pub > ImplabJs
comparison core/src/js/components/StateMachine.js @ 34:27e8e9e38e07 default tip
Слияние
author | nickolay |
---|---|
date | Wed, 05 Jun 2019 20:44:15 +0300 |
parents | acdcdf1a8d21 |
children |
comparison
equal
deleted
inserted
replaced
33:8af8e840dd49 | 34:27e8e9e38e07 |
---|---|
1 define([ "dojo/_base/declare", "../safe", "../text/format" ], function(declare, safe, format) { | |
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 }); |