Skip to content

Commit

Permalink
v2: add dom package
Browse files Browse the repository at this point in the history
This change implements the starting point of a new v2 major version
of the dom package.

It is now implemented on top of the syscall/js API, which is supported
by Go WebAssembly and GopherJS (as of version 1.12-2). The design goal
has been to stay as close as possible to v1 API to make the transition
easier to make. The only changes that were done were out of neccessity:

- All struct fields with `js:"foo"` tags have been replaced with
  equivalent methods
- Underlying() returns js.Value instead of *js.Object
- AddEventListener() returns js.Func instead of func(*js.Object)

There is a remaining TODO in window.RequestAnimationFrame method
to make it so that cancelling the callback via CancelAnimationFrame
makes it so the js.Func wrapper's Release method is called. Arranging
this is difficult (it requires either having an internal map and sync
primitive for tracking js.Func by IDs, or changing the return value of
the RequestAnimationFrame method from int to something where the
js.Func and its Release method can be accessed easily.

The current implementation is functional but may end up using more
memory in some situations. It's not blocking for the initial alpha
release, so it remains a TODO for now.

This implementation was based on work done in by @yml in
Pull Request #59.

Fixes #57.

Co-authored-by: Yann Malet <yann.malet@gmail.com>
  • Loading branch information
dmitshur and yml committed May 18, 2019
1 parent d6d651d commit cd0da75
Show file tree
Hide file tree
Showing 5 changed files with 3,718 additions and 4 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
# js/dom

Package dom provides GopherJS bindings for the JavaScript DOM APIs.
Package dom provides Go bindings for the JavaScript DOM APIs.

## Install
## Version 2

Version 2 of package dom is implemented on top of the [`syscall/js`](https://godoc.org/syscall/js) API and supports both Go WebAssembly and GopherJS.

It provides an API that is as close as possible to v1, with the following neccessary changes:

- All struct fields with `js:"foo"` tags have been replaced with equivalent methods
- `Underlying()` returns `js.Value` instead of `*js.Object`
- `AddEventListener()` returns `js.Func` instead of `func(*js.Object)`

### Install

go get honnef.co/go/js/dom/v2

### Documentation

For documentation, see https://godoc.org/honnef.co/go/js/dom/v2.

## Version 1

Version 1 of package dom is implemented on top of the [`github.com/gopherjs/gopherjs/js`](https://godoc.org/github.com/gopherjs/gopherjs/js) API and supports GopherJS only.

### Install

go get honnef.co/go/js/dom

## Documentation
### Documentation

For documentation, see http://godoc.org/honnef.co/go/js/dom
For documentation, see https://godoc.org/honnef.co/go/js/dom.
Loading

0 comments on commit cd0da75

Please sign in to comment.