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

does wcDocker have a destroy-function? #103

Open
lomotelsch opened this issue Mar 9, 2016 · 8 comments
Open

does wcDocker have a destroy-function? #103

lomotelsch opened this issue Mar 9, 2016 · 8 comments

Comments

@lomotelsch
Copy link

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

@Lochemage
Copy link
Contributor

@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
Copy link

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
Copy link
Contributor

@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.

Lochemage added a commit that referenced this issue Mar 10, 2016
@lomotelsch
Copy link
Author

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
Copy link
Contributor

@lomotelsch

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

@lomotelsch
Copy link
Author

@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
Copy link
Author

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
Copy link
Contributor

@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.

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

3 participants