about summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
authorMarkus Wüstenberg2022-09-22 09:41:06 +0200
committerGitHub2022-09-22 09:41:06 +0200
commitf387a7123040d9414350bf783bdeff17ac0572c7 (patch)
tree89859a54e3cd6bf3e6169c384529af98aeee4dc5 /examples
parent3334d6c7d049cec57ad36f9d5cb0d491faf54a5d (diff)
downloadgomponents-f387a7123040d9414350bf783bdeff17ac0572c7.tar.lz
gomponents-f387a7123040d9414350bf783bdeff17ac0572c7.tar.zst
gomponents-f387a7123040d9414350bf783bdeff17ac0572c7.zip
Add generic Map implementation (#108)
Instead of waiting for a good time to switch the `Map` implementation,
I've decided to just offer two implementations: one for Go versions
before 1.18, and one for 1.18 and onwards. This is achieved using build
tags in the source files.

This is obviously a breaking change for consumers of this library that
use Go 1.18 and onwards.

See #88
Diffstat (limited to 'examples')
-rw-r--r--examples/simple/simple.go7
-rw-r--r--examples/tailwindcss/tailwindcss.go7
2 files changed, 10 insertions, 4 deletions
diff --git a/examples/simple/simple.go b/examples/simple/simple.go
index 93aa28f..0a7138a 100644
--- a/examples/simple/simple.go
+++ b/examples/simple/simple.go
@@ -1,3 +1,6 @@
+//go:build go1.18
+// +build go1.18
+
 package main
 
 import (
@@ -58,8 +61,8 @@ func Navbar(currentPath string, links []PageLink) g.Node {
 		Ul(
 			NavbarLink("/", "Home", currentPath),
 
-			g.Group(g.Map(len(links), func(i int) g.Node {
-				return NavbarLink(links[i].Path, links[i].Name, currentPath)
+			g.Group(g.Map(links, func(pl PageLink) g.Node {
+				return NavbarLink(pl.Path, pl.Name, currentPath)
 			})),
 		),
 
diff --git a/examples/tailwindcss/tailwindcss.go b/examples/tailwindcss/tailwindcss.go
index 2af2d33..39a012e 100644
--- a/examples/tailwindcss/tailwindcss.go
+++ b/examples/tailwindcss/tailwindcss.go
@@ -1,3 +1,6 @@
+//go:build go1.18
+// +build go1.18
+
 package main
 
 import (
@@ -81,8 +84,8 @@ func Navbar(currentPath string, links []PageLink) g.Node {
 				NavbarLink("/", "Home", currentPath == "/"),
 
 				// We can Map custom slices to Nodes
-				g.Group(g.Map(len(links), func(i int) g.Node {
-					return NavbarLink(links[i].Path, links[i].Name, currentPath == links[i].Path)
+				g.Group(g.Map(links, func(pl PageLink) g.Node {
+					return NavbarLink(pl.Path, pl.Name, currentPath == pl.Path)
 				})),
 			),
 		),