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

Add the ability to remove event listeners #77

Open
naftasantos opened this issue Apr 19, 2018 · 3 comments
Open

Add the ability to remove event listeners #77

naftasantos opened this issue Apr 19, 2018 · 3 comments
Labels
to implement implement in the next release

Comments

@naftasantos
Copy link

I have a screen with dynamically loaded html content. In one of these contents, I use the MDL select component. However, sometimes I need to destroy this screen and build another one that does not have this component.

This behavior causes some crashes inside getmdl-select.js hideAllMenus, because the necessary objects do not really exist anymore. More specifically in the line 63: menu['MaterialMenu'].hide();.

image

I did some debug, and realized that the problem was occurring because on line 68, there is an event listener being added to the body of the document: document.body.addEventListener('click', hideAllMenus, false);

Since this event listener uses a named function declared inside the function _addEventListeners, I can't remove it from outside of the function. Also, every time I load a screen that needs to call getmdlSelect.init, a new listener will be added to the body. So, when an event occurs, this function will be called various times.

Similar to getmdlSelect.init('#target'); the component should have a getmdlSelect.dispose('#target'); to allow for a more dynamic usage.

@randrianov
Copy link
Member

@naftasantos thank you for sharing, would you like to create PR?
it will be very helpful or we will include this into dev plan.

@naftasantos
Copy link
Author

I tried to push at least an 'undefined' verification as a quick fix measure, but I have no access. For the full feature, since I changed our project to use another library, I won't be able to work on it. 😄

@alexbananabob alexbananabob added the to implement implement in the next release label Jun 1, 2018
@CragVFX
Copy link

CragVFX commented Nov 13, 2018

Is there any plan to address this issue? I have the same use-case, of dynamically loaded content. Below is a quick "fix" for the issue, but doesn't resolve the cause.

                [].forEach.call(menus, function (menu) {
                    if (typeof menu['MaterialMenu'] !== 'undefined') menu['MaterialMenu'].hide();
                });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to implement implement in the next release
Projects
None yet
Development

No branches or pull requests

4 participants