-
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
04b4a95
commit 3b6b553
Showing
4 changed files
with
110 additions
and
7 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 |
---|---|---|
@@ -1,11 +1,43 @@ | ||
package react | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
type ComponentStruct interface { | ||
Render(ctx *Context) interface{} | ||
} | ||
|
||
func IsComponent(value interface{}) bool { | ||
_, ok := value.(ComponentStruct) | ||
ok := false | ||
|
||
if value != nil { | ||
rVal := reflect.TypeOf(value) | ||
_, ok = rVal.MethodByName("Render") | ||
} | ||
|
||
return ok | ||
} | ||
|
||
func renderComponent(value interface{}, ctx interface{}) interface{} { | ||
if !IsComponent(value) { | ||
return nil | ||
} | ||
|
||
rVal := reflect.ValueOf(value) | ||
method := rVal.MethodByName("Render") | ||
|
||
if method.IsZero() || method.IsNil() { | ||
return nil | ||
} | ||
|
||
var result []reflect.Value | ||
|
||
if ctx != nil { | ||
result = method.Call([]reflect.Value{reflect.ValueOf(ctx)}) | ||
} else { | ||
result = method.Call([]reflect.Value{reflect.ValueOf(NewContext())}) | ||
} | ||
|
||
return result[0].Interface() | ||
} |
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
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