Skip to content

Commit e4f689e

Browse files
committed
Implement channel and component lifecycle fixes
This commit addresses the counter rerendering issue with several architectural improvements: 1. **Variable Hoisting**: Channels declared with make() are now hoisted to struct fields - Added type inference to detect channel creation expressions - Channels are initialized once in the constructor, not on every render - References updated to use field selectors (c.channel vs channel) 2. **Send Statement Fix**: Channel send operations now correctly reference hoisted variables - Modified generateStatement to check hoistedVars map for send statements - Generates c.channel <- value instead of channel <- value 3. **Nested Component Lifecycle**: Automatic BindApp invocation for child components - Child components wrapped in IIFE that calls BindApp before Render - Ensures channel listeners start for nested components - Passes parent app reference down to children 4. **Idempotent BindApp**: Prevents goroutine leaks from multiple BindApp calls - Added listenersStarted field to components with channel parameters - BindApp checks flag and returns early if listeners already running - Sets flag after starting listeners Changes: - pkg/codegen/codegen.go: Core hoisting and lifecycle logic - pkg/codegen/codegen_test.go: Updated test expectations - examples/counter/*_gen.go: Regenerated with new architecture All unit tests pass (29 tests). E2e tests show improvement (no crashes in some runs) but still have runtime issues that need further investigation.
1 parent 6971cd7 commit e4f689e

4 files changed

Lines changed: 281 additions & 34 deletions

File tree

examples/counter/app_gen.go

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/counter/counter_gen.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)