Energyflow: fix NaN values (#21084)

This commit is contained in:
Michael Geers 2025-05-06 10:35:25 +02:00 • committed by GitHub
parent 7294c8b959
commit f6bcc49e80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,7 @@
<script lang="ts">
import { CountUp } from "countup.js";
import { defineComponent, type PropType } from "vue";
import type { Timeout } from "@/types/evcc";
const DURATION = 0.5;
export default defineComponent({
@ -17,11 +18,12 @@ export default defineComponent({
data() {
return {
instance: null as CountUp | null,
timeout: null as Timeout | null,
};
},
watch: {
to(value) {
this.instance?.update(value);
this.update(value);
},
},
mounted() {
@ -40,11 +42,24 @@ export default defineComponent({
},
unmounted() {
this.instance = null;
if (this.timeout !== null) {
clearTimeout(this.timeout);
}
},
methods: {
forceUpdate() {
this.instance?.reset();
this.instance?.update(this.to);
this.update(this.to);
},
update(value: number) {
// debounced to avoid rendering issues
// @see https://github.com/inorganik/countUp.js/issues/330#issuecomment-2697595198
if (this.timeout !== null) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(() => {
this.instance?.update(value);
}, 100);
},
},
});