Is Vuex broken?!
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Hamcha 2019-09-23 17:58:48 +02:00
parent 3ea031caa3
commit 94b361c21f
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
3 changed files with 17 additions and 10 deletions

View file

@ -14,10 +14,10 @@ const actions: ActionTree<NetworkState, AppState> = {
const client = new PeerClient(options.playerInfo, options._customPeer); const client = new PeerClient(options.playerInfo, options._customPeer);
commit("becomeClient", { peer: client }); commit("becomeClient", { peer: client });
client.on("connected", () => { client.on("connected", () => {
commit("connected"); commit("connectionStatusChanged", "connected");
}); });
client.on("disconnected", () => { client.on("disconnected", () => {
commit("disconnected"); commit("connectionStatusChanged", "disconnected");
}); });
client.on("error", err => { client.on("error", err => {
commit("connectionError", err); commit("connectionError", err);

View file

@ -1,5 +1,10 @@
import { MutationTree } from "vuex"; import { MutationTree } from "vuex";
import { NetworkState, ServerNetworkState, ClientNetworkState } from "./types"; import {
NetworkState,
ServerNetworkState,
ClientNetworkState,
ConnectionStatus
} from "./types";
import { LocalClient, PeerServer, PeerClient } from "@/network"; import { LocalClient, PeerServer, PeerClient } from "@/network";
const mutations: MutationTree<NetworkState> = { const mutations: MutationTree<NetworkState> = {
@ -15,12 +20,8 @@ const mutations: MutationTree<NetworkState> = {
(state as ClientNetworkState).peer = payload.peer; (state as ClientNetworkState).peer = payload.peer;
}, },
connected(state) { connectionStatusChanged(state, status: ConnectionStatus) {
(state as ClientNetworkState).connectionStatus = "connected"; (state as ClientNetworkState).connectionStatus = status;
},
disconnected(state) {
(state as ClientNetworkState).connectionStatus = "disconnected";
}, },
connectionError(state, error) { connectionError(state, error) {

View file

@ -7,6 +7,12 @@ import {
} from "@/network"; } from "@/network";
import Peer from "peerjs"; import Peer from "peerjs";
export type ConnectionStatus =
| "connecting"
| "connected"
| "disconnected"
| "error";
export interface ChatMessage { export interface ChatMessage {
who: string; who: string;
to: string; to: string;
@ -23,7 +29,7 @@ export interface NoNetworkState extends SharedNetworkState {
export interface ClientNetworkState extends SharedNetworkState { export interface ClientNetworkState extends SharedNetworkState {
peerType: "client"; peerType: "client";
connectionStatus: "connecting" | "connected" | "disconnected" | "error"; connectionStatus: ConnectionStatus;
connectionError?: Error; connectionError?: Error;
peer: PeerClient; peer: PeerClient;
} }