Skip to content

Commit 78c60da

Browse files
adnaanclaude
andauthored
feat(lvt): migrate templates to method dispatch pattern (#6)
Remove Store interface with Change() method in favor of automatic method dispatch. Actions now route to methods by name (e.g., action "increment" -> Increment() method). Changes: - Generator templates: Convert Change() switch to individual methods - Kit templates (simple, single, multi): Same pattern - Auth handler: Register, Login, MagicLink, ForgotPassword, SwitchView - E2E tests: LoadingTestState, FocusTestState migrated - Golden files and README updated BREAKING CHANGE: Generated code no longer uses Change() method. Existing apps must migrate to method dispatch pattern. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent d5105fb commit 78c60da

15 files changed

Lines changed: 1049 additions & 803 deletions

File tree

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -812,22 +812,30 @@ type State struct {
812812
// ...
813813
}
814814

815-
func (s *State) Change(ctx *livetemplate.ActionContext) error {
816-
switch ctx.Action {
817-
case "add":
818-
// Create user
819-
case "update":
820-
// Update user
821-
case "delete":
822-
// Delete user
823-
case "search":
824-
// Search users
825-
// ...
826-
}
815+
// Action methods - automatically dispatched based on action name
816+
func (s *State) Add(ctx *livetemplate.ActionContext) error {
817+
// Create user
818+
return nil
819+
}
820+
821+
func (s *State) Update(ctx *livetemplate.ActionContext) error {
822+
// Update user
823+
return nil
824+
}
825+
826+
func (s *State) Delete(ctx *livetemplate.ActionContext) error {
827+
// Delete user
828+
return nil
829+
}
830+
831+
func (s *State) Search(ctx *livetemplate.ActionContext) error {
832+
// Search users
833+
return nil
827834
}
828835

829836
func (s *State) Init() error {
830837
// Load initial data
838+
return nil
831839
}
832840

833841
func Handler(queries *models.Queries) http.Handler {

e2e/livetemplate_core_test.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,15 +1129,12 @@ func TestTemplate_E2E_CompleteRenderingSequence(t *testing.T) {
11291129
})
11301130
}
11311131

1132-
// LoadingTestState implements the Store interface for loading indicator E2E coverage.
1132+
// LoadingTestState implements state for loading indicator E2E coverage.
11331133
type LoadingTestState struct {
11341134
Message string
11351135
}
11361136

1137-
// Change satisfies the Store interface; loading tests do not mutate state.
1138-
func (s *LoadingTestState) Change(ctx *livetemplate.ActionContext) error {
1139-
return nil
1140-
}
1137+
// No action methods needed - loading tests do not mutate state.
11411138

11421139
// TestLoadingIndicator verifies the loading indicator appears serverside and disappears once the client boots.
11431140
func TestLoadingIndicator(t *testing.T) {
@@ -1377,12 +1374,9 @@ type FocusTestState struct {
13771374
Counter int
13781375
}
13791376

1380-
// Change applies focus test actions.
1381-
func (s *FocusTestState) Change(ctx *livetemplate.ActionContext) error {
1382-
switch ctx.Action {
1383-
case "increment":
1384-
s.Counter++
1385-
}
1377+
// Increment handles the "increment" action.
1378+
func (s *FocusTestState) Increment(_ *livetemplate.ActionContext) error {
1379+
s.Counter++
13861380
return nil
13871381
}
13881382

internal/generator/templates/app/home.go.tmpl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ type Resource struct {
2323
Type string `json:"type"`
2424
}
2525

26-
func (s *HomeState) Change(ctx *livetemplate.ActionContext) error {
27-
// No actions for home page yet
28-
return nil
29-
}
26+
// No action methods needed for home page (static)
3027

3128
// Handler creates an http.Handler for the home page
3229
func Handler() http.Handler {

0 commit comments

Comments
 (0)