feat: get fsm to a working testing state

This commit is contained in:
Paul Makles
2022-06-28 13:49:50 +01:00
parent 80f4bb3d98
commit ce88fab714
6 changed files with 63 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
import { action, makeAutoObservable } from "mobx";
import { action, computed, makeAutoObservable } from "mobx";
import { Client } from "revolt.js";
type State = "Ready" | "Connecting" | "Online" | "Disconnected" | "Offline";
@@ -34,6 +34,17 @@ export default class Session {
window.addEventListener("offline", this.onOffline);
}
/**
* Initiate logout and destroy client.
*/
@action destroy() {
if (this.client) {
this.client.logout(false);
this.state = "Ready";
this.client = null;
}
}
private onOnline() {
this.emit({
action: "ONLINE",
@@ -90,6 +101,8 @@ export default class Session {
}
@action async emit(data: Transition) {
console.info("Handle event:", data);
switch (data.action) {
// Login with session
case "LOGIN": {
@@ -161,4 +174,12 @@ export default class Session {
}
}
}
/**
* Whether we are ready to render.
* @returns Boolean
*/
@computed get ready() {
return this.client?.user;
}
}