-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add hello_world, update
r/demo/event
(#3130)
<!-- please provide a detailed description of the changes made in this pull request. --> ## Description We don't have a clean & simple hello_world realm. I also updated the doc on the `r/demo/events` realm, and also renamed it to emit. <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
8 changed files
with
57 additions
and
17 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,12 @@ | ||
// Package emit demonstrates how to use the std.Emit() function | ||
// to emit Gno events that can be used to track data changes off-chain. | ||
// std.Emit is variadic; apart from the event name, it can take in any number of key-value pairs to emit. | ||
package emit | ||
|
||
import ( | ||
"std" | ||
) | ||
|
||
func Emit(value string) { | ||
std.Emit("EventName", "key", value) | ||
} |
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 @@ | ||
module gno.land/r/demo/emit |
14 changes: 7 additions & 7 deletions
14
...les/gno.land/r/demo/event/z1_filetest.gno → ...ples/gno.land/r/demo/emit/z1_filetest.gno
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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
package main | ||
|
||
import "gno.land/r/demo/event" | ||
import "gno.land/r/demo/emit" | ||
|
||
func main() { | ||
event.Emit("foo") | ||
event.Emit("bar") | ||
emit.Emit("foo") | ||
emit.Emit("bar") | ||
} | ||
|
||
// Events: | ||
// [ | ||
// { | ||
// "type": "TAG", | ||
// "type": "EventName", | ||
// "attrs": [ | ||
// { | ||
// "key": "key", | ||
// "value": "foo" | ||
// } | ||
// ], | ||
// "pkg_path": "gno.land/r/demo/event", | ||
// "pkg_path": "gno.land/r/demo/emit", | ||
// "func": "Emit" | ||
// }, | ||
// { | ||
// "type": "TAG", | ||
// "type": "EventName", | ||
// "attrs": [ | ||
// { | ||
// "key": "key", | ||
// "value": "bar" | ||
// } | ||
// ], | ||
// "pkg_path": "gno.land/r/demo/event", | ||
// "pkg_path": "gno.land/r/demo/emit", | ||
// "func": "Emit" | ||
// } | ||
// ] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
module gno.land/r/demo/hello_world |
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,17 @@ | ||
// Package hello_world demonstrates the usage of the Render() function. | ||
// Render() can be called via the vm/qrender ABCI query off-chain to | ||
// retrieve realm state or any other custom data defined by the realm | ||
// developer. The vm/qrender query allows for additional data to be | ||
// passed in with the call, which can be utilized as the path argument | ||
// to the Render() function. This allows developers to create different | ||
// "renders" of their realms depending on the data which is passed in, | ||
// such as pagination, admin dashboards, and more. | ||
package hello_world | ||
|
||
func Render(path string) string { | ||
if path == "" { | ||
return "# Hello, 世界!" | ||
} | ||
|
||
return "# Hello, " + path + "!" | ||
} |
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,19 @@ | ||
package hello_world | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestHello(t *testing.T) { | ||
expected := "# Hello, 世界!" | ||
got := Render("") | ||
if got != expected { | ||
t.Fatalf("Expected %s, got %s", expected, got) | ||
} | ||
|
||
got = Render("world") | ||
expected = "# Hello, world!" | ||
if got != expected { | ||
t.Fatalf("Expected %s, got %s", expected, got) | ||
} | ||
} |