-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): mirror realm (#3156)
<!-- 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
Showing
5 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters