Lentil Hoffman 50ac2b7b35
refactor: rename Lossless to Hyperview and Lossy to View
- Renamed Lossless class to Hyperview for clarity
- Renamed Lossy class to View for simplicity
- Updated all imports and references throughout the codebase
- Updated documentation to reflect new terminology
- Fixed test files to use new class names
- Added proper exports in index files
2025-07-09 14:28:52 -05:00

43 lines
1.0 KiB
TypeScript

import { PropertyTypes } from "../../../../core/types";
import { CollapsedDelta } from "../../../hyperview";
import { ResolverPlugin } from "../plugin";
type FirstWriteWinsState = {
value?: PropertyTypes;
timestamp: number;
};
/**
* First Write Wins plugin
*
* Keeps the first value that was written, ignoring subsequent writes
*/
export class FirstWriteWinsPlugin extends ResolverPlugin<FirstWriteWinsState> {
readonly dependencies = [] as const;
initialize(): FirstWriteWinsState {
return { timestamp: Infinity };
}
update(
currentState: FirstWriteWinsState,
newValue: PropertyTypes,
delta: CollapsedDelta,
): FirstWriteWinsState {
// Only update if this delta is earlier than our current earliest
if (delta.timeCreated < currentState.timestamp) {
return {
value: newValue,
timestamp: delta.timeCreated
};
}
return currentState;
}
resolve(
state: FirstWriteWinsState,
): PropertyTypes | undefined {
return state.value;
}
}