-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2: Create with support for both GopherJS and GOOS=js GOARCH=wasm. #57
Comments
I have attempted to do this in this branch |
@yml Thanks for looking at this and sharing your work. I think that's a great step forward. The approach I'd like us to use for My proposed approach is for us to have separate files, one with That way, the @@ -131,74 +131,76 @@ type Event interface {
PreventDefault()
StopImmediatePropagation()
StopPropagation()
- Underlying() *js.Object
+ Underlying() js.Value
} We'll need to maintain and keep in sync two files rather than one, but I think that's the only viable way to proceed. Luckily, this package is mostly complete and doesn't change much, so it's not a very high cost. If that makes sense to you, and if you'd like, feel free to make a PR with that approach. Otherwise, I or someone else can get around to it later. From the yml#1 description, you said you only tested that it compiles. One of the additional steps we'll need to do, before we can merge a PR into this package, is test that it functions as expected. |
@dominikh, in PR #59, you said:
(I wanted to move the discussion here, so the PR discussion can stay focused on the approach described in the PR description.) I would like to avoid it too, but out of all alternatives, it seems the least bad. I'm happy to hear any suggestions that are better. I'm aware of the following alternatives (that do not seem better):
Basically, with this solution, we are creating 2 separate |
I think I've found a potentially show-stopping problem with implementing this issue. This package relies very heavily on the Lines 1802 to 1811 in 6da835b
Wasm has no support for this feature (the only way to access fields is via the That means the current |
I guess the alternative is to change these fields to be a method with the same name. These is yet another difference in the API with the gopherjs equivalent. The question is how much of API differences can we tolerate under the same import path before feeling clunky. |
I fear none. I assume @shurcooL was aiming for equal api so that it won’t be a breaking change, just an additional implementation. |
ACK. If the APIs are different, they should be different packages, i.e. different import paths. |
Agreed. @dominikh How do you feel about a The API would be the same as v1, except current |
Ugh. Fine. |
Just to confirm, you're effectively referring to a |
The import path was conceived with Go modules ( If I understand correctly, it should be compatible with module-less Go 1.10 and intersect well with Go modules after that's released (1.11 and onwards). Does that sound like a reasonable approach @myitcv, or is there something you'd suggest changing? I'm not yet very familiar with Go modules and how one is supposed to create packages for it. |
Given the |
I have an update on this. @hajimehoshi has added support for the When we last attempted this in PR #59, we discovered a blocking problem that a significant breaking API change will be necessary, and so we'll need to use a different import path per the semantic import versioning convention, to avoid breaking existing programs importing the current v1 API. I've taken the previous work by @yml in PR #59 and implemented the following changes on top of it:
In my testing, the new v2 API is fully functional with Go WebAssembly and GopherJS. I have not found any major problems. I'll send a PR for it now (crediting @yml as a co-author). |
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>
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 necessity: - 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) - GetBoundingClientRect() returns *Rect instead of ClientRect Update GetBoundingClientRect to return DOMRect instead of the legacy ClientRect. A breaking API change was needed to make it return a pointer rather than a value, so it was a good opportunity to also update the type at the same time. There is a remaining TODO in window.RequestAnimationFrame method to make it so that canceling 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. Document API stability; v2 is currently in alpha and more API changes may be done before it exits alpha state. This implementation was based on work done by @yml in Pull Request #59. Fixes #57. Co-authored-by: Yann Malet <yann.malet@gmail.com> Co-authored-by: Dominik Honnef <dominik@honnef.co> GitHub-Pull-Request: #69
Go is getting Wasm support in 1.11: https://tip.golang.org/doc/go1.11#wasm.
A lot of frontend Go code uses this package, so supporting
js/wasm
would be very helpful.The text was updated successfully, but these errors were encountered: