vugu / vugu

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

Remove redundant definitions in *_vgen.go #255

Closed Lord-Y closed 6 months ago

Lord-Y commented 7 months ago

Hello,

This PR goes with https://github.com/vugu/vugu/issues/246 requirements.

When the parser is executed to genereate *_vgen.go files, you can find a lot of redundant definitions vugu.VGAttribute{vugu.VGAttribute like:

                        vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "div", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "class", Val: "mt-5"}}}
                        vgparent.AppendChild(vgn)
                        {
                                vgparent := vgn
                                _ = vgparent
                                vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n            "}
                                vgparent.AppendChild(vgn)
                                vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "h1", Attr: []vugu.VGAttribute(nil)}
                                vgparent.AppendChild(vgn)
                                vgn.SetInnerHTML(vugu.HTML("Welcome to Vugu"))
                                vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n            "}
                                vgparent.AppendChild(vgn)
                                vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "p", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "class", Val: "lead"}}}
                                vgparent.AppendChild(vgn)
                                {
                                        vgparent := vgn
                                        _ = vgparent
                                        vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "This page is being rendered via \n                "}
                                        vgparent.AppendChild(vgn)
                                        vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "a", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "href", Val: "https://webassembly.org/"}}}

It's not an error but it's cleaner to remove them. This PR solves this problem.

Lord-Y commented 6 months ago

Any blocking points about this one @owenwaller @bradleypeabody ?

owenwaller commented 6 months ago

Hi @Lord-Y

Sorry, I'm only getting to look at this one now.

At first glance, I think this is one for @bradleypeabody as I am not entirely sure which area this is in, or what the correct answer is.

I don't see any duplication in the section you have pasted in above. All of the vugu.VGAttribute{vugu.VGAttribute{... blocks are all creating the first element in a []vugu.VGAttribute which looks legit to me. It just happens that its a single element slice that has been generated.

So I'm a bit confused. What was the (linter?) error that you saw to fix this?

Owen

Lord-Y commented 6 months ago

Hi @owenwaller , here is an example:

git clone git@github.com:vugu-examples/simple.git
cd simple/
vgrun devserver.go
# stop vgrun and then:
grep -c 'vugu.VGAttribute{vugu.VGAttribute' 0_components_vgen.go
12

Linter message: redundant type from array, slice, or map composite literalsimplifycompositelit

bradleypeabody commented 6 months ago

Okay. My preference would be to not worry about linting issues and instead focus on functional bugs or features, but that said I get what you mean. Merging.

bradleypeabody commented 6 months ago

Actually @Lord-Y the pipeline build is doing some weird stuff. It's saying the operation was cancelled but it's happening each time automatically. We're going to need to fix that before I can keep merging stuff in - I can't be sure that this change doesn't break anything.

Lord-Y commented 6 months ago

@bradleypeabody It's also weird to me. After syncing my branch with master, all tests are passing.

Maybe it's because the image that is used is ubuntu-latest which is https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#go / https://github.com/actions/runner-images#available-images and in the CI, the requirements was go version 1.16 and 1.17. I also saw this issue https://github.com/actions/runner/issues/2468 but I guess it's more for people that are using github enterprise version.

Anyway, All checks have passed :-)