angular · Medium · autosave state machine
An editor saves drafts in the background. A slow confirmation for an older revision currently marks the latest text as saved, and an older failure can replace the current status.
Task
Reduce edit, save, success and failure events into a truthful draft status.
Contract
Input is {events}. edit carries revision and text; save, success and failure carry revision. Return {text,revision,status,error}. Status is idle, dirty, saving, saved or failed.
Acceptance criteria
- Only the latest revision may become saved or failed.
- Saving an old revision does not change current status.
- Editing clears the previous error.
- Success must match both the current revision and latest save attempt.
Constraints
- Do not mutate caller-owned input.
- Keep the supplied framework adapter and public contract unchanged.
- Add candidate tests for at least one boundary not covered by the public cases.
Editable files
src/repair.js— Task-specific state or service boundarytests/candidate.test.js— Candidate-authored regression