Last active
March 7, 2018 18:20
-
-
Save bzub/962d4cda9cf469d06d96c3d8c4ace2a7 to your computer and use it in GitHub Desktop.
vecty panic with list child (with RenderSkipper workaround)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/gopherjs/vecty" | |
"github.com/gopherjs/vecty/elem" | |
"github.com/gopherjs/vecty/event" | |
"github.com/gopherjs/vecty/prop" | |
) | |
type PageView struct { | |
vecty.Core | |
bHTMLLabel *Button | |
bListLabel *Button | |
} | |
type Button struct { | |
vecty.Core | |
Label vecty.ComponentOrHTML | |
Disabled bool | |
} | |
type fakeComponent struct { | |
vecty.Core | |
child vecty.ComponentOrHTML | |
} | |
func main() { | |
bHTMLLabel := &Button{ | |
Label: vecty.Text("HTML Label"), | |
} | |
bListLabel := &Button{ | |
Label: vecty.List{ | |
vecty.Text("List "), | |
elem.Code(vecty.Text("Label")), | |
}, | |
} | |
vecty.RenderBody(&PageView{ | |
bHTMLLabel: bHTMLLabel, | |
bListLabel: bListLabel, | |
}) | |
} | |
func (c *PageView) Render() vecty.ComponentOrHTML { | |
return elem.Body( | |
elem.Div( | |
elem.Input( | |
vecty.Markup( | |
prop.Type(prop.TypeCheckbox), | |
event.Change(func(e *vecty.Event) { | |
checked := e.Target.Get("checked").Bool() | |
c.bHTMLLabel.Disabled = checked | |
vecty.Rerender(c.bHTMLLabel) | |
c.bListLabel.Disabled = checked | |
vecty.Rerender(c.bListLabel) | |
}), | |
), | |
), | |
vecty.Text("Disable all buttons"), | |
), | |
c.bHTMLLabel, | |
c.bListLabel, | |
) | |
} | |
func (c *Button) Render() vecty.ComponentOrHTML { | |
return elem.Button( | |
vecty.Markup( | |
prop.Type(prop.TypeButton), | |
vecty.Property("disabled", c.Disabled), | |
event.Change(func(e *vecty.Event) { | |
c.Disabled = true | |
vecty.Rerender(c) | |
}), | |
), | |
&fakeComponent{child: c.Label}, | |
) | |
} | |
func (c *fakeComponent) Render() vecty.ComponentOrHTML { | |
switch t := c.child.(type) { | |
case vecty.List: | |
return elem.Div(t) | |
} | |
return c.child | |
} | |
func (c *fakeComponent) SkipRender(prev vecty.Component) bool { | |
switch prev.(type) { | |
case *fakeComponent: | |
return true | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment