From 2e5a4fd804e62d3bb7a305e85d7fa025f9dc0126 Mon Sep 17 00:00:00 2001 From: Nicola Krumschmidt Date: Fri, 5 May 2023 15:16:53 +0200 Subject: [PATCH] Convert latency store to setup function (#18505) --- app/src/stores/latency.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/app/src/stores/latency.ts b/app/src/stores/latency.ts index 5d72c8f3bd..55299bcb7b 100644 --- a/app/src/stores/latency.ts +++ b/app/src/stores/latency.ts @@ -1,22 +1,26 @@ import { defineStore } from 'pinia'; +import { ref } from 'vue'; type Latency = { latency: number; timestamp: Date; }; -export const useLatencyStore = defineStore({ - id: 'latencyStore', - state: () => ({ - latency: [] as Latency[], - }), - actions: { - async dehydrate() { - this.$reset(); - }, - save(latency: Latency) { - this.latency.push(latency); - this.latency = this.latency.slice(-20); - }, - }, +export const useLatencyStore = defineStore('latencyStore', () => { + const latency = ref([]); + + return { + latency, + dehydrate, + save, + }; + + async function dehydrate() { + latency.value = []; + } + + function save(newLatency: Latency) { + latency.value.push(newLatency); + latency.value = latency.value.slice(-20); + } });