Skip to content

Commit

Permalink
feat(examples): mirror realm (#3156)
Browse files Browse the repository at this point in the history
<!-- please provide a detailed description of the changes made in this
pull request. -->

## Description

Adds the mirror realm.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
</details>
  • Loading branch information
leohhhn authored Nov 19, 2024
1 parent 1e2929b commit b3800b7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/gno.land/r/demo/mirror/doc.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package mirror demonstrates that users can pass realm functions
// as arguments to other realms.
package mirror
3 changes: 3 additions & 0 deletions examples/gno.land/r/demo/mirror/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module gno.land/r/demo/mirror

require gno.land/p/demo/avl v0.0.0-latest
33 changes: 33 additions & 0 deletions examples/gno.land/r/demo/mirror/mirror.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mirror

import (
"gno.land/p/demo/avl"
)

var store avl.Tree

func Register(pkgpath string, rndr func(string) string) {
if store.Has(pkgpath) {
return
}

if rndr == nil {
return
}

store.Set(pkgpath, rndr)
}

func Render(path string) string {
if raw, ok := store.Get(path); ok {
return raw.(func(string) string)("")
}

if store.Size() == 0 {
return "None are fair."
}

return "Mirror, mirror on the wall, which realm's the fairest of them all?"
}

// Credits to @jeronimoalbi
1 change: 1 addition & 0 deletions examples/gno.land/r/leon/home/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ require (
gno.land/r/demo/art/gnoface v0.0.0-latest
gno.land/r/demo/art/millipede v0.0.0-latest
gno.land/r/demo/hof v0.0.0-latest
gno.land/r/demo/mirror v0.0.0-latest
gno.land/r/leon/config v0.0.0-latest
)
2 changes: 2 additions & 0 deletions examples/gno.land/r/leon/home/home.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gno.land/r/demo/art/gnoface"
"gno.land/r/demo/art/millipede"
"gno.land/r/demo/hof"
"gno.land/r/demo/mirror"
"gno.land/r/leon/config"
)

Expand All @@ -34,6 +35,7 @@ TODO import r/gh
}

hof.Register()
mirror.Register(std.CurrentRealm().PkgPath(), Render)
}

func UpdatePFP(url, caption string) {
Expand Down

0 comments on commit b3800b7

Please sign in to comment.