WebCabin / wcDocker

wcDocker (Web Cabin Docker) is a powerful window layout system with a responsive and completely interactive design. Move, remove, create, and duplicate panel windows at any time! Organize how you wish! View the demo here:
http://docker.webcabin.org
146 stars 53 forks source link

does wcDocker have a destroy-function? #103

Open lomotelsch opened 8 years ago

lomotelsch commented 8 years ago

A destroy-function is not documented, so is there a way to free memory after removing it? Thanks, Sebastian

Lochemage commented 8 years ago

@lomotelsch

If you are talking about destroying a panel, wcDocker.removePanel() should be used for that: http://docker.api.webcabin.org/module-wcDocker.html#toc24

However, if you have specific things you would need to clean up while your panel is being destroyed, you should register the following event handlers for it: wcDocker.EVENT.CLOSING and/or wcDocker.EVENT.CLOSED. One happens before, and the other happens right after the panel has been destroyed.

http://docker.api.webcabin.org/module-wcDocker.html#toc4

Does this help?

AFamularo-lomoSoft commented 8 years ago

Hello Jeff,

My colleague has missed to describe the scenario.

We build a Single Page Application with Angular. We have several modules with different content.

When the user switch from one module to another, angular, for been precise the ui-router will remove the docker-directive and create a new instance.

In the docker-directive we will watch the directive destroy event. When this event occurs we have to clean up the memory. We have to dispose the panel but also the docker instance.

Therefore a destroy function which knows the docker events etc. would be helpful.

How can we handle this use case?

Thank you, Alexander

Lochemage commented 8 years ago

@AFamularo-lomoSoft

Ahh, I don't know why I did not name it wcDocker.destroy(), but there is a wcDocker.clear() which does exactly this. It will destroy all panels and other bits that make up the interface. I noticed that I forgot to also clean up referenced event handlers that have been applied directly to wcDocker, so I will add that asap.

wcDocker.clear() method: http://docker.api.webcabin.org/module-wcDocker.html#toc13

After calling this, it should be safe to simply un-reference the wcDocker object and allow the browser to garbage collect it. Also note, the clear method only triggers wcDocker.EVENT.CLOSED, and NOT wcDocker.EVENT.CLOSING, in case you have specific cleanup done in that one.

lomotelsch commented 8 years ago

I noticed that I forgot to also clean up referenced event handlers that have been applied directly to wcDocker, so I will add that asap.

Perfect Jeff, clear() works for now and is excactly what I was looking for. Would be nice to have the wcDocker-events removed too by using clear()...

Lochemage commented 8 years ago

@lomotelsch

It should, actually. I've committed that change right after I mentioned it ;)

lomotelsch commented 8 years ago

@Lochemage ah you mean your exposed wcDocker-events - i see. I´m talking about the browser/jQuery events, which still stay in the memory when using clear(): https://www.youtube.com/watch?v=J0D5h5dIUg4&feature=youtu.be

lomotelsch commented 8 years ago

I do not know if this is very smart, but since you use event-delegation, the simplest way to "decouple" the events would be to bind to $('body.wcDesktop') instead of $('body') and removing the class wcDesktop from body when using clear(). I mean the most stable solution would be to remove every single event manually... What do you think?

Lochemage commented 8 years ago

@lomotelsch

Ahh, I understand. wcDesktop would not work, that class is only applied if you are running it on a desktop PC, otherwise you get wcMobile.

As for the mouse handler events, I have some plans to refactor that somewhat, I'll make sure this also includes unbinding them.