MA10: Capstone: offline, usable and ready to release for KhetNote

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

Project 1: offline-first saving and sync

🎯You'll be able to

Complete Project 1: visits that save on the phone first, an outbox that survives restarts, and a sync engine that copes with lost answers, slow servers and conflicting edits.

🏠The everyday picture

A postman in a hill district writes each delivery in a notebook, even where there's no signal. Back in town, the notes go to the office one by one, each with its own number, so nothing is entered twice and nothing is lost if the bus is late.

📘What it really is

📝A worked example

Input: test 05 failing: "a change whose answer was lost is sent again, and the server keeps only one copy".

Steps:

  1. Read the test: the server stores the change, then the answer is lost, and the app sends it again.
  2. Check the engine: the starter sends no Idempotency-Key, so the server can't tell the second send is the same change.
  3. Give each outbox change a key when it's created, store it with the change, and send it as the header every time, then run npm run test:offline.

Expected output: test 05 passes; all ten pass in a few seconds in the reference.

🌍Where it's used

📝Case scenario

A learner's sync passed tests 1 to 6, then failed test 7: with the server set to slow, the app waited forever and the outbox didn't move on. Adding the 10-second timeout, and treating it as "try again later", fixed it. They added the case to their sync design.

🖱️Try it

Start the practice server with npm run server, set it to down with curl -X POST http://127.0.0.1:8095/_mode -d down, and write what you expect the app to do with two saved visits. Then set it to up. Success: your expectation matches tests 02 and 04.

⚠️Common mistakes

🛠️For your project

Project 1's evidence: the output of npm run test:offline with 10 passing, docs/sync-design.md, and a short note on which cases you tested by hand with the practice server.

✅Quick check

Why send the same idempotency key when a change is resent?

Show the answer

So the server can tell it's the same change and store it once.

What should the app do when a request gets no answer in 10 seconds?

Show the answer

Give up on that try and send the change again later, keeping it in the outbox.

← PreviousPlanning the capstone
ProLearners Assist