feat: add src/state.mjs

This commit is contained in:
2026-09-25 11:57:07 +08:00
parent 74e10f772a
commit 48a412e5be

15
src/state.mjs Normal file
View File

@@ -0,0 +1,15 @@
export function advance(state, event) {
const next = { ...state, anomalies: [...state.anomalies] };
if (event.type === 'ALARM') {
if (next.open) next.anomalies.push('duplicate alarm');
else { next.open = true; next.firstAlarm = event.time; next.acknowledged = false; }
} else if (event.type === 'ACK') {
if (!next.open) next.anomalies.push('ack without alarm');
else if (next.acknowledged) next.anomalies.push('duplicate ack');
else next.acknowledged = true;
} else if (event.type === 'CLEAR') {
if (!next.open) next.anomalies.push('clear without alarm');
else { next.open = false; next.closedAt = event.time; }
}
return next;
}