annotate src/implab/components/StateMachine.js @ 14:5fd2a35d65c0

Слияние
author cin
date Fri, 08 Sep 2017 13:45:10 +0300
parents 7d7059d2a810
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
7d7059d2a810 Подправлены пути в пакетах
egor
parents: 0
diff changeset
1 define([ "dojo/_base/declare", "../safe", "../text/format" ], function(declare, safe, format) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
2 return declare(null, {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
3 states : null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
4
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
5 current : null,
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
6
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
7 constructor : function(opts) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
8 safe.argumentNotNull(opts, "opts");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
9 safe.argumentNotNull(opts.states, "opts.states");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
10 safe.argumentNotNull(opts.initial, "opts.initial");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
11
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
12 this.states = opts.states;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
13 this.current = opts.initial;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
14
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
15 if (safe.isNull(this.states[this.current]))
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
16 throw new Error("Invalid initial state " + this.current);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
17 },
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
18
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
19 move : function(input, noThrow) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
20 safe.argumentNotNull(input, "input");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
21
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
22 var next = this.states[this.current][input];
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
23 if(safe.isNull(next)) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
24 if (noThrow)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
25 return false;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
26 else
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
27 throw new Error(format("Invalid transition {0}-{1}->?", this.current, input));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
28 } else {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
29 this.current = next;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
30 return true;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
31 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
32 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
33 });
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
34 });