backboneboilerplate icon indicating copy to clipboard operation
backboneboilerplate copied to clipboard

vm.js logic?

Open chchrist opened this issue 13 years ago • 5 comments

Hello, Thnx for the great boilerplate. I am trying to understand the logic in vm.js. Specifically the cleanup procedure. It seems that it checks if the view is not undefined then does a cleanup. But that way, you clean the same view you create later. You have to clean/unbind events etc the view the user was before and then create the new view.

Is it correct or am I missing something?

Thanks :)

chchrist avatar Apr 25 '12 11:04 chchrist

So if you create a view called 'SomeViewLabel' and then try create another view with the name 'SomeViewLabel' what will happen is that the first one you created will unbind any events attached to it before it overrides itself with the new one.

Does this make any sense?

thomasdavis avatar Apr 25 '12 11:04 thomasdavis

Ah OK , yes it makes sense, but what would be great is to be able to be at viewone and when you go to viewtwo to unbind the events or other stuff from viewone. Let's say my viewone has a var tick = setInterval() I want to be able to cleatInterval(tick) before I open the viewtwo.

chchrist avatar Apr 25 '12 13:04 chchrist

Hi thomas,

trying to understand why we would want to keep the views around and then remove them when we are about to create a new view with the same name? Wouldn't it make more sense to follow the path you outline in your tutorials (remove the currentView if there is one and then set the currentView to the new view being displayed) ?

Appreciate your feedback and thoughts.

hansgill avatar Jul 10 '12 16:07 hansgill

Shouldn't the "vm" be responsible for calling the "destroy"(unbind and remove view) method on each view that is about to be replaced? Not sure if you want to have previous created views being "zombies" around your application.

joaovpmamede avatar Sep 09 '12 23:09 joaovpmamede

I agree with @chchrist. vm should also have a separate destroy logic(along with create), where a view can be explicitly destroyed by passing its name.

arunkjn avatar Jul 18 '13 12:07 arunkjn