forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f12da74
commit f103cb7
Showing
6 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
File renamed without changes.
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
File renamed without changes.
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,27 @@ | ||
package registry | ||
|
||
import ( | ||
"gno.land/p/demo/avl" | ||
"std" | ||
) | ||
|
||
var callbacks avl.Tree | ||
type functionCB func(args ...interface{}) []interface{} | ||
|
||
func Register(id string, callback functionCB){ | ||
_,exists:=callbacks.Get(id) | ||
if exists{ | ||
panic("A callback already exists for the id") | ||
} | ||
|
||
callbacks.Set(id, callback) | ||
} | ||
|
||
func Exec(id string, args ...interface{}){ | ||
cb, ok:= callbacks.Get(id) | ||
if !ok{ | ||
panic("Callback not found") | ||
} | ||
function := cb.(functionCB) | ||
function(args) | ||
} |
22 changes: 22 additions & 0 deletions
22
examples/gno.land/r/demo/teritori/registry/registry_test.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package registry | ||
|
||
import ( | ||
"std" | ||
"testing" | ||
|
||
"gno.land/p/demo/avl" | ||
"gno.land/p/demo/testutils" | ||
"strings" | ||
) | ||
|
||
func TestGetProfile(t *testing.T) { | ||
user1 := testutils.TestAddress("user1") | ||
std.TestSetOrigCaller(user1) | ||
functionID:="SOMEID" | ||
var cb functionCB = func(args ...interface{})[]interface{}{ | ||
//t.Errorf("dataType",dataType) | ||
return nil | ||
} | ||
Register(functionID, cb) | ||
Exec(functionID) | ||
} |
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