jsbridge

package
v1.3.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMismatchedInputLength the length of input are mismatched
	ErrMismatchedInputLength = errors.New("binder: mismatched input length")

	// ErrMismatchedOutputLength the length of output are mismatched
	ErrMismatchedOutputLength = errors.New("binder: mismatched output length")

	// ErrBinderNotImplemented the type binder is not implemented yet
	ErrBinderNotImplemented = errors.New("binder: not impelmented")

	// ErrFuncNotSupported the type function is not supported yet
	ErrFuncNotSupported = errors.New("func: not supported")

	// ErrIsNotFunc bind works with func only
	ErrIsNotFunc = errors.New("func: bind works with func only")
)
View Source
var (
	TypeFunc   = reflect.TypeOf(func() {}).String()
	TypeError  = reflect.TypeOf(errors.New("type")).String()
	TypeString = reflect.TypeOf("string").String()
)

Functions

func Await

func Await(awaitable js.Value) ([]js.Value, []js.Value)

This function try to execute wasm functions that are wrapped with "Promise" see: https://stackoverflow.com/questions/68426700/how-to-wait-a-js-async-function-from-golang-wasm/68427221#comment120939975_68427221

func BindFunc

func BindFunc(jsFuncName string, fn interface{}) error

BindFunc bind go func to js func in global only support - func(...) - func(...) error - func(...) T - func(...) (T,error)

func BindFuncs

func BindFuncs(fnList map[string]interface{}) error

func Close

func Close()

func NewJsError

func NewJsError(message string) map[string]string

Types

type AsyncInvoker

type AsyncInvoker func(resolve, reject js.Value, fn reflect.Value, in []reflect.Value)

func Async

func Async(funcType reflect.Type) (AsyncInvoker, error)

type InputBinder

type InputBinder func([]js.Value) ([]reflect.Value, error)

InputBinder convert inputs from js.Value to reflect.Value

type InputBuilder

type InputBuilder struct {
	IsVariadic bool
	// contains filtered or unexported fields
}

InputBuilder binder builder

func NewInputBuilder

func NewInputBuilder(fn reflect.Type) *InputBuilder

NewInputBuilder create InputBuilder

func (*InputBuilder) Bind

func (b *InputBuilder) Bind(args []js.Value) ([]reflect.Value, error)

Bind bind js inputs to reflect values

func (*InputBuilder) Build

func (b *InputBuilder) Build() (InputBinder, error)

Build build InputBinder js.ValueOf returns x as a JavaScript value:

| Go                     | JavaScript             |
| ---------------------- | ---------------------- |
| js.Value               | [its value]            |
| js.Func                | function               |
| nil                    | null                   |
| bool                   | boolean                |
| integers and floats    | number                 |
| string                 | string                 |
| []interface{}          | new array              |
| map[string]interface{} | new object             |

Panics if x is not one of the expected types.

type OutputBinder

type OutputBinder func([]reflect.Value) []js.Value

OutputBinder convert Outputs from js.Value to reflect.Value

type OutputBuilder

type OutputBuilder struct {
	// contains filtered or unexported fields
}

OutputBuilder binder builder

func NewOutputBuilder

func NewOutputBuilder(fn reflect.Type) *OutputBuilder

NewOutputBuilder create OutputBuilder

func (*OutputBuilder) Bind

func (b *OutputBuilder) Bind(args []reflect.Value) []js.Value

Bind bind js Outputs to reflect values

func (*OutputBuilder) Build

func (b *OutputBuilder) Build() (OutputBinder, error)

Build build OutputBinder js.ValueOf returns x as a JavaScript value:

| Go                     | JavaScript             |
| ---------------------- | ---------------------- |
| js.Value               | [its value]            |
| js.Func                | function               |
| nil                    | null                   |
| bool                   | boolean                |
| integers and floats    | number                 |
| string                 | string                 |
| []interface{}          | new array              |
| map[string]interface{} | new object             |

Panics if x is not one of the expected types.

Jump to

Keyboard shortcuts

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