wasm

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 2 Imported by: 0

README

go-webassembly-helpers

Go helpers for communication with JavaScript properties, functions and DOM in the context of WebAssembly.

Documentation

👉 GoDoc

Todo

  • Readme
  • Many things

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateElement

func CreateElement(tagname string) js.Value

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

func DefineFunc(name string, function JSFunc)

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 Document

func Document() js.Value

Document returns the JS global document

func GetElementByID

func GetElementByID(id string) js.Value

GetElementByID retrieves an element in the DOM by its id (shortcut to Document().Call("getElementById", id)).

Types

type AttributeMap

type AttributeMap map[string]string

AttributeMap is a map of HTML attributes

type JSFunc

type JSFunc func(this js.Value, args []js.Value) interface{}

JSFunc type

type JSFuncMap

type JSFuncMap map[string]JSFunc

JSFuncMap type

func (*JSFuncMap) DefineAll

func (fm *JSFuncMap) DefineAll() *JSFuncMap

DefineAll sets JavaScript functions in the global scope according to the current *JSFuncMap

type JSPropMap

type JSPropMap map[string]interface{}

JSPropMap type

func (*JSPropMap) DefineAll

func (pm *JSPropMap) DefineAll() *JSPropMap

DefineAll sets JavaScript properties in the global scope according to the current *JSPropMap. It panics when trying to define a function, use DefineFuncMap() or *JSFuncMap.DefineAll() instead.

type Object

type Object struct {
	Value js.Value
}

Object wraps a javascript object js.Value, providing it some extended methods

func NewElement

func NewElement(tagname string) *Object

NewElement creates a new wrapped object from input tagname

func ObjectFrom

func ObjectFrom(v js.Value) *Object

ObjectFrom returns a wrapper of the input object js.Value to access some extended methods

func (*Object) AddClass

func (o *Object) AddClass(names ...string) *Object

AddClass adds classes to the *Object value and returns the *Object.

func (*Object) Call

func (o *Object) Call(name string, args ...interface{}) *Object

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

func (o *Object) Get(name string) js.Value

Get returns the queried JavaScript property p of value v.

func (*Object) GetAttribute

func (o *Object) GetAttribute(name string) string

GetAttribute returns the attribute of current *Object's value.

func (*Object) GetCall

func (o *Object) GetCall(name string, args ...interface{}) js.Value

GetCall calls an object's method and return its return value.

func (*Object) GetInvoke

func (o *Object) GetInvoke(args ...interface{}) js.Value

GetInvoke calls the current object if it is a function and panics otherwise. It returns its return value.

func (*Object) Invoke

func (o *Object) Invoke(args ...interface{}) *Object

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

func (o *Object) QuerySelector(sel string) js.Value

QuerySelector func

func (*Object) QuerySelectorAll

func (o *Object) QuerySelectorAll(sel string) js.Value

QuerySelectorAll func

func (*Object) RemoveClass

func (o *Object) RemoveClass(names ...string) *Object

RemoveClass removes classes to the *Object value and returns the *Object.

func (*Object) SetAttribute

func (o *Object) SetAttribute(name string, value string) *Object

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

func (o *Object) SetProp(name string, value interface{}) *Object

SetProp method

func (*Object) SetProps

func (o *Object) SetProps(pm PropMap) *Object

SetProps allows to set several properties in a single declaration using a map. Example: o.SetProps(wasm.PropMap{"textContent": "click me", "href": "./home.html"}

func (*Object) SetStyle

func (o *Object) SetStyle(name, value string) *Object

SetStyle sets current *Object value style name to value.

func (*Object) SetStyles

func (o *Object) SetStyles(styleMap StyleMap) *Object

SetStyles sets the *Object current value styles from a wadom.StyleMap.

type PropMap

type PropMap map[string]interface{}

PropMap is a map of JavaScript properties

type StyleMap

type StyleMap map[string]string

StyleMap is a map of style values

Jump to

Keyboard shortcuts

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