import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    url: "",
    port: ""
  },
  mutations: {
    SET_SERVER_DOMAIN(state, url) {
      state.url = url
    },
    SET_SERVER_PORT(state, port) {
      state.port = port
    }
  },
  actions: {
    syncServer({ commit }, url) {
      // do something async
      commit('SET_SERVER_DOMAIN', url)
    },
    syncServerPort({ commit }, port) {
      commit('SET_SERVER_PORT', port)
    }
  },
  getters: {
    serverUrl: state => {
      return state.url + ":" + state.port;
    }
  }
})
