about summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-11-02 10:59:16 +0100
committerGitHub2020-11-02 10:59:16 +0100
commit267d40bbea6036f913c4047a6a2055b3e5d7bb96 (patch)
treeef2bcb5be63bb6f9fdfd6a608698473ac2192ea6 /examples
parent6c8f0c235287edf7252fe239d4c9beb258c6ff01 (diff)
downloadgomponents-267d40bbea6036f913c4047a6a2055b3e5d7bb96.tar.lz
gomponents-267d40bbea6036f913c4047a6a2055b3e5d7bb96.tar.zst
gomponents-267d40bbea6036f913c4047a6a2055b3e5d7bb96.zip
Add Map function (#40)
`Map` makes it easier to build lists of elements without having to iterate.
Diffstat (limited to 'examples')
-rw-r--r--examples/simple/simple.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/examples/simple/simple.go b/examples/simple/simple.go
index 3802f43..dd6dd58 100644
--- a/examples/simple/simple.go
+++ b/examples/simple/simple.go
@@ -61,11 +61,11 @@ func navbar(props navbarProps) g.Node {
 		{"/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))
 }