vugu / vugu

Vugu: A modern UI library for Go+WebAssembly (experimental)
https://www.vugu.org
MIT License
4.84k stars 175 forks source link

Make the code generator aware of syscall/js and use build tags to write dual output where needed #32

Closed bradleypeabody closed 5 years ago

bradleypeabody commented 5 years ago

Right now if you import syscall/js in your .vugu file the corresponding .go file will not build server-side. For complex UI's this is an issue. After some discussion at https://github.com/golang/go/issues/31158, this aspect of the syscall/js package is not likely to change. So the Vugu code generator should handle it.

Some basic ideas:

Another approach would be to mirror the syscall/js so it gets imported server side as something like import js "github.com/vugu/vugu/js-stub. We'd still need to have a separate file with a build tag, but it could seriously reduce the amount of weirdness required during codegen. I like this idea...

The code generator should probably look for it's "do not edit!" comment before clobbering an existing file, since someone could accidentally get burned if a subtle change add a single js.Value reference now starts outputting another file.

bradleypeabody commented 5 years ago

Plan is to make github.com/vugu/vugu/js as a mirror of syscall/js that fully delegates in wasm (ideally with zero overhead), but then in non-wasm it is dumbed down and all of the values are undefined, Truthy() always returns false, Get() always returns undefined, and Call() panics.

Then vugu components can just import js "github.com/vugu/vugu/js" and it does the appropriate thing in each environment. No build tags required in components. Boom

bradleypeabody commented 5 years ago

github.com/vugu/vugu/js is now done and being used. Closing.