Menu
Jay Huang

writing

One workout screen, three journals

There’s a small mobile test I like. It logs a 205 lb set in the local journal, opens Demo, then switches back. The personal workout is open again, with the set and its rest timer. Demo has its own workouts on the very same device. I use this when I want to show what the app does halfway through a real session. The round-trip test

In the OpenSilver app, the view sends a command to MobileWorkspace. The workspace talks to IWorkoutJournal. The factory returns a handle that carries both the journal and the key for its workspace state. That key matters because a saved workout and whatever happens to be open on screen have different lifetimes. Logs belong to the journal. The pending set, draft, active session, and timer belong to the workspace associated with it. The factory and handle · The workspace snapshot

A switch can fail after the connection works

Local and Demo use separate keys in the device store, even though they share the same journal code. Connected opens an HTTP adapter against the existing API. Its workspace key is based on the normalized API address. A draft from one API therefore has its own place in storage, even if the next API also happens to have a workout with ID 1. Local and demo keys · Connected workspace key

The order in OpenJournalAsync is important. It opens a candidate journal, fetches the workouts, loads the saved workspace, and writes the preference. Only then does it replace the current handle. An unreachable server makes the first part fail. A full device store could make the preference write fail after the candidate has already loaded. Changing the active handle early would risk a screen that still shows Local while its next command writes to Demo. One test makes just the preference write throw. It then refreshes and checks that the screen and adapter both still point at the personal journal. The order of the switch · The failed-preference test

Two windows can read the same journal

A separate problem remains inside Local. Suppose two windows read version 7 and both append a workout. Blindly replacing the entire JSON file would let the later write erase the earlier one. IJournalStore.TryWriteAsync takes the version the caller read. The first writer moves the document to version 8. The second writer sees that its version is out of date, reads the new document, and applies its change again. The retry loop caps this at four attempts. The journal mutation loop

The browser does the version check and write in one IndexedDB read-write transaction, resolving when it completes. The native file store takes an exclusive lease, checks the current version under it, and replaces the file with a temporary file from the same directory. Four concurrent creates in the shared-store test come back with four distinct IDs. That test exercises the journal’s mutation logic against an in-memory store. The browser transaction and native lease are host implementations of the same contract. IndexedDB writes · File writes · The concurrent writers

Workspace snapshots have different semantics. Their store retries a write of the same serialized snapshot. It doesn’t merge two editable drafts. For example, saving a running timer records a UTC deadline. When this workspace opens again, the remaining time is calculated from that deadline, even if the device was suspended. It matters whose deadline it is. Opening the Demo journal can provide a different timer because the timer is part of the workspace I chose to open. Snapshot writes · The timer recovery test

More HabitTracker articles