feat(broadcast): migrate to Subscribe(SelfTopic())+Publish#102
Conversation
Phase 5 of the broadcast-action-redesign proposal removes ctx.BroadcastAction from livetemplate in v0.10.0. This PR migrates the examples monorepo to the new opt-in peer-fanout pattern: - Mount: ctx.Subscribe(ctx.SelfTopic()) - Actions: ctx.Publish(ctx.SelfTopic(), "ActionName", data) Bumps livetemplate pin v0.9.0 → v0.9.2 (where Subscribe / Publish / SelfTopic shipped via Phase 1). Migrated 4 apps (11 BroadcastAction call sites): - chat/main.go (UserJoined / NewMessage / UserLeft) - shared-notepad/main.go (Refresh) - landing-demo/main.go (Increment / Decrement / Reset; new Mount) - todos/controller.go (RefreshTodos × 4) Also reworded the BroadcastAction subtest in landing-demo/landing_demo_test.go (t.Run name "BroadcastAction_Propagates_To_Peer_Tab" → "Publish_Propagates_To_Peer_Tab"; skip message updated). Test remains skipped — the chromedp peer-tab issue tracked at #94 is independent of the broadcast→publish rename. Substring grep across the repo for "BroadcastAction" returns zero matches. Lands BEFORE livetemplate v0.10.0 — the migrated code uses Subscribe / Publish / SelfTopic which already ship in v0.9.2, so this PR builds and tests cleanly against the current published library. Once livetemplate v0.10.0 ships, re-pin and the apps continue to work without further changes. Refs livetemplate#415 (broadcast-action-redesign proposal) Refs livetemplate#429 (Phase 5 livetemplate-side PR)
Code ReviewOverview: This PR migrates all examples from the deprecated
|
Address the claude-review concern about partial-mutation semantics when Publish returns an error after the primary mutation has already committed. The behavior is intentional: under the new Subscribe/Publish primitive, the only errors Publish can actually return are programmer errors (empty SelfTopic from a misconfigured Authenticator, or MaxPublishesPerAction cap exceeded). Surfacing these loudly is a feature — the alternative (log-and-swallow) hides real configuration bugs that would otherwise silently break multi-tab sync. Added a comment at chat/main.go's first Publish call site explaining the rationale; the same propagation pattern is intentional at every other Publish site in the repo. No behavior change; comment-only. Refs livetemplate#415 (broadcast-action-redesign proposal) Refs livetemplate#429 (Phase 5 livetemplate-side PR)
|
Thanks for the careful read on the propagation question — this is a real semantic shift from the old Decision: keep propagation. Rationale committed inline at The errors that
Surfacing these loudly via This matches the convention applied in livetemplate#429's own test controllers + The minor |
Code Review: feat(broadcast): migrate to Subscribe(SelfTopic())+PublishOverviewClean, mechanical migration from the removed Strengths
Issues & Suggestions1. Behavior change: mutated state returned alongside
|
|
Thanks for the round-2 review. Quick walkthrough of the items, all addressable by reply per CLAUDE.md "decline with a PR reply, never silently": Item 1 (state-on-error semantics): This was the R1 concern; rationale documented inline at Item 2 ( Item 3 ( Item 4 (long comment in No push needed — convergence by CLAUDE.md heuristic: R2 raised the same item 1 concern from R1, no new functional issues, items 2-4 are non-blocking style/pre-existing observations. Ready for merge pending maintainer signoff. |
Phase 5 of the broadcast-action-redesign proposal removes
ctx.BroadcastActionfrom livetemplate in v0.10.0. This PR migrates the examples monorepo to the new opt-in peer-fanout pattern:ctx.Subscribe(ctx.SelfTopic())ctx.Publish(ctx.SelfTopic(), "ActionName", data)Bumps livetemplate pin v0.9.0 → v0.9.2 (Subscribe / Publish / SelfTopic already ship in v0.9.2 via Phase 1).
Migrated apps
chat/main.goUserJoined/NewMessage/UserLeftshared-notepad/main.goRefreshlanding-demo/main.goIncrement/Decrement/Reset; newMountmethod added to establish the Subscribetodos/controller.goRefreshTodos× 4Plus comment rewording in
landing-demo/landing_demo_test.go(skipped subtest renamedBroadcastAction_Propagates_To_Peer_Tab→Publish_Propagates_To_Peer_Tab).Verification
go build ./...— cleango vet ./...— cleanBroadcastActionreturns zero matchesOrdering
This PR is intentionally landed before livetemplate v0.10.0:
Test Examples against Core Changesjob builds the currentexamples/mainagainst the open Phase-5 livetemplate worktree)Refs livetemplate#415 (broadcast-action-redesign proposal)
Refs livetemplate#429 (Phase 5 livetemplate-side PR)
🤖 Generated with Claude Code