-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When a 'root' is specified while instancing a new Resthub.View, the view's el is inserted in the DOM during the instanciation #145
Comments
Hi, Thanks for reporting this issue. Regards, |
Resthub.View. |
yeah sorry I messed up. I'll edit my post |
I put a fix in my fork : https://github.com/sdeleuze/resthub-backbone-stack, but I am not sure we should merge it. I am not sure it is inconsistent : if no root is provided, $el should be attached manually by the user (like in raw Backbone). If it is provided, it need to be attached to the DOM just 1 time. Nevertheless, this fix could perhaps make things better in cases where $el is removed from DOM between 2 render() calls. Anyway, on non trivial apps this change has currently some side effects (need more tests to figure out exactly what occur). Could you explain what issues current implementation produce, and test the fix I provided in my fork ? |
The issue seems to be fixed with the fix. The problem I was encountering was : So I created the view and called one of that view's method that would call render() or not depending on some conditions. Of course there are a lot of ways to bypass my issue (the most obvious one being testing the conditions before making the new instance), but It was surprising to have the $el in the DOM when I though I didn't do any "rendering", and I thought that behaviour was not natural, so I let you know. |
Hi,
The title says it all.
if you instanciate a view extending Resthub.View that has a "root" value defined in it, or if root is specified in the options object, this view's el will be attached to the root element during the instanciation, even if "render" is never called. I don't think this should be the case.
example :
function (Resthub) {
var Popin = Resthub.View.extend({
className: 'test',
});
return Popin;
});
new Popin(); --> $el is attached
new Popin({root:"body"}); --> $el is atttached to the body during this call.
apparently, the el gets attached to the root element in the Resthub method "_insertRoot".
The call stack is as follows :
(backbone.js) View ( http://backbonejs.org/docs/backbone.html#section-120 )
(backbone.js) _ensureElement ( http://backbonejs.org/docs/backbone.html#section-133)
(resthub.js) setElement
(resthub.js) _insertRoot
Maybe this behavior should be moved to the render ?
Thanks,
Léo.
The text was updated successfully, but these errors were encountered: