hlive
hlive copied to clipboard
Hello world input not working
v0.2.0 branch
Per the quickstart
package main
import (
"context"
"fmt"
"log"
"net/http"
l "github.com/SamHennessy/hlive"
)
const port = 3000
// Step 1
// func home() *l.Page {
// page := l.NewPage()
// page.DOM().Body().Add("Hello, world.")
// return page
// }
// Step 2
func home() *l.Page {
var message string
input := l.NewComponent("input")
input.Add(l.Attrs{"type": "text"})
input.Add(l.On("keyup", func(ctx context.Context, e l.Event) {
message = e.Value
}))
page := l.NewPage()
page.DOM().Body().Add(l.NewTag("div", input))
page.DOM().Body().Add(l.T("hr"))
page.DOM().Body().Add("Hello, ", &message)
return page
}
// Step 2.1
// func home() *l.Page {
// var message string
//
// input := l.C("input",
// l.Attrs{"type": "text"},
// l.On("keyup", func(_ context.Context, e l.Event) {
// message = e.Value
// }),
// )
//
// page := l.NewPage()
// page.DOM().Body().Add(
// l.T("div", input),
// l.T("hr"),
// "Hello, ", &message,
// )
//
// return page
// }
func main() {
http.Handle("/", l.NewPageServer(home))
addr := fmt.Sprintf(":%d", port)
log.Printf("Listing on %s.", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
log.Println("Error: http listen and serve:", err)
}
}
on first keystroke in the input you receive errors
7:32AM ERR invalid node callers="runtime.goexit:1594 > net/http.(*conn).serve:1991 > net/http.serverHandler.ServeHTTP:2947 > net/http.(*ServeMux).ServeHTTP:2487 > github.com/SamHennessy/hlive.(*PageServer).ServeHTTP:38 > main.home:35 > github.com/SamHennessy/hlive.(*Component).Add:207 > github.com/SamHennessy/hlive.(*Tag).Add:269 > github.com/SamHennessy/hlive.addElementToTag:360 > github.com/SamHennessy/hlive.addElementToTag:441 > github.com/SamHennessy/hlive.(*NodeGroup).Add:174" node=(*string)(0xc00018a030)
7:32AM ERR invalid node callers="runtime.goexit:1594 > net/http.(*conn).serve:1991 > net/http.serverHandler.ServeHTTP:2947 > net/http.(*ServeMux).ServeHTTP:2487 > github.com/SamHennessy/hlive.(*PageServer).ServeHTTP:48 > main.home:35 > github.com/SamHennessy/hlive.(*Component).Add:207 > github.com/SamHennessy/hlive.(*Tag).Add:269 > github.com/SamHennessy/hlive.addElementToTag:360 > github.com/SamHennessy/hlive.addElementToTag:441 > github.com/SamHennessy/hlive.(*NodeGroup).Add:174" node=(*string)(0xc000017390)
7:32AM ERR invalid node callers="runtime.goexit:1594 > net/http.(*conn).serve:1991 > net/http.serverHandler.ServeHTTP:2947 > net/http.(*ServeMux).ServeHTTP:2487 > github.com/SamHennessy/hlive.(*PageServer).ServeHTTP:38 > main.home:35 > github.com/SamHennessy/hlive.(*Component).Add:207 > github.com/SamHennessy/hlive.(*Tag).Add:269 > github.com/SamHennessy/hlive.addElementToTag:360 > github.com/SamHennessy/hlive.addElementToTag:441 > github.com/SamHennessy/hlive.(*NodeGroup).Add:174" node=(*string)(0xc0000b8210)
Appears
https://github.com/SamHennessy/hlive/blob/2a1de9ceddaa9e3563c1c97e41ea3bdb9e75de8d/hlive.go#L115
is the culprit as *string isn't valid. Going to fork and try to fix.
just so you know I'm deep into not just fixing this but a host of issues, DM'd on slack