Closed bradleypeabody closed 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
github.com/vugu/vugu/js is now done and being used. Closing.
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:
js.Value
could be replaced withinterface{}
and method bodies for such methods could be implemented with a panic (since server code should never legitimately call it).Another approach would be to mirror the
syscall/js
so it gets imported server side as something likeimport 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.