refactor: Vuex state factory export - #1952
Conversation
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
Bundle size report (gzip)
119 chunks compared, 21 changed. Sizes are gzip, matching what nginx serves. |
There was a problem hiding this comment.
🟢 Approval recommended
The refactor consistently updates state exports, resets, and consumers to use state factories, and the RootState typing change aligns with the new convention.
Pull request overview
Refactors Vuex module state exports to consistently use factory functions (instead of exporting a shared static state object), and updates call sites/types accordingly to keep module state initialization/reset behavior consistent across the app.
Changes:
- Convert many
src/store/**/state.tsexports fromdefaultState()/state = defaultState()toexport const state = () => ({ ... }). - Update mutations and UI call sites to import the factory (
{ state as defaultState }) and invoke it when cloning defaults or resetting state. - Update
RootStatetype derivation to useReturnType<module['state']>now that state is consistently a function.
File summaries
| File | Description |
|---|---|
| src/views/Diagnostics.vue | Switch layout defaults import to state factory for cloning default diagnostics card config. |
| src/store/webcams/state.ts | Export webcams Vuex state as a factory function. |
| src/store/webcams/mutations.ts | Update reset/default import to use state factory. |
| src/store/wait/state.ts | Export wait Vuex state as a factory function. |
| src/store/wait/mutations.ts | Update reset/default import to use state factory. |
| src/store/version/state.ts | Export version Vuex state as a factory function. |
| src/store/version/mutations.ts | Update reset/default import to use state factory. |
| src/store/types.ts | Derive RootState via ReturnType<module['state']> to match state-as-factory convention. |
| src/store/timelapse/state.ts | Export timelapse Vuex state as a factory function. |
| src/store/timelapse/mutations.ts | Update reset/default import to use state factory. |
| src/store/spoolman/state.ts | Export spoolman Vuex state as a factory function. |
| src/store/spoolman/mutations.ts | Update reset/default import to use state factory. |
| src/store/socket/state.ts | Export socket Vuex state as a factory function. |
| src/store/socket/mutations.ts | Update reset/default import to use state factory. |
| src/store/server/state.ts | Export server Vuex state as a factory function. |
| src/store/server/mutations.ts | Update reset/default import to use state factory. |
| src/store/sensors/state.ts | Export sensors Vuex state as a factory function. |
| src/store/sensors/mutations.ts | Update reset/default import to use state factory. |
| src/store/printer/state.ts | Export printer Vuex state as a factory function. |
| src/store/printer/mutations.ts | Update reset/default import to use state factory. |
| src/store/power/state.ts | Export power Vuex state as a factory function. |
| src/store/power/mutations.ts | Update reset/default import to use state factory. |
| src/store/notifications/state.ts | Export notifications Vuex state as a factory function. |
| src/store/notifications/mutations.ts | Update reset/default import to use state factory. |
| src/store/mmu/state.ts | Export mmu Vuex state as a factory function. |
| src/store/mmu/mutations.ts | Update reset/default import to use state factory. |
| src/store/mesh/state.ts | Export mesh Vuex state as a factory function. |
| src/store/mesh/mutations.ts | Update reset/default import to use state factory. |
| src/store/macros/state.ts | Export macros Vuex state as a factory function. |
| src/store/macros/mutations.ts | Update reset/default import to use state factory. |
| src/store/layout/state.ts | Export layout Vuex state as a factory function. |
| src/store/layout/mutations.ts | Update reset/init logic to use state factory (and its layouts) for defaults/migration. |
| src/store/jobQueue/state.ts | Export jobQueue Vuex state as a factory function. |
| src/store/jobQueue/mutations.ts | Update reset/default import to use state factory. |
| src/store/history/state.ts | Export history Vuex state as a factory function. |
| src/store/history/mutations.ts | Update reset/default import to use state factory. |
| src/store/gcodePreview/state.ts | Export gcodePreview Vuex state as a factory function. |
| src/store/gcodePreview/mutations.ts | Update reset/default import to use state factory. |
| src/store/files/state.ts | Export files Vuex state as a factory function. |
| src/store/files/mutations.ts | Update reset/default import to use state factory. |
| src/store/database/state.ts | Export database Vuex state as a factory function. |
| src/store/database/mutations.ts | Update reset/default import to use state factory. |
| src/store/console/state.ts | Export console Vuex state as a factory function. |
| src/store/console/mutations.ts | Update reset/default import to use state factory. |
| src/store/config/state.ts | Export config Vuex state as a factory function. |
| src/store/config/mutations.ts | Update reset/default import to use state factory. |
| src/store/charts/state.ts | Export charts Vuex state as a factory function. |
| src/store/charts/mutations.ts | Update reset/default import to use state factory. |
| src/store/auth/state.ts | Export auth Vuex state as a factory function. |
| src/store/auth/mutations.ts | Update reset/default import to use state factory. |
| src/store/announcements/state.ts | Export announcements Vuex state as a factory function. |
| src/store/announcements/mutations.ts | Update reset/default import to use state factory. |
| src/store/analysis/state.ts | Export analysis Vuex state as a factory function. |
| src/store/analysis/mutations.ts | Update reset/default import to use state factory. |
| src/store/afc/state.ts | Export afc Vuex state as a factory function. |
| src/store/afc/mutations.ts | Update reset/default import to use state factory. |
| src/components/widgets/diagnostics/config/MetricsConfigStep.vue | Switch layout defaults import to state factory for deriving the default diagnostics card config. |
| src/components/settings/WarningsSettings.vue | Switch config defaults import to state factory for default UI settings values. |
| src/components/settings/ToolheadSettings.vue | Switch config defaults import to state factory for default general/toolhead UI settings values. |
| src/components/settings/SpoolmanSettings.vue | Switch config defaults import to state factory for default spoolman UI settings values. |
| src/components/settings/MmuSettings.vue | Switch config defaults import to state factory for default mmu UI settings values. |
| src/components/settings/GcodePreviewSettings.vue | Switch config defaults import to state factory for default gcode preview UI settings values. |
| src/components/settings/FileEditorSettings.vue | Switch config defaults import to state factory for default editor UI settings values. |
| src/components/layout/AppBar.vue | Switch layout defaults import to state factory for default layout data used by UI actions. |
Review details
- Files reviewed: 64/64 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
There was a problem hiding this comment.
🟢 Approval recommended
The refactor is consistent across modules/callers and correctly switches Vuex module state to factory functions without leaving stale defaultState/static state usages.
Review details
- Files reviewed: 91/91 changed files
- Comments generated: 0 new
- Review effort level: Lite
Refactor Vuex state to always use a factory instead of static value.