Add Map function (#40) `Map` makes it easier to build lists of elements without having to iterate.
1 file changed, 6 insertions(+), 6 deletions(-)
changed files
M examples/simple/simple.go → examples/simple/simple.go
@@ -61,11 +61,11 @@ {"/", "Home"}, {"/foo", "Foo"}, {"/bar", "Bar"}, } - var lis []g.Node - for _, item := range items { - lis = append(lis, el.Li(el.A(item.path, - attr.Classes(map[string]bool{"is-active": props.path == item.path}), - g.Text(item.text)))) - } + lis := g.Map(len(items), func(i int) g.Node { + item := items[i] + return el.Li( + el.A(item.path, attr.Classes(map[string]bool{"is-active": props.path == item.path}), g.Text(item.text)), + ) + }) return el.Ul(attr.Class("nav"), g.Group(lis)) }