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:
parent
5bd4e4ed6e
commit
0408768d35
3 changed files with 12 additions and 8 deletions
|
|
@ -467,9 +467,9 @@ sealed class Args
|
|||
[MessagePackObject]
|
||||
public sealed class CounterState
|
||||
{
|
||||
[Key("counterId")] public string CounterId { get; set; } = "";
|
||||
[Key("count")] public int Count { get; set; }
|
||||
[Key("receipts")] public Dictionary<string, IncrementReceipt> Receipts { get; set; } = new(StringComparer.Ordinal);
|
||||
[Key(0)] public string CounterId { get; set; } = "";
|
||||
[Key(1)] public int Count { get; set; }
|
||||
[Key(2)] public Dictionary<string, IncrementReceipt> Receipts { get; set; } = new(StringComparer.Ordinal);
|
||||
public static CounterState Initial(string counterId) => new() { CounterId = counterId };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ import {
|
|||
decodeCultNetPayload,
|
||||
} 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 {
|
||||
interface Window {
|
||||
__sampleReady?: boolean;
|
||||
|
|
@ -83,17 +87,17 @@ try {
|
|||
stateBindingResolver: async binding => {
|
||||
if (binding.pointerId !== "sample.counter.count") return undefined;
|
||||
return {
|
||||
latest: async () => decodeCultNetPayload<{ count: number }>(counter.current!).count,
|
||||
latest: async () => counterCount(counter.current!),
|
||||
watch: callback => counter.watch(record => {
|
||||
if (!record) return;
|
||||
const count = decodeCultNetPayload<{ count: number }>(record).count;
|
||||
const count = counterCount(record);
|
||||
window.__sampleCount = count;
|
||||
callback(count);
|
||||
}),
|
||||
};
|
||||
},
|
||||
});
|
||||
window.__sampleCount = decodeCultNetPayload<{ count: number }>(counter.current!).count;
|
||||
window.__sampleCount = counterCount(counter.current!);
|
||||
window.__sampleReady = true;
|
||||
} catch (error) {
|
||||
const details = error instanceof AggregateError
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ using MessagePack;
|
|||
[MessagePackObject]
|
||||
public sealed class CounterState
|
||||
{
|
||||
[Key("counterId")] public string CounterId { get; set; } = "";
|
||||
[Key("count")] public int Count { get; set; }
|
||||
[Key(0)] public string CounterId { get; set; } = "";
|
||||
[Key(1)] public int Count { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue