Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug go-app in nowasm #946

Closed
gepengscu opened this issue Apr 9, 2024 · 4 comments
Closed

debug go-app in nowasm #946

gepengscu opened this issue Apr 9, 2024 · 4 comments

Comments

@gepengscu
Copy link

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.

  1. Public the private methods in app.Value interface, or permit registering callback functions which are called by the private functions.
  2. Define a DOM object for running unit test in nowasm mode.
@oderwat
Copy link
Sponsor Contributor

oderwat commented Apr 9, 2024

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.

@gepengscu
Copy link
Author

gepengscu commented Apr 10, 2024

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)
}

@oderwat
Copy link
Sponsor Contributor

oderwat commented Apr 10, 2024

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?

@gepengscu
Copy link
Author

Go.work is a good idea.Thank you @oderwat very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants