If you pass null as the second argument to insertBefore(), it does an appendChild. So you can rewrite this as

container.insertBefore(domNode, before ? before.getHTMLNode() : null)