Surface / Drawing only what a Message can change

Draw only the parts of a page a Message can change

In a Foldkit application every event (a click, a key, a server's answer) is a Message. Your update function turns the Model, which is the application's state, and a Message into the next Model, and your view function then builds the whole page from it. So a key typed in a search box builds the header, the sidebar and twenty panels again, and Foldkit compares each with what is on the page to find that nothing changed. On a page with many parts, most of that work is for parts the Message never touched.

If you say which fields of the Model each Message writes, and which fields each part of the page reads, the two can be matched once, ahead of time. A Message then draws only the parts that read something it writes. A "drawing" here is one run of a part's view function.

foldkit-surface already has the reads: a Surface names a part of the page and the Model fields it reads (its README starts from nothing). foldkit-surface/writes adds the writes and joins the two. The test packages/surface/test/writes.test.ts runs five Surfaces through fifty Messages in a running Foldkit application and counts the drawings.

bash
pnpm add foldkit-surface @doeixd/metakit