Documentation ¶
Overview ¶
Package wasm provides some helpers to facilitate communication between JavaScript DOM/globals and Go, in the context of WebAssembly. For now it is an incomplete collection of experiments and it is not meant to be used in production.
Index ¶
- func CreateElement(tagname string) js.Value
- func Define(name string, value interface{})
- func DefineFunc(name string, function JSFunc)
- func DefineFuncMap(funcMap JSFuncMap)
- func DefineMap(propMap map[string]interface{})
- func Document() js.Value
- func GetElementByID(id string) js.Value
- type AttributeMap
- type JSFunc
- type JSFuncMap
- type JSPropMap
- type Object
- func (o *Object) AddClass(names ...string) *Object
- func (o *Object) Call(name string, args ...interface{}) *Object
- func (o *Object) Get(name string) js.Value
- func (o *Object) GetAttribute(name string) string
- func (o *Object) GetCall(name string, args ...interface{}) js.Value
- func (o *Object) GetInvoke(args ...interface{}) js.Value
- func (o *Object) Invoke(args ...interface{}) *Object
- func (o *Object) QuerySelector(sel string) js.Value
- func (o *Object) QuerySelectorAll(sel string) js.Value
- func (o *Object) RemoveClass(names ...string) *Object
- func (o *Object) SetAttribute(name string, value string) *Object
- func (o *Object) SetAttributes(am AttributeMap) *Object
- func (o *Object) SetProp(name string, value interface{}) *Object
- func (o *Object) SetProps(pm PropMap) *Object
- func (o *Object) SetStyle(name, value string) *Object
- func (o *Object) SetStyles(styleMap StyleMap) *Object
- type PropMap
- type StyleMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateElement ¶
CreateElement return a new js.Value element with the input tagname (shortcut to Document().Call("createElement", tagname).
func Define ¶
func Define(name string, value interface{})
Define sets a JavaScript property with given name and value. The value cannot be a function and panics in this case, use DefineFunc instead.
func DefineFunc ¶
DefineFunc sets a JavaScript function with given name in the global scope.
func DefineFuncMap ¶
func DefineFuncMap(funcMap JSFuncMap)
DefineFuncMap sets JavaScript functions in the global scope according to the input JSFuncMap
func DefineMap ¶
func DefineMap(propMap map[string]interface{})
DefineMap sets a JavaScript properties according to the given map. Map values cannot be a function and panics in this case, use DefineFuncMap instead.
func GetElementByID ¶
GetElementByID retrieves an element in the DOM by its id (shortcut to Document().Call("getElementById", id)).
Types ¶
type Object ¶
Object wraps a javascript object js.Value, providing it some extended methods
func NewElement ¶
NewElement creates a new wrapped object from input tagname
func ObjectFrom ¶
ObjectFrom returns a wrapper of the input object js.Value to access some extended methods
func (*Object) Call ¶
Call calls an object's method and returns the current object. The result of the called method is is ignored. Example: o.Call("setAttribute", "role", "search").SetProp(...)
func (*Object) GetAttribute ¶
GetAttribute returns the attribute of current *Object's value.
func (*Object) GetInvoke ¶
GetInvoke calls the current object if it is a function and panics otherwise. It returns its return value.
func (*Object) Invoke ¶
Invoke calls the current object if it is a function and panics otherwise. It ignores its return value and return the current *Object instead. (Use GetInvoke() if that return value is needed)
func (*Object) QuerySelector ¶
QuerySelector func
func (*Object) QuerySelectorAll ¶
QuerySelectorAll func
func (*Object) RemoveClass ¶
RemoveClass removes classes to the *Object value and returns the *Object.
func (*Object) SetAttribute ¶
SetAttribute sets HTML attribute name to value and returns the current *Object.
func (*Object) SetAttributes ¶
func (o *Object) SetAttributes(am AttributeMap) *Object
SetAttributes sets HTML attribute from given AttributeMap and returns the current *Object.
func (*Object) SetProps ¶
SetProps allows to set several properties in a single declaration using a map. Example: o.SetProps(wasm.PropMap{"textContent": "click me", "href": "./home.html"}