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

Bug fix undefined error, if destory is called before timers have fired #345

Merged
merged 1 commit into from
Apr 9, 2015
Merged

Conversation

raido
Copy link

@raido raido commented Apr 9, 2015

I have an application where user can enable/disable keyboard via UI button. If button is clicked multiple times in a row, then undefined errors are thrown, because timers are not torn down when calling destroy(). I propose this quick fix by adding extra if guards in timer handlers.

@raido
Copy link
Author

raido commented Apr 9, 2015

Proper fix would be clearing all timeouts in destroy(), i may look into this, if i have more time. This solution is a quick fix.

These timers also make unit testing difficult where it is included, because unit tests call destroy and timers fire after it.

@Mottie
Copy link
Owner

Mottie commented Apr 9, 2015

Hi @raido!

Hmm, how are you destroying/initializing the keyboard? I used this code and could not duplicate the issue (demo):

$('button').click(function () {
    var kb = $('#keyboard').getkeyboard();
    if (kb) {
        kb.destroy();
        $(this).text('Restore');
    } else {
        $(this).text('Destroy');
        $('#keyboard').keyboard();
    }
});

And maybe it would just be better to add this code in the destroy method:

clearTimeout(base.timer);

@raido
Copy link
Author

raido commented Apr 9, 2015

Hi @Mottie

clearTimeout(base.timer) does not work in my case, there are other timeouts that fire nevertheless.

Key thing that makes it break, is to call focus on the input right after the initialization, see demo - http://jsfiddle.net/egb3a1sk/227/

Mottie added a commit that referenced this pull request Apr 9, 2015
Bug fix undefined error, if destory is called before timers have fired
@Mottie Mottie merged commit 88192a5 into Mottie:master Apr 9, 2015
@Mottie
Copy link
Owner

Mottie commented Apr 9, 2015

ok thanks!

Mottie added a commit that referenced this pull request Apr 9, 2015
@Mottie Mottie added the Bug label Apr 9, 2015
@raido
Copy link
Author

raido commented Apr 9, 2015

I'll be waiting for the patch release :)

@Mottie
Copy link
Owner

Mottie commented Apr 9, 2015

You didn't have to wait long 😉

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

Successfully merging this pull request may close these issues.

2 participants