go-kivik / kivik

Common interface to CouchDB or CouchDB-like databases for Go and GopherJS
Other
312 stars 44 forks source link

pouchdb: GOARCH=wasm GOOS=js #667

Open elliott5 opened 6 years ago

elliott5 commented 6 years ago

The release of go1.11beta1 heralds the imminent arrival of the GOARCH=wasm GOOS=js target.

In the long term I expect the WASM to supersede GopherJS, but in the medium term both will be used side-by-side.

So this issue is to ask for your thoughts on targeting both WASM & GopherJS targets.

There are some notes from someone who has done it already at: https://github.com/ncw/oxo3d/tree/master/oxo3dwasm#notes-on-converting-gopherjs---gowasm

I'm guessing the key issue is to confine these issues to a single file, with two versions.

elliott5 commented 6 years ago

https://github.com/gopherjs/gopherwasm aims to provide a common API for both platforms.

flimzy commented 6 years ago

Thanks for bringing up the issue! I fully think a WASM target should be supported by Kivik.

Having said that, while I've been watch the WASM support for Go evolve with much interest, I have not yet even attempted to use it, and probably won't for a while, just due to time constraints. But if you, or someone else, would be interested in producing a PR (either using gopherwasm, or native go/wasm support), I'd love to merge it.

One comment makes me wonder if the gopherwasm approach would be appropriate for this project--this driver already wraps async PouchDB calls to make them more Go-idiomatic sync calls. Maybe that wouldn't be a problem at all, but it might not play nicely with whatever sync/async model/abstraction gopherwasm provides. I won't really know until I investigate.

flimzy commented 6 years ago

I spent some time today playing with compiling this package for WASM, and ran into an unexpected problem. Go 1.11's syscall/js library doesn't provide access to the this variable. There is a workaround, but it requires some significant manual stitching of JS files after compilation, which would make this not at all an out-of-the-box experience.

For this reason, I believe WASM support for this driver isn't realistic at the moment, but perhaps by the time Go 1.12 is released, presumably with more mature WASM support, this will no longer be true.

On the other hand, if someone has the time to find creative ways around these problems, I would love to be proven wrong :)