QORMQORM v0.8.4 api 开始使用 EN

Go 包:qormext

github.com/qorm/qorm/pkg/qormext 自动生成(TestAPIRef),请勿手工编辑。

唯一的公开 Go 包。应用用 Go 注册自己的原生操作,打包器将其编译进应用的单一可执行文件——桌面桥接把未知操作分发到这里。

import "github.com/qorm/qorm/pkg/qormext"

Package qormext is the user middle-layer registry. An app registers its OWN native ops (in Go) via native/desktop.go, which the packager compiles INTO the app's single executable. The desktop bridge dispatches unknown ops here.

Contract — the app's native/desktop.go:

package main
import "github.com/qorm/qorm/pkg/qormext"
func init() {
    qormext.Register("myOp", func(data map[string]any) string {
        // your Go logic; return one line of JS to run back in the app
        return `qormOnMyOp("done")`
    })
}

Functions

CallJS

func CallJS(script string)

CallJS runs a line of JS in the app's WebView (from the Go middle-layer).

CompatibleABI

func CompatibleABI(declared string) bool

CompatibleABI reports whether an app's declared plugin ABI (e.g. "1" or "1.2") is major-compatible with this runtime's ABIVersion. An empty/unset declaration is always compatible (the app uses no versioned middle-layer).

Emit

func Emit(event, dataJSON string)

Emit pushes a signal onto the frontend event channel: every qormOn(event) listener in the UI fires with dataJSON (a JSON value — "null" if empty). This is the middle-layer's push side: Go/WASM code tells the UI something changed and the frontend just listens, instead of the UI polling. Runs on desktop (via the evaluator) and in WASM (via eval) alike.

Native

func Native(op, dataJSON string)

Native triggers a framework low-level op (hardware bridge / built-in) directly from Go: e.g. Native("bluetoothScan", "{}") reaches the native bridge or Web API. Results arrive at the app's qormOn<X> JS callback.

Register

func Register(name string, fn Op)

Register adds a custom native op (call from an init() in native/desktop.go).

SetEvaluator

func SetEvaluator(fn func(string))

SetEvaluator wires the host's JS evaluator (desktop only).

Types

Op

type Op func(data map[string]any) string

Op handles a custom native op: it receives the qormToNative payload and returns a line of JS (e.g. qormOnFoo(...)) to eval back in the app, or "".