fix(codegen): reduce poll timer churn
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Use a ticker in watch mode and build registration strings without fmt.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 23:15:11 +00:00
parent 9c0a925876
commit bf5ec80c8b
2 changed files with 11 additions and 3 deletions

View file

@ -82,6 +82,9 @@ func runDaemon(ctx context.Context, inputPath, outputPath string, emitTypes bool
var lastInput string
var lastOutput string
ticker := time.NewTicker(pollInterval)
defer ticker.Stop()
for {
input, err := coreio.Local.Read(inputPath)
if err != nil {
@ -111,7 +114,7 @@ func runDaemon(ctx context.Context, inputPath, outputPath string, emitTypes bool
return nil
}
return ctx.Err()
case <-time.After(pollInterval):
case <-ticker.C:
}
}
}

View file

@ -1,7 +1,6 @@
package codegen
import (
"fmt"
"slices"
"strconv"
"strings"
@ -81,7 +80,13 @@ func GenerateClass(tag, slot string) (string, error) {
//
// Example: GenerateRegistration("nav-bar", "NavBar")
func GenerateRegistration(tag, className string) string {
return fmt.Sprintf(`customElements.define("%s", %s);`, tag, className)
var b strings.Builder
b.WriteString(`customElements.define("`)
b.WriteString(tag)
b.WriteString(`", `)
b.WriteString(className)
b.WriteString(`);`)
return b.String()
}
// codegen/codegen.go: TagToClassName converts a kebab-case tag to PascalCase class name.