-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSessionContext.ts
56 lines (47 loc) · 1.1 KB
/
SessionContext.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
import State from "./State";
export interface SerializedSessionContext {
current : {
name : string;
fsm : string;
}
}
/**
* Context traces substates path.
* It keeps a current state reference, and from which super state, current state was reached.
*
* At any given time, at least two SessionContext exists:
* + FSM
* + current state in FSM.
*/
export default class SessionContext {
previous_: State = null;
current_: State = null;
constructor(prev: State, current: State) {
this.previous_ = prev;
this.current_ = current;
}
get from() {
return this.previous_;
}
get current() {
return this.current_;
}
set current(current: State) {
this.current_ = current;
}
__stateToJSON(s: State) {
if ( s===null ) {
return null;
} else {
return {
name : s.name,
fsm : s.fsm_!==null ? s.fsm_.name : s.name
}
}
}
serialize() {
return {
current: this.__stateToJSON( this.current )
}
}
}