From 6277ffa607ee3963421137176c9f8e4dc74b5f5d Mon Sep 17 00:00:00 2001 From: Miguel Angel Mulero Martinez Date: Tue, 18 Feb 2025 17:09:30 +0100 Subject: [PATCH] Fix as many Vue3 issues as possible The biggest problem is with arrays. Vue3 is not detecting well reactivity in some arrays because we have the view and the logic in different files, so we can't access the reactivity proxy in a clean way. I've added reactivity in the definition of the modules affected as a workaround, but I'm sure there must be a better way. --- package.json | 2 +- src/components/init.js | 49 ++--- .../port-picker/FirmwareVirtualOption.vue | 50 ++++-- .../port-picker/PortOverrideOption.vue | 56 +++--- src/components/port-picker/PortPicker.vue | 43 ++--- src/components/port-picker/PortsInput.vue | 169 ++++++------------ src/components/quad-status/BatteryIcon.vue | 154 +++++++--------- src/components/quad-status/BatteryLegend.vue | 36 ++-- src/components/status-bar/PortUtilization.vue | 44 ++--- src/components/status-bar/StatusBar.vue | 2 +- src/js/fc.js | 3 +- src/js/port_handler.js | 18 +- yarn.lock | 2 +- 13 files changed, 284 insertions(+), 344 deletions(-) diff --git a/package.json b/package.json index 396afa2ea5..52acc96f19 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "three": "~0.97.0", "tiny-emitter": "^2.1.0", "vite-plugin-pwa": "^0.17.5", - "vue": "^3.5.12" + "vue": "^3.5.13" }, "devDependencies": { "@babel/core": "^7.24.4", diff --git a/src/components/init.js b/src/components/init.js index 062ec8841d..19ae8ead14 100644 --- a/src/components/init.js +++ b/src/components/init.js @@ -2,10 +2,10 @@ // `i18n` helper to window and setting up `i18next` // in the future it should be pure. This means it should // explicitly export things used by other parts of the app. -import '../js/localization.js'; -import '../js/injected_methods'; -import i18next from 'i18next'; -import { createApp } from "vue"; +import "../js/localization.js"; +import "../js/injected_methods"; +import i18next from "i18next"; +import { createApp, reactive } from "vue"; import I18NextVue from "i18next-vue"; import BatteryLegend from "./quad-status/BatteryLegend.vue"; import BetaflightLogo from "./betaflight-logo/BetaflightLogo.vue"; @@ -18,35 +18,42 @@ import PortUsage from "../js/port_usage.js"; import PortPicker from "./port-picker/PortPicker.vue"; import CONFIGURATOR from "../js/data_storage.js"; -// Most of the global objects can go here at first. -// It's a bit of overkill for simple components, -// but these instance would eventually have more children -// which would find the use for those extra properties. -const betaflightModel = { +/* + Most of the global objects can go here at first. + It's a bit of overkill for simple components, + but these instance would eventually have more children + which would find the use for those extra properties. + + FIXME For some reason, some of them (like PortHandler and FC) + need to be marked as reactive in it's own module, to detect + changes in arrays so I added the `reactive` wrapper there too. +*/ +const betaflightModel = reactive({ CONFIGURATOR, FC, MSP, PortUsage, PortHandler, -}; +}); -i18next.on('initialized', function() { +i18next.on("initialized", function () { console.log("i18n initialized, starting Vue framework"); const app = createApp({ - data() { return betaflightModel; }, + setup() { + return betaflightModel; + }, }); - app - .use(I18NextVue, { i18next }) - .component('BetaflightLogo', BetaflightLogo) - .component('BatteryLegend', BatteryLegend) - .component('StatusBar', StatusBar) - .component('BatteryIcon', BatteryIcon) - .component('PortPicker', PortPicker) - .mount('#main-wrapper'); + app.use(I18NextVue, { i18next }) + .component("BetaflightLogo", BetaflightLogo) + .component("BatteryLegend", BatteryLegend) + .component("StatusBar", StatusBar) + .component("BatteryIcon", BatteryIcon) + .component("PortPicker", PortPicker) + .mount("#main-wrapper"); - if (process.env.NODE_ENV === 'development') { + if (process.env.NODE_ENV === "development") { console.log("Development mode enabled, installing Vue tools"); // TODO Vue.config.devtools = true; app.config.performance = true; diff --git a/src/components/port-picker/FirmwareVirtualOption.vue b/src/components/port-picker/FirmwareVirtualOption.vue index 462a7e2e15..22c9793566 100644 --- a/src/components/port-picker/FirmwareVirtualOption.vue +++ b/src/components/port-picker/FirmwareVirtualOption.vue @@ -1,7 +1,13 @@ diff --git a/src/components/port-picker/PortOverrideOption.vue b/src/components/port-picker/PortOverrideOption.vue index ce7974deee..9559e14bee 100644 --- a/src/components/port-picker/PortOverrideOption.vue +++ b/src/components/port-picker/PortOverrideOption.vue @@ -1,44 +1,38 @@ diff --git a/src/components/port-picker/PortPicker.vue b/src/components/port-picker/PortPicker.vue index f973d5cd67..0bc32eeddf 100644 --- a/src/components/port-picker/PortPicker.vue +++ b/src/components/port-picker/PortPicker.vue @@ -3,28 +3,28 @@ diff --git a/src/components/port-picker/PortsInput.vue b/src/components/port-picker/PortsInput.vue index d671449b82..bfd9409d1d 100644 --- a/src/components/port-picker/PortsInput.vue +++ b/src/components/port-picker/PortsInput.vue @@ -3,20 +3,19 @@ @@ -124,7 +80,7 @@ diff --git a/src/components/quad-status/BatteryIcon.vue b/src/components/quad-status/BatteryIcon.vue index d80338e3cf..fea452f950 100644 --- a/src/components/quad-status/BatteryIcon.vue +++ b/src/components/quad-status/BatteryIcon.vue @@ -5,118 +5,92 @@ + -