Skip to content
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

Prevent zombie view in router.js #11

Closed
thomasdao opened this issue Mar 21, 2012 · 7 comments
Closed

Prevent zombie view in router.js #11

thomasdao opened this issue Mar 21, 2012 · 7 comments

Comments

@thomasdao
Copy link

Hi,

Thanks for creating the boilerplate, I really like it. This is just minor suggestion to prevent zombie view in the file router.js

Currently we always create a new view when user navigate to different url, and never close or reuse them properly.

E.g:
optimize: function () {
require(['views/optimize/page'], function (OptimizePage) {
var optimizePage = new OptimizePage();
optimizePage.render();
});
},

I think a better approach is to check whether the page is already been initialized, then we can reuse it efficiently without creating new page every time. For e.g:

if (! this.optimizePage) {
this.optimizePage = new OptimizePage()
}
this.optimizePage.render()

@thomasdavis
Copy link
Owner

Thanks Thomas, you are exactly right. I am working on the View Manager write now that controls the life cycle of views and stops zombie views, will be pushing in the next few hours. Thanks again!

@thomasdao
Copy link
Author

Hi,

I think it would be a nice improvement when we return 'this' on the render method.

ChildPage = Backbone.View.extend {
render: function() {
// do something
return this;
}
}

Sometime, from master page we want to append a child page, we could do:
childPage = new ChildPage()
$(element).append(childPage.render().el)

@engram-design
Copy link

I've also had issues with the current View Manager, which, while great, doesn't clean up properly. I came across this after loading views where events defined in (events.js) were being triggered multiple times. To work around this, I'm using undelegateEvents() on the previous view before creating a new one.

I'm aware that the VM isn't fully implemented yet, but any plans on setting this up?

@thomasdavis
Copy link
Owner

on second thought undelegateEvents is probably the only default cleanup a view manager should do and also calling clean() if it has been defined. What do you think?

@engram-design
Copy link

I'm certainly no expert, but that's just what I'm doing! Sounds good :)

Also, on the subject of VM - is it supposed to re-use already created views when called again? As currently, it doesn't seem to, and just creates a new view when create is called. In fact, views[name] is never defined.

Thanks for your quick response by the way!

@thomasdavis
Copy link
Owner

So in the view manager the views should always be created fresh, if you want to maintain a view you can do so using your applications logic.

Some goals I had for the view manager were

  • clean up !important
  • managing children / nested views
  • a basic signalling of view creation to the app
  • eventually more advanced event delegation e.g. the ability to make all event listeners on a view dormant etc
  • handle dynamic reusable views such as table rows

For now I've changed the unbind() to undelegateEvents().

@engram-design
Copy link

Ok, that clears that up - sounds good. Thanks mate!

@okor okor closed this as completed Jun 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants