Open owenwaller opened 5 months ago
Autogenerated version is fine for me, I usually only change 1 line in this file:
rootBuilder := vuguSetup(buildEnv, renderer.EventEnv())
You could even provide a setup.go skeleton with
func vuguSetup(buildEnv *vugu.BuildEnv, eventEnv vugu.EventEnv) vugu.Builder {
return &page.Root{}
}
@Scapal
Thanks for this, but can you be clear exactly which line you are taking about always having to change with a diff against the generated main_wasm.go
?
This line:
rootBuilder := &Root{}
Is doing more than it appears, specifically the Root
is name of the struct that the is generated by vugugen
based on the filename of the .vugu
file.
This means that the current main_wasm.go
has an implicit naming convention in it. This is not obvious if you don't know vugu
's internals.
[Aside: I would like to break this convention so that when you run vugugen
you can pick a name for the root "object", and change any generated main_wasm.go
as required. But that's a not going to happen soon, as we are busy on other areas.]
Thanks
HI @owenwaller ,
Yes it is exactly that line. I call a vuguSetup()
function to setup the routing, the wiring and the authentication.
Oh, in fact I don't even change the main_wasm.go
, vugugen
is detecting that the function exists and adapt the main_wasm.go
accordingly:
If your main package includes a function called vuguSetup, then when vugugen creates your main_wasm.go file it will include a call to that function. https://www.vugu.org/doc/wiring
Reason
@bradleypeabody and myself are seeking feedback from the community in relation to the
main_wasm.go
file. We are considering marking this file as autogenerated in the future and recommending that users do not edit it.Currently, unless you run
vugugen
with the-skip-main
flagvugugen
will generate a file calledmain_wasm.go
that is themain
function for yourvugu
application.We need to know how the community is using this file (if at all), especially in production environments. So if you are;
-skip-main
option and creating your ownmain
function.Can you please feedback in this issue?
At present we have no idea which category the majority of
vugu
users fall into so we are trying to determine this as a first step.A simple "We use the file as is" or something similar is all we need. If you fall into either of the last two options, can you give us an idea why you needed to edit the file or create a new one?
The
main_wasm.go
At present if the logic works as follows:
The current logic ensures that
main_wasm.go
is only generated once, so any edits to this file are not lost.The contents are currently:
Possible Options
From the perspective of a developer using
vugu
to build a web ui the options are:init
command to generate a version ofmain_wasm.go
for you. This allows us to pull out this functionality from the rest ofvugu
.main_wasm.go
file. Instead document what you need need to do to create one along with examples.For the first three options we are also considering exposing the template used to generate the 'main_wasm.go
. At present the template is internal to the
vuggen` tool. This would allow users to customise the template to suit their needs.