-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathState.ts
58 lines (43 loc) · 1.17 KB
/
State.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Transition from "./Transition";
import Session from "./Session";
import FSM from "./FSM";
export type TransitionMap = { [key: string]: Transition };
export default class State {
name_: string;
fsm_ : FSM;
isFinal_ = true;
isInitial_ = true;
enterTransitions_: TransitionMap = {};
exitTransitions_: TransitionMap = {};
constructor(name: string, fsm: FSM) {
this.name_ = name;
this.fsm_ = fsm;
}
onEnter(session: Session<any>, tr: Transition) {
// emit new state this
}
addEnterTransition(t: Transition) {
this.enterTransitions_[t.event] = t;
this.isInitial_ = false;
}
addExitTransition(t: Transition) {
this.exitTransitions_[t.event] = t;
this.isFinal_ = false;
}
get isFinal() {
return this.isFinal_;
}
get isInitial() {
return this.isInitial_;
}
get name() {
return this.name_;
}
transitionForEvent(event: string) {
const r = this.exitTransitions_[event];
return r !== void 0 ? r : null;
}
serialize() :any {
throw new Error("states can't be serialized like this.!");
}
}