Give the counter sample integer MessagePack keys

CounterState in samples/eve-browser-network used string [Key]s, which the
registry rejects at registration, so the provider threw on open. Keys are now
0 counterId, 1 count, 2 receipts. The payload becomes a MessagePack array, so
the browser lowerer reads count positionally instead of by field name. The
getting-started chapter carried the same string-key shape and is corrected to
match.

BenchItem needed nothing: a5d1be6 already marked it [MessagePackObject]; the
earlier scan rejection came from a stale benchmark build. After rebuilding,
both types register.

No .cc stores exist under samples.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-14 00:27:19 +02:00
commit 0408768d35
3 changed files with 12 additions and 8 deletions

View file

@ -467,9 +467,9 @@ sealed class Args
[MessagePackObject] [MessagePackObject]
public sealed class CounterState public sealed class CounterState
{ {
[Key("counterId")] public string CounterId { get; set; } = ""; [Key(0)] public string CounterId { get; set; } = "";
[Key("count")] public int Count { get; set; } [Key(1)] public int Count { get; set; }
[Key("receipts")] public Dictionary<string, IncrementReceipt> Receipts { get; set; } = new(StringComparer.Ordinal); [Key(2)] public Dictionary<string, IncrementReceipt> Receipts { get; set; } = new(StringComparer.Ordinal);
public static CounterState Initial(string counterId) => new() { CounterId = counterId }; public static CounterState Initial(string counterId) => new() { CounterId = counterId };
} }

View file

@ -7,6 +7,10 @@ import {
decodeCultNetPayload, decodeCultNetPayload,
} from "cultmesh-browser"; } from "cultmesh-browser";
// CounterState is an integer-keyed MessagePack object: [counterId, count, receipts].
const counterCount = (record: Parameters<typeof decodeCultNetPayload>[0]) =>
decodeCultNetPayload<[string, number, unknown]>(record)[1];
declare global { declare global {
interface Window { interface Window {
__sampleReady?: boolean; __sampleReady?: boolean;
@ -83,17 +87,17 @@ try {
stateBindingResolver: async binding => { stateBindingResolver: async binding => {
if (binding.pointerId !== "sample.counter.count") return undefined; if (binding.pointerId !== "sample.counter.count") return undefined;
return { return {
latest: async () => decodeCultNetPayload<{ count: number }>(counter.current!).count, latest: async () => counterCount(counter.current!),
watch: callback => counter.watch(record => { watch: callback => counter.watch(record => {
if (!record) return; if (!record) return;
const count = decodeCultNetPayload<{ count: number }>(record).count; const count = counterCount(record);
window.__sampleCount = count; window.__sampleCount = count;
callback(count); callback(count);
}), }),
}; };
}, },
}); });
window.__sampleCount = decodeCultNetPayload<{ count: number }>(counter.current!).count; window.__sampleCount = counterCount(counter.current!);
window.__sampleReady = true; window.__sampleReady = true;
} catch (error) { } catch (error) {
const details = error instanceof AggregateError const details = error instanceof AggregateError

View file

@ -15,8 +15,8 @@ using MessagePack;
[MessagePackObject] [MessagePackObject]
public sealed class CounterState public sealed class CounterState
{ {
[Key("counterId")] public string CounterId { get; set; } = ""; [Key(0)] public string CounterId { get; set; } = "";
[Key("count")] public int Count { get; set; } [Key(1)] public int Count { get; set; }
} }
``` ```