Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brettlangdon/go-dom
Web API package for use when compling Go to WASM
https://github.com/brettlangdon/go-dom
dom go golang wasm web webassembly
Last synced: about 1 month ago
JSON representation
Web API package for use when compling Go to WASM
- Host: GitHub
- URL: https://github.com/brettlangdon/go-dom
- Owner: brettlangdon
- Created: 2018-09-23T17:00:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-25T13:44:33.000Z (about 6 years ago)
- Last Synced: 2024-06-20T08:20:45.168Z (5 months ago)
- Topics: dom, go, golang, wasm, web, webassembly
- Language: Go
- Homepage:
- Size: 416 KB
- Stars: 8
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: history.go
Awesome Lists containing this project
README
go-dom
------**This package is a work in progress**
The `go-dom` package exposes the [Web API Spec](https://spec.whatwg.org/) as a Go package.
This package is mostly just wrappers around calls to [syscall/js](https://tip.golang.org/pkg/syscall/js/)
to expose the browser Web API in a Go friendly manner.This package's code is generated from [WebIDL](https://heycam.github.io/webidl/) definitions for the various Web API Specs.
## Examples
These examples can be compiled and run using `GOARCH=wasm GOOS=js` as described at https://github.com/golang/go/wiki/WebAssembly
Find all `div` elements and print them to the console
```go
package mainimport (
"github.com/brettlangdon/go-dom/console"
"github.com/brettlangdon/go-dom/document"
)func main() {
nodes := document.QuerySelectorAll("div")
for i := 0; i < nodes.GetLength(); i++ {
console.Dir(nodes.Item(0))
}
}
```Add a `click` handler to `document` which prints the event information.
```go
package mainimport (
dom "github.com/brettlangdon/go-dom"
"github.com/brettlangdon/go-dom/console"
"github.com/brettlangdon/go-dom/document"
)func main() {
loop := dom.NewLoop()document.AddEventListener("click", dom.NewEventHandler(func(evt dom.Event) {
console.Dir(evt)
}))loop.Loop()
}
```This last example uses a `dom.Loop` which is used to keep the program running instead of exiting.
If the Go program exits then the callback handlers will no longer execute.
Calling `loop.Stop()` will cause the Go program to exit.