I'm making a Backbone app and using $('main').replaceWith(view.el) to change views.
However, if I navigate to the same view twice, the view disappears.
This is because replaceWith currently works by adding node after this and then removing this. But if this === node, it adds it and immediately removes it because they are the same node.
A better solution is to use the browser's native Node.prototype.replaceChild() method.
Here's my suggestion, does this look okay?
replaceWith: function (node) {
return bonzo(this[0].parentNode.replaceChild(bonzo(normalize(node))[0], this[0]))
}
It seems to work. If I don't find any problems I'll fork it and submit a pull req.
I'm making a Backbone app and using
$('main').replaceWith(view.el)
to change views.However, if I navigate to the same view twice, the view disappears.
This is because replaceWith currently works by adding
node
afterthis
and then removingthis
. But ifthis === node
, it adds it and immediately removes it because they are the same node.A better solution is to use the browser's native
Node.prototype.replaceChild()
method.Here's my suggestion, does this look okay?
It seems to work. If I don't find any problems I'll fork it and submit a pull req.