jsutil

package
v0.0.0-...-5fe729b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Rendered for js/wasm

Overview

Package jsutil provides utility functions for interacting with native JavaScript APIs via syscall/js API. It has support for common types in honnef.co/go/js/dom/v2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(fn interface{}) js.Func

Wrap returns a wrapper func that handles the conversion from native JavaScript js.Value parameters to the following types.

It supports js.Value (left unmodified), dom.Document, dom.Element, dom.Event, dom.HTMLElement, dom.Node. It has to be one of those types exactly; it can't be another type that implements the interface like *dom.BasicElement.

For other types, the input is assumed to be a JSON string which is then unmarshalled into that type.

If the number of arguments provided to the wrapped func doesn't match the number of arguments for original func, it panics.

Here is example usage:

<span onclick="Handler(event, this, {{.SomeStruct | json}});">Example</span>

func Handler(event dom.Event, htmlElement dom.HTMLElement, data someStruct) {
	data.Foo = ... // Use event, htmlElement, data.
}

func main() {
	js.Global().Set("Handler", jsutil.Wrap(Handler))
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL