Skip to content

Commit

Permalink
Added vecty.Nil, prevent replaceNode if new node is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Jul 4, 2016
1 parent a788b0c commit 5fa1362
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dom.go
Expand Up @@ -247,3 +247,22 @@ func (c *Composite) ReconcileBody() {
replaceNode(c.Body.Node(), oldBody.Node())
}
}

type nilComponent struct {
node *js.Object
}

// Apply implements the Markup interface.
func (s *nilComponent) Apply(element *Element) {}

func (s *nilComponent) Reconcile(oldComp Component) {}

func (s *nilComponent) Node() *js.Object {
return nil
}

func (e *nilComponent) Unmount() {}

func Nil() Component {
return &nilComponent{}
}
3 changes: 3 additions & 0 deletions domutil.go
Expand Up @@ -10,5 +10,8 @@ func replaceNode(newNode, oldNode *js.Object) {
if newNode == oldNode {
return
}
if newNode == nil {
return
}
oldNode.Get("parentNode").Call("replaceChild", newNode, oldNode)
}

0 comments on commit 5fa1362

Please sign in to comment.