Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

var CURRENT_VERSION string = "v2.17.3"
var CURRENT_VERSION string = "v2.17.4"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Expand Down
16 changes: 16 additions & 0 deletions pkg/wasm/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ func CreateWasmFunc(name string, fn func()) {}
func CreateWasmStringFunc(name string, fn func(string)) {}
func CreateWasmBoolFunc(name string, fn func(bool)) {}

// CreateWasmFuncWithReturn registers a named global JS function that can return a value back to JS.
// Wraps syscall/js.FuncOf. Use when a JS library expects a callback that returns a value
// synchronously (e.g. option objects, formatters, renderers). The function persists for the
// lifetime of the page. Returns a JSValue so it can be passed directly to JS object properties.
//
// Example:
//
// // Register a callback and pass it as a property on a JS config object:
// cb := CreateWasmFuncWithReturn("myCallback", func(this JSValue, args []JSValue) any {
// return args[0].String() + "_suffix"
// })
// config.Set("formatter", cb)
func CreateWasmFuncWithReturn(name string, fn func(this JSValue, args []JSValue) any) JSValue {
return JSValue{}
}

// ── Topic infrastructure (generated code only — not part of the user API) ────

// TopicKey is a typed key used by the auto-generated topic system.
Expand Down
18 changes: 18 additions & 0 deletions pkg/wasm/wasm-runtime/runtime/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,21 @@ func CreateWasmBoolFunc(name string, fn func(bool)) {
})
})
}

// CreateWasmFuncWithReturn registers a named global JS function that can return a value back to JS.
// Wraps syscall/js.FuncOf. The returned JSValue holds the js.Func so it can be passed
// directly to JS object properties (chart configs, map renderers, etc.) that require a
// synchronous return value. The js.Func is retained in keep and never released — it must
// stay alive for the lifetime of the page; releasing it would panic on the next invocation.
func CreateWasmFuncWithReturn(name string, fn func(this JSValue, args []JSValue) any) JSValue {
f := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
jsArgs := make([]JSValue, len(args))
for i, a := range args {
jsArgs[i] = JSValue{a}
}
return toJSVal(fn(JSValue{this}, jsArgs))
})
keep = append(keep, f)
js.Global().Set(name, f)
return JSValue{f.Value}
}
2 changes: 2 additions & 0 deletions pkg/wasm/wasm-runtime/runtime/events_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ package runtime
func CreateWasmFunc(name string, fn func()) {}
func CreateWasmStringFunc(name string, fn func(string)) {}
func CreateWasmBoolFunc(name string, fn func(bool)) {}

func CreateWasmFuncWithReturn(name string, fn func(this JSValue, args []JSValue) any) JSValue { return JSValue{} }
Loading