-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add isFirstRender flag during rendering phase #3428
Conversation
Currently this does not work in an alternative is to add a method ensureChildView method that would only show the child view if not exists
It could be used safely inside onRender Anyway, any solution would require an option to not reinit the regions |
Yet another alternative is to make the show child view declarative in the region definition
or
The advantage is that the implementation of how the child view is show would not be exposed to user. We could change it safely |
True, I was already ahead of #3427 I dont know if I like the declarative way with the |
Again I think this further complicates the view const MyView = Mn.View.extend({
initialize() {
if(this.isRendered()) {
// preexisting DOM
this.showChildView('view1', new View1());
this.showChildView('view2', new View2());
}
},
onRender(view, firstRender) {
// Will only be called if the view is re-rendered
if(firstRender) {
console.log('If view had preexisting DOM I will never occur');
this.showChildView('view1', new View1());
}
if(this.isRendered()) { console.log('If view had preexisting DOM I will always occur'); }
this.showChildView('view2', new View2()); // render every time
}
}); vs const MyView = Mn.View.extend({
// Will be called whether or not the view has preexisting el but only once
onReady() {
this.showChildView('view1', new View1());
this.showChildView('view2', new View2());
},
onRender() {
if(this.isRendered()) { // will be called every render but only true if !onReady
this.showChildView('view2', new View2());
}
}
}); I would suggest with new renders and non-destructive regions, the |
Good point I like it better ! |
onReady must be called after every render with a destructive renderer |
@blikblum I though we could introduced the |
Call on
showChildView
to set children views is usually set duringonRender
, but as regions & children are not always erased on re-rendering (it depends on the Renderer the user set) I think you should offer another way to know more easily if this call should be done or not.Today we have this check
or user can set its own flag
I would like Marionette offers the second logic to all Views, because it will be more versatile
This will be a great feature along with #3427