debug go-app in nowasm
gepengscu opened this issue · comments
The difficulty in debugging wasm has limited the development of go-app. Here are a few suggestions for debugging wasm in nowasm mode. I'm not sure if they are feasible or not.
- Public the private methods in app.Value interface, or permit registering callback functions which are called by the private functions.
- Define a DOM object for running unit test in nowasm mode.
I guess you mean it limits your development using Go-App?
Could you give an example what is problematic for you to get right? Are you trying to combine "normal" JavaScript libraries with Go-App?
We generally do not have problems with debugging and bug fixing for our steadily growing applications that are from using WASM / Go-App. Sure, a step debugger that links back to the Go source would be nice, but using our print logging with stack traces works very well for us and writing smaller example applications before using new functionalities in a larger project makes things also more manageable.
P.S.: If you need some private Methods, just check out the Go-App code and use a "go.work" file in the project. Then you can add all the debugging you need. This possibility is one of the reasons why we use Go in the company.
I use the following codes in unit test. The code is mostly effective in logical testing. I think that it will be nice if a go side DOM is supported in go-app nowasm mode.
package tester
import (
"fmt"
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
func CValue(v any) Value {
return value{
Value: app.ValueOf(v),
value: v,
methods: make(map[any]func(args ...any) app.Value),
}
}
type (
Value interface {
app.Value
Methods(map[string]func(args ...any) app.Value) Value
}
value struct {
app.Value
value any
methods map[any]func(args ...any) app.Value
}
)
func (v value) Methods(m map[string]func(args ...any) app.Value) Value {
for k, f := range m {
v.methods[k] = f
}
return v
}
func (v value) Call(m string, args ...any) app.Value {
if f, ok := v.methods[m]; ok {
return f(args...)
}
fmt.Println("unknown function ", m)
return CValue(v.value)
}
func (v value) IsNull() bool {
return v.value == nil
}
This is logic test.
func TestFundamentals(t *testing.T) {
v := Fundamentals(0)
canvas := tester.CValue(map[any]any{
"width": 100,
"height": 100,
}).Methods(map[string]func(args ...any) app.Value{
"getContext": func(args ...any) app.Value {
//name := args[0].(string)
//attrs := args[1]
return tester.CValue(map[any]any{}).
Methods(map[string]func(args ...any) app.Value{
"getParameter": func(args ...any) app.Value {
return tester.CValue(map[any]any{})
},
"getExtension": func(args ...any) app.Value {
return tester.CValue(map[any]any{})
},
"createTexture": func(args ...any) app.Value {
return tester.CValue(map[any]any{})
},
"bindTexture": func(args ...any) app.Value {
return tester.CValue(map[any]any{})
},
"texParameteri": func(args ...any) app.Value {
return tester.CValue(map[any]any{})
},
})
},
"addEventListener": func(args ...any) app.Value {
return tester.CValue(map[any]any{})
},
"removeEventListener": func(args ...any) app.Value {
return tester.CValue(map[any]any{})
},
})
v.Run(canvas)
}
What is 'go-app nowasm mode'? Do you mean using the Go-App declarative HTML generation? Isn't this a totally bloated way to create a standard HTML web server?