Skip to content

Commit

Permalink
- removed dependency of honnef/dom pkg
Browse files Browse the repository at this point in the history
- add new function to getElementById
- fix golint issue
  • Loading branch information
rocketlaunchr-cto committed Jul 26, 2019
1 parent 7f3cd5b commit 2e8fb07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions react.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package react

import (
"github.com/gopherjs/gopherjs/js"
"honnef.co/go/js/dom"
)

var (
Expand All @@ -26,8 +25,17 @@ var (
CreateReactClass = js.Global
)

// GetElementByID will return the first element with the specified id in the dom object.
// If no dom is provided, window.document will be used.
func GetElementByID(id string, dom ...*js.Object) *js.Object {
if len(dom) > 0 {
return dom[0].Call("getElementById", id)
}
return js.Global.Get("document").Call("getElementById", id)
}

// Render will render component to the specified target dom element.
func Render(element *js.Object, domTarget dom.Element, callback ...func()) *js.Object {
func Render(element *js.Object, domTarget *js.Object, callback ...func()) *js.Object {
if len(callback) > 0 && callback[0] != nil {
return ReactDOM.Call("render", element, domTarget, callback[0])
}
Expand Down
2 changes: 1 addition & 1 deletion react_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *SyntheticEvent) IsTrusted() bool {
return s.O.Get("isTrusted").Bool()
}

// NativeEvents ...
// NativeEvent ...
//
// See: https://reactjs.org/docs/events.html#overview
//
Expand Down

0 comments on commit 2e8fb07

Please sign in to comment.