LiveAtlas/src/App.vue

77 lines
1.3 KiB
Vue
Raw Normal View History

2020-11-20 18:43:30 +00:00
<template>
2020-11-23 12:13:28 +00:00
<Leaflet></Leaflet>
<Sidebar></Sidebar>
2020-11-20 18:43:30 +00:00
</template>
2020-11-20 21:47:56 +00:00
<script lang="ts">
2020-11-23 12:13:28 +00:00
import {defineComponent, computed, ref} from 'vue';
import Leaflet from './components/Leaflet.vue';
import Sidebar from './components/Sidebar.vue';
import {ActionTypes, useStore} from "./store";
export default defineComponent({
name: 'WorldList',
components: {
Leaflet,
Sidebar,
},
setup() {
let store = useStore(),
updateInterval = computed(() => store.state.configuration.updateInterval),
updatesEnabled = ref(false),
updateTimeout = ref(0);
return {
store,
updateInterval,
updatesEnabled,
updateTimeout
}
},
mounted() {
this.loadConfiguration();
},
beforeUnmount() {
this.stopUpdates();
},
methods: {
loadConfiguration() {
useStore().dispatch(ActionTypes.LOAD_CONFIGRUATION, undefined).then(() => {
this.startUpdates();
});
},
startUpdates() {
this.updatesEnabled = true;
this.update();
},
update() {
useStore().dispatch(ActionTypes.GET_UPDATE, undefined).then(() => {
if(this.updatesEnabled) {
this.updateTimeout = setTimeout(() => this.update(), this.updateInterval);
}
});
},
stopUpdates() {
this.updatesEnabled = false;
if (this.updateTimeout) {
clearTimeout(this.updateTimeout);
}
this.updateTimeout = 0;
}
}
});
2020-11-20 18:43:30 +00:00
</script>
2020-11-20 21:47:56 +00:00
<style lang="scss">
2020-11-23 12:13:28 +00:00
2020-11-20 18:43:30 +00:00
</style>