Array reactivity
This commit is contained in:
1 parent
bffa172a93
commit
b2ec264ede
1 file changed
+11
-9
+11
-9
@@ -80,9 +80,9 @@ function createStore() {
|
||||
voc_ppb: state.environment.live.voc_ppb,
|
||||
vpd: state.environment.live.vpd,
|
||||
};
|
||||
state.environment.history.push(reading);
|
||||
state.environment.history = [...state.environment.history, reading];
|
||||
if (state.environment.history.length > 1441) {
|
||||
state.environment.history.shift();
|
||||
state.environment.history = state.environment.history.slice(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +142,10 @@ function createStore() {
|
||||
voc_ppb: payload.voc_ppb ?? 0,
|
||||
vpd: calcVpd(ambient.temp_c, ambient.humidity_pct),
|
||||
};
|
||||
chamber.history.push(reading);
|
||||
if (chamber.history.length > HISTORY_MAX) chamber.history.shift();
|
||||
chamber.history = [...chamber.history, reading];
|
||||
if (chamber.history.length > HISTORY_MAX) {
|
||||
chamber.history = chamber.history.slice(1);
|
||||
}
|
||||
|
||||
// Mirror fruiting into the legacy global env.live / env.history for
|
||||
// the top-bar health score and any code still reading the pre-
|
||||
@@ -156,9 +158,9 @@ function createStore() {
|
||||
state.environment.live.vpd = calcVpd(ambient.temp_c, ambient.humidity_pct);
|
||||
if (payload.co2?.valid) state.environment.live.co2_ppm = payload.co2.ppm;
|
||||
|
||||
state.environment.history.push(reading);
|
||||
state.environment.history = [...state.environment.history, reading];
|
||||
if (state.environment.history.length > HISTORY_MAX) {
|
||||
state.environment.history.shift();
|
||||
state.environment.history = state.environment.history.slice(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,18 +177,18 @@ function createStore() {
|
||||
const existing = state.environment.alerts.find(a => a.id === anomaly.id);
|
||||
if (existing) return;
|
||||
|
||||
state.environment.alerts.push({
|
||||
state.environment.alerts = [...state.environment.alerts, {
|
||||
id: anomaly.id,
|
||||
type: anomaly.type,
|
||||
severity: anomaly.severity,
|
||||
message: anomaly.message,
|
||||
ts: anomaly.ts,
|
||||
dismissed: anomaly.dismissed,
|
||||
});
|
||||
}];
|
||||
|
||||
// Cap alerts list — keep newest 50
|
||||
if (state.environment.alerts.length > 50) {
|
||||
state.environment.alerts.shift();
|
||||
state.environment.alerts = state.environment.alerts.slice(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user