feat: add src/state.mjs
This commit is contained in:
15
src/state.mjs
Normal file
15
src/state.mjs
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user