import { NO_HISTORY } from "../domain/practice/history.ts"; import { NO_MEMORY } from "../domain/practice/memory.ts"; import { EMPTY_MODEL } from "../domain/practice/model.ts"; import { recordAnswer, type Answer } from "../domain/practice/record.ts"; import { historyStore, memoryStore, modelStore } from "./practice-stores.ts"; import { recordPractice } from "./streak-store.ts"; /** * Write one answer into this browser: the one place a sitting, the warm-up * and the test all go through. What an answer touches, and why a test answer * touches less, is decided in `lib/domain/practice/record.ts`. * * Read at the call, not subscribed to: a sitting that re-rendered on its own * writes would rebuild under the learner's hands. */ export function commitAnswer( answer: Answer, now: Date = new Date(), /** Other questions about the same subject, so a review asked in another form moves the card that was due. */ siblings: readonly { id: string; kind: Answer["item"]["kind"] }[] = [], ): void { const recorded = recordAnswer( { history: historyStore.read() ?? NO_HISTORY, model: modelStore.read() ?? EMPTY_MODEL, memory: memoryStore.read() ?? NO_MEMORY }, answer, now, siblings, ); if (recorded.history) historyStore.write(recorded.history); if (recorded.model) modelStore.write(recorded.model); if (recorded.memory) memoryStore.write(recorded.memory); if (recorded.practised) recordPractice(now); }