Esempio n. 1
0
func M(selector string, attrs js.M, children ...View) VirtualElement {
	renderableChildren := make([]interface{}, len(children))
	for i, child := range children {
		renderableChildren[i] = child.View()
	}
	return VirtualElement{m.M(selector, attrs, renderableChildren)}
}
Esempio n. 2
0
// View is a function that takes a controller as its first argument, and returns
// a view. Unfortunately, due to the need for compatibility with MakeFunc, the
// signature is poor.
func View(this *js.Object, args []*js.Object) interface{} {
	controller := args[0]
	pages := controller.Get("pages")
	children := js.S{}
	p := pages.Invoke()
	for i := 0; i < p.Length(); i++ {
		page := p.Index(i)
		children = append(
			children,
			m.M("a", js.M{
				"href": page.Get("url").String()},
				page.Get("title").String()))
	}

	children = append(children,
		m.M("button", js.M{
			"onclick": controller.Get("rotate")},
			"Rotate links"))

	return m.M("div", js.M{}, children...)
}