hexops / vecty

Vecty lets you build responsive and dynamic web frontends in Go using WebAssembly, competing with modern web frameworks like React & VueJS.
BSD 3-Clause "New" or "Revised" License
2.79k stars 143 forks source link

Make error for "TypeError: setting getter-only property "list"" clearer #238

Closed electricface closed 5 years ago

electricface commented 5 years ago

The following code can reproduce the problem:

package main

import (
    "github.com/gopherjs/vecty"
    "github.com/gopherjs/vecty/elem"
)

func main() {
    vecty.RenderBody(&MyComponent{})
}

type MyComponent struct {
    vecty.Core
}

func (mc *MyComponent) Render() vecty.ComponentOrHTML {
    return elem.Body(
        elem.Input(
            vecty.Markup(
                vecty.Property("list", "datalist1"),
            ),
        ),
    )
}

console error:

TypeError: setting getter-only property "list" ..js:9392:37
    Set http://localhost:8080/..js:9392
    Set http://localhost:8080/..js:9394
    reconcileProperties http://localhost:8080/..js:8039
    reconcile http://localhost:8080/..js:7964
    render http://localhost:8080/..js:8978
    reconcileChildren http://localhost:8080/..js:8344
    reconcile http://localhost:8080/..js:7969
    renderComponent http://localhost:8080/..js:9102
    RenderBody http://localhost:8080/..js:9322
    main http://localhost:8080/..js:9669
    $init http://localhost:8080/..js:9693
    $goroutine http://localhost:8080/..js:1478
    $runScheduled http://localhost:8080/..js:1518
    $schedule http://localhost:8080/..js:1534
    $go http://localhost:8080/..js:1510
    <anonymous> http://localhost:8080/..js:9704
    <anonymous> http://localhost:8080/..js:9707

The current solution is to modify the list property by calling the setAttribute method on the focus event.

pdf commented 5 years ago

If you want to set an attribute rather than a property, use vecty.Attribute() instead of vecty.Property().

electricface commented 5 years ago

Already solved, thank you very much.