jshelpers

package
v2.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsObject

func AsObject[T any](value js.Value) (*T, error)

AsObject converts a JS value to a go struct JS value must be an object Given Go struct must have "js" tags to specify fields mapping

func AsSlice

func AsSlice[T any](value js.Value) ([]T, error)

AsSlice converts a JS value to a slice of T value must be an array of a type handled by goValue

func FromObject

func FromObject(from any) js.Value

FromObject converts a Go struct to a JS Object Given Go struct must have "js" tags to specify fields mapping

func FromSlice

func FromSlice(from any) js.Value

FromSlice converts a Go slice to a JS Array

func NewError

func NewError(msg any) js.Value

func NewErrorWithCause

func NewErrorWithCause(msg any, cause any) js.Value

Types

type JsFunc

type JsFunc func(this js.Value, args []js.Value) any

JsFunc represent a function that can be converted to a js.Func using js.FuncOf

func AsPromise

func AsPromise(goFunc any) JsFunc

AsPromise convert a classic Go function to a function taking js arguments. arguments and return types must be types handled by this package function must return 2 variables, second one must be an error

func AsyncJsFunc

func AsyncJsFunc(innerFunc JsFuncWithError) JsFunc

type JsFuncWithError

type JsFuncWithError func(this js.Value, args []js.Value) (any, error)

JsFuncWithError is a JsFunc with an additional error returned, convert it to a promise with AsPromise

Jump to

Keyboard shortcuts

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