feat: update counter and todos to use automatic method dispatch#11
Merged
feat: update counter and todos to use automatic method dispatch#11
Conversation
Updates examples to use the new Controller pattern with automatic method dispatch instead of implementing the Store interface with a Change() switch statement. ## Changes ### counter/main.go - Removed `Change()` method with switch statement - Added individual action methods: `Increment()`, `Decrement()`, `Reset()` - Added documentation explaining the Controller pattern ### todos/main.go - Removed `Change()` method with switch statement - Added individual action methods: - `Add()` - creates a new todo - `Toggle()` - toggles completion status - `Delete()` - removes a todo - `Search()` - filters todos - `Sort()` - changes sort order - `NextPage()` / `PrevPage()` / `GotoPage()` - pagination - `ClearCompleted()` - removes completed todos - Added documentation explaining the pattern ## Benefits - Cleaner code with single-responsibility methods - Better IDE support (method completion, go-to-definition) - Actions support snake_case, camelCase, and case-insensitive matching - No boilerplate switch statement needed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the counter and todos examples to use the new Controller pattern with automatic method dispatch, eliminating the need for manual Change() switch statements.
- Replaces switch-based action routing with direct method dispatch
- Adds comprehensive documentation explaining the Controller pattern
- Cleans up unused dependencies from go.mod/go.sum
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| counter/main.go | Refactored from single Change() switch to individual Increment(), Decrement(), and Reset() methods with automatic dispatch |
| todos/main.go | Refactored from single Change() switch to nine individual action methods (Add(), Toggle(), Delete(), Search(), Sort(), NextPage(), PrevPage(), GotoPage(), ClearCompleted()) |
| counter/go.mod | Removed unused dependencies (charmbracelet, muesli, modelcontextprotocol, and other terminal UI libraries) |
| counter/go.sum | Updated checksums to reflect dependency removals |
| todos/go.mod | Removed same set of unused dependencies as counter |
| todos/go.sum | Updated checksums to reflect dependency removals |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The Handle() signature changed from Handle(stores ...Store) to
Handle(stores ...interface{}) in v0.5.1 to support the new automatic
method dispatch pattern.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
v0.5.2 includes the Handle(stores ...interface{}) API change that
supports automatic method dispatch without requiring the Store interface.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updates counter and todos examples to use the new Controller pattern with automatic method dispatch instead of implementing the
Storeinterface with aChange()switch statement.Depends on: livetemplate/livetemplate#66
Changes
counter/main.go
Change()method with switch statementIncrement(),Decrement(),Reset()todos/main.go
Change()method with switch statementAdd(),Toggle(),Delete(),Search(),Sort(),NextPage(),PrevPage(),GotoPage(),ClearCompleted()Before vs After
Test plan
🤖 Generated with Claude Code