kept(k, d) reads magpie.<k> as JSON and gives d when nothing is stored,
when the value is a different kind from d, or when it can't be read.
keep(k, v) writes it, and a write that fails holds only for this time.
They replace eleven try/JSON.parse/getItem and setItem copies: the
discovery ignore list, model favourites, Usage's folds (usageOpen,
usageAccounts, usageAcctsOpened, usageKeysAll, usageAcctsAll) and the
panel's folded options. The three Usage fold reads, which were written
out twice, are now one usageFolds(). The star's write had no try at all.
This is the room for the next two commits (outloudvi's two masking
reports), so the app.js budget doesn't go up. app.js shrinks by 1,062
bytes, to 1,308,386 at eb6d1d8d9.
The panel's last allowances (magpie.panelQuotas) keep their own read and
write. quota-refresh-order runs loadQuotas in a vm with only localStorage
stubbed, and keep() isn't there.
Run on mote, at this tree on eb6d1d8d9:
- go test -tags nogui -run Budget ./internal/gui: ok.
- node --test on favorite-star, provider-discovery, panel-options-fold,
panel-quota-kept, usage-accounts-fold, usage-fold and usage-keys-fold,
both engines: 96/96.
- Inside the 124-file run listed in the next commit.
Broken by hand: kept() made to return d and keep() made a no-op. 27 of 48
chromium tests went red (panel-options-fold, panel-quota-kept,
provider-discovery's ignore tests, usage-accounts-fold, usage-fold and
usage-keys-fold). favorite-star stayed green because it doesn't reload.
Not tried: Linux WebKitGTK and Windows WebView2. One change in kind:
usageAccounts stored as an array now reads as {}, where before it was used
as an array.