mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2026-01-11 20:55:58 -08:00
21 lines
498 B
JavaScript
21 lines
498 B
JavaScript
export class FSM {
|
|
// Constructor
|
|
constructor(options) {
|
|
this.state = options && options.state;
|
|
this.transitions = options && options.transitions || {};
|
|
}
|
|
|
|
// Do nothing if the to is inaccesible
|
|
dispatch(to, params) {
|
|
const action = this.transitions[this.state][to];
|
|
if (action) {
|
|
this.state = to;
|
|
|
|
if (params) {
|
|
action(params);
|
|
} else {
|
|
action()
|
|
}
|
|
}
|
|
}
|
|
} |