gjs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MPL-2.0 Imports: 5 Imported by: 0

README

✨ GJS ✨

Comprehensive API for Webassembly environment

Create a fork Github Actions made-with-Go GoReportCard Go.mod version LICENCE Latest release

About

GJS provides a comprehensive API to access the WebAssembly host environment when using the js/wasm architecture. Its API is based on JavaScript semantics and provides WebAssembly interop between Go and JS values. Its current scope is to provide a comprehensive and well-tested API.

Install

GOOS=js GOARCH=wasm go get github.com/chumaumenze/gjs

Usage

package main

import "github.com/chumaumenze/gjs"

type Data struct {
    Code    int
	Message string `json:"message"`
    inner   any
}

func main() {
    data := Data{
        Code: 200,
		Message: "Hello World!",
        inner: "I am ignored",
	}
	v := gjs.ValueOf(data) // e.g. {Code: 200, "message": "Hello World!"}
}

Motivations

The Go standard library's syscall/js package offers limited compatibility between Go and JavaScript values.

  • The js.Value type lacks support for interfaces or assignment methods for complex Go values.
  • The js.ValueOf function cannot handle complex types like structs, leading to a panic with the error message ValueOf: invalid value.

To overcome these limitations, gjs builds upon and extends the functionality of syscall/js.

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

View Source
var (
	Global  = js.Global()
	Array   = Global.Get("Array")
	Object  = Global.Get("Object")
	Console = Global.Get("console")
	Promise = Global.Get("Promise")
)

Functions

func Promisify

func Promisify(jsFunc PromiseHandlerFunc) js.Value

func RecoverPanics

func RecoverPanics(callback any)

Types

type CallerInfo

type CallerInfo struct {
	File       string
	LineNumber int
	FuncName   string
}

func GetCallerInfo

func GetCallerInfo(skip int) CallerInfo

func (*CallerInfo) String

func (c *CallerInfo) String() string

type PromiseHandlerFunc

type PromiseHandlerFunc func(resolve, reject js.Value)

type Value

type Value js.Value

func ValueOf

func ValueOf(v any) Value

func (Value) Into

func (v Value) Into() js.Value

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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