vugu: github.com/vugu/vugu/js Index | Files

package js

import "github.com/vugu/vugu/js"

Package js is a drop-in replacement for syscall/js that provides identical behavior in a WebAssembly environment, and useful non-functional behavior outside of WebAssembly.

To use it, simply import this package instead of "syscall/js" and use it in exactly the same way. Your code will compile targeting either wasm or non-wasm environments. In wasm, the functionality is exactly the same, the calls and types are delegated directly to "syscall/js". The compiler will optimize away virtually (if not literally) all of the overhead associated with this aliasing. When run outside of wasm, appropriate functionality indicates that the environment is not availble: All js.Value instances are undefined. Global(), Value.Get() always return undefined. Value.Call(), FuncOf() and other such functions will panic. Value.Truthy() will always return false. For example, Global().Truthy() can be used to determine if the js environment is functional.

Rationale: Since syscall/js is only available when the GOOS is "js", this means programs which run server-side cannot access that package and will fail to compile. Since Vugu components are inherently closely integrated with browsers and may often need to do things like declare variables of type js.Value, this is a problem for components which are rendered not only in wasm client-side but also server-side. Build tags can be used to provide multiple implementations of a components but this can become tedious.

Usually what you want is that the majority of your code which is not js-specific can be written once and execute in the browser or on the server, and the relatively small amount of functionality that is uses "js" will compile properly in both environments but just not be executed on the server. Or allow for if statements to easily disable functionality not available server-side. That's what this package provides.

Index

Package Files

doc.go impl-nonjs.go

func CopyBytesToGo Uses

func CopyBytesToGo(dst []byte, src Value) int

CopyBytesToGo placeholder for syscall/js

func CopyBytesToJS Uses

func CopyBytesToJS(dst Value, src []byte) int

CopyBytesToJS placeholder for syscall/js

type Error Uses

type Error struct {
    Value
}

Error placeholder for syscall/js

func (Error) Error Uses

func (e Error) Error() string

Error placeholder for syscall/js

type Func Uses

type Func struct {
    Value
}

Func placeholder for syscall/js

func FuncOf Uses

func FuncOf(fn func(Value, []Value) interface{}) Func

FuncOf placeholder for syscall/js

func (Func) Release Uses

func (c Func) Release()

Release placeholder for syscall/js

type Type Uses

type Type int

Type placeholder for syscall/js

const (
    TypeUndefined Type = iota
    TypeNull
    TypeBoolean
    TypeNumber
    TypeString
    TypeSymbol
    TypeObject
    TypeFunction
)

Placeholder for syscall/js

func (Type) String Uses

func (t Type) String() string

String placeholder for syscall/js

type Value Uses

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

Value placeholder for syscall/js

func Global Uses

func Global() Value

Global placeholder for syscall/js

func Null Uses

func Null() Value

Null placeholder for syscall/js

func Undefined Uses

func Undefined() Value

Undefined placeholder for syscall/js

func ValueOf Uses

func ValueOf(x interface{}) Value

ValueOf placeholder for syscall/js

func (Value) Bool Uses

func (v Value) Bool() bool

func (Value) Call Uses

func (v Value) Call(m string, args ...interface{}) Value

func (Value) Float Uses

func (v Value) Float() float64

func (Value) Get Uses

func (v Value) Get(p string) Value

func (Value) Index Uses

func (v Value) Index(i int) Value

func (Value) InstanceOf Uses

func (v Value) InstanceOf(t Value) bool

func (Value) Int Uses

func (v Value) Int() int

func (Value) Invoke Uses

func (v Value) Invoke(args ...interface{}) Value

func (Value) JSValue Uses

func (v Value) JSValue() Value

JSValue placeholder for syscall/js

func (Value) Length Uses

func (v Value) Length() int

func (Value) New Uses

func (v Value) New(args ...interface{}) Value

func (Value) Set Uses

func (v Value) Set(p string, x interface{})

func (Value) SetIndex Uses

func (v Value) SetIndex(i int, x interface{})

func (Value) String Uses

func (v Value) String() string

func (Value) Truthy Uses

func (v Value) Truthy() bool

func (Value) Type Uses

func (v Value) Type() Type

Type placeholder for syscall/js

type ValueError Uses

type ValueError struct {
    Method string
    Type   Type
}

ValueError placeholder for syscall/js

func (*ValueError) Error Uses

func (e *ValueError) Error() string

Error placeholder for syscall/js

type Wrapper Uses

type Wrapper interface {
    JSValue() Value
}

Wrapper placeholder for syscall/js

Package js imports 1 packages (graph) and is imported by 1 packages. Updated 2019-09-19. Refresh now. Tools for package owners.