From 5fa136289be675934037691817742335ee53a275 Mon Sep 17 00:00:00 2001 From: David Brophy Date: Mon, 4 Jul 2016 17:43:26 +0200 Subject: [PATCH] Added vecty.Nil, prevent replaceNode if new node is nil --- dom.go | 19 +++++++++++++++++++ domutil.go | 3 +++ 2 files changed, 22 insertions(+) diff --git a/dom.go b/dom.go index 838265da..f8a75601 100644 --- a/dom.go +++ b/dom.go @@ -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{} +} diff --git a/domutil.go b/domutil.go index 78c7d85b..d08dcb6e 100644 --- a/domutil.go +++ b/domutil.go @@ -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) }