forked from abner/for-legacy-web
feat: get fsm to a working testing state
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user