19 lines
977 B
TypeScript
19 lines
977 B
TypeScript
import type { ScadaReplay } from "../api/scada-replay-client";
|
|
|
|
/** Keep projection identity when polling only advances the replay clock. */
|
|
export function reuseScadaReadings(previous: ScadaReplay["latest"] | null | undefined, next: ScadaReplay["latest"]): ScadaReplay["latest"] {
|
|
if (previous?.length !== next.length) return next;
|
|
const unchanged = next.every((row, index) => {
|
|
const old = previous[index];
|
|
return old.device_id === row.device_id && old.time === row.time && old.quality === row.quality
|
|
&& old.reason === row.reason && Object.is(old.monitored_value, row.monitored_value)
|
|
&& Object.is(old.cleaned_value, row.cleaned_value);
|
|
});
|
|
return unchanged ? previous : next;
|
|
}
|
|
|
|
export function reuseReplayProjection(previous: ScadaReplay | null, next: ScadaReplay | null): ScadaReplay | null {
|
|
if (!next || previous?.replay_id !== next.replay_id) return next;
|
|
return { ...next, latest: reuseScadaReadings(previous.latest, next.latest) };
|
|
}
|