Last active
March 7, 2018 15:08
-
-
Save bzub/5a2b17debe18f5aef17e6b22e0cdbc8d to your computer and use it in GitHub Desktop.
vecty panic with list child
This file contains hidden or 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 | |
} | |
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) | |
}), | |
), | |
c.Label, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment