Skip to content

Commit f2c6c8b

Browse files
pedrolamasclaude
andauthored
refactor: freeze immutable entries (#1875)
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d978cac commit f2c6c8b

10 files changed

Lines changed: 30 additions & 25 deletions

File tree

src/store/announcements/mutations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Vue from 'vue'
21
import type { MutationTree } from 'vuex'
32
import { defaultState } from './state'
43
import type { AnnouncementsState } from './types'
@@ -36,6 +35,6 @@ export const mutations = {
3635
}
3736
}
3837

39-
Vue.set(state, 'entries', entries)
38+
state.entries = entries
4039
}
4140
} satisfies MutationTree<AnnouncementsState>

src/store/config/mutations.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const mutations = {
5151
(dest, src) => Array.isArray(dest) ? src : undefined
5252
)
5353

54-
Vue.set(state, 'uiSettings', mergedSettings)
54+
state.uiSettings = mergedSettings
5555
}
5656
},
5757

@@ -107,7 +107,7 @@ export const mutations = {
107107
})
108108
}
109109
localStorage.setItem(Globals.LOCAL_INSTANCES_STORAGE_KEY, JSON.stringify(instances))
110-
Vue.set(state, 'instances', instances)
110+
state.instances = instances
111111
},
112112

113113
setUpdateInstanceName (state, payload) {
@@ -120,12 +120,10 @@ export const mutations = {
120120
},
121121

122122
setRemoveInstance (state, payload) {
123-
const instances = state.instances
124-
const i = instances.findIndex((instance: InstanceConfig) => instance.apiUrl === payload.apiUrl)
125-
if (i >= 0) {
126-
instances.splice(i, 1)
127-
Vue.set(state, 'instances', instances)
128-
localStorage.setItem(Globals.LOCAL_INSTANCES_STORAGE_KEY, JSON.stringify(instances))
123+
const index = state.instances.findIndex((instance: InstanceConfig) => instance.apiUrl === payload.apiUrl)
124+
if (index >= 0) {
125+
state.instances.splice(index, 1)
126+
localStorage.setItem(Globals.LOCAL_INSTANCES_STORAGE_KEY, JSON.stringify(state.instances))
129127
}
130128
},
131129

src/store/console/mutations.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const mutations = {
3636
while (state.console.length >= Globals.CONSOLE_HISTORY_RETENTION) {
3737
state.console.shift()
3838
}
39-
state.console.push(entry)
39+
state.console.push(Object.freeze(entry))
4040
},
4141

4242
/**
@@ -45,6 +45,7 @@ export const mutations = {
4545
setAllEntries (state, payload: ConsoleEntry[]) {
4646
state.consoleEntryCount = payload.length
4747
state.console = payload
48+
.map(entry => Object.freeze(entry))
4849
},
4950

5051
setResetPromptDialog (state, payload: string) {
@@ -162,6 +163,6 @@ export const mutations = {
162163
},
163164

164165
setLastCleared (state) {
165-
Vue.set(state, 'lastCleared', Date.now())
166+
state.lastCleared = Date.now()
166167
}
167168
} satisfies MutationTree<ConsoleState>

src/store/database/mutations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Vue from 'vue'
21
import type { MutationTree } from 'vuex'
32
import { defaultState } from './state'
43
import type { DatabaseInfo, DatabaseState } from './types'
@@ -10,7 +9,7 @@ export const mutations = {
109
},
1110

1211
setServerDatabaseList (state, payload: DatabaseInfo) {
13-
Vue.set(state, 'info', payload)
12+
state.info = payload
1413
},
1514

1615
setServerDatabasePostBackup (state, payload: { backup_path: string }) {

src/store/files/mutations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const mutations = {
2121
}
2222

2323
if (state.currentPaths[root]) {
24-
Vue.set(state.currentPaths, root, undefined)
24+
Vue.delete(state.currentPaths, root)
2525
}
2626
},
2727

src/store/macros/mutations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ export const mutations = {
9393
},
9494

9595
setExpanded (state, expanded: number[]) {
96-
Vue.set(state, 'expanded', expanded)
96+
state.expanded = expanded
9797
}
9898
} satisfies MutationTree<MacrosState>

src/store/notifications/mutations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const mutations = {
3434
},
3535

3636
setClearAllNotifications (state) {
37-
Vue.set(state, 'notifications', [...state.notifications.filter(n => !n.clear)])
37+
state.notifications = state.notifications
38+
.filter(n => !n.clear)
3839
}
3940
} satisfies MutationTree<NotificationsState>

src/store/power/mutations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Vue from 'vue'
21
import type { MutationTree } from 'vuex'
32
import type { DevicePowerState } from './types'
43
import { defaultState } from './state'
@@ -19,7 +18,7 @@ export const mutations = {
1918
for (const key in payload) {
2019
const i = state.devices.findIndex(device => device.device === key)
2120
if (i >= 0) {
22-
Vue.set(state.devices[i], 'status', payload[key])
21+
state.devices[i].status = payload[key]
2322
}
2423
}
2524
}

src/store/sensors/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export const actions = {
1212
SocketActions.serverSensorsList()
1313
},
1414

15-
async onSensorsList ({ commit }, payload: { sensors: Moonraker.Sensor.ListResponse }) {
15+
async onSensorsList ({ commit }, payload: Moonraker.Sensor.ListResponse) {
1616
if (payload) {
1717
commit('setSensorsList', payload)
1818
}
1919
},
2020

21-
async onSensorUpdate ({ commit }, payload: Record<string, Moonraker.Sensor.Entry>) {
21+
async onSensorUpdate ({ commit }, payload: Record<string, Moonraker.Sensor.Values>) {
2222
if (payload) {
2323
commit('setSensorUpdate', payload)
2424
}

src/store/sensors/mutations.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Vue from 'vue'
21
import type { MutationTree } from 'vuex'
32
import type { MoonrakerSensorsState } from './types'
43
import { defaultState } from './state'
@@ -12,12 +11,21 @@ export const mutations = {
1211
},
1312

1413
setSensorsList (state, payload: Moonraker.Sensor.ListResponse) {
15-
state.sensors = payload.sensors
14+
state.sensors = Object.fromEntries(
15+
Object.entries(payload.sensors)
16+
.map(([key, entry]) => [
17+
key,
18+
{
19+
...entry,
20+
values: Object.freeze(entry.values)
21+
}
22+
])
23+
)
1624
},
1725

18-
setSensorUpdate (state, payload: Record<string, Moonraker.Sensor.Entry>) {
26+
setSensorUpdate (state, payload: Record<string, Moonraker.Sensor.Values>) {
1927
for (const sensorKey in payload) {
20-
Vue.set(state.sensors[sensorKey], 'values', payload[sensorKey])
28+
state.sensors[sensorKey].values = Object.freeze(payload[sensorKey])
2129
}
2230
}
2331
} satisfies MutationTree<MoonrakerSensorsState>

0 commit comments

Comments
 (0)