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

Events firing twice or more #718

Closed
lxsameer opened this issue Oct 5, 2015 · 6 comments · Fixed by #729
Closed

Events firing twice or more #718

lxsameer opened this issue Oct 5, 2015 · 6 comments · Fixed by #729

Comments

@lxsameer
Copy link
Contributor

lxsameer commented Oct 5, 2015

I'm using Turbolinks jquery to with AdminLTE and after each request events handlers execute more than once. After some investigation I found out that you binds you document inside a $(function()) block. This is not a good idea generally and should we should avoid such mistakes. For instance, this example below can be a common occurrence and should be avoided:

/* BAD: don't bind 'document' events while inside $()! */
$(function() {
  $(document).on('click', 'button', function() { ... })
});

You should be binding your events outside a $(function()) block. This will ensure that your events will only ever be bound once.

/* Good: events are bound outside a $() wrapper. */
$(document).on('click', 'button', function() { ... })
@almasaeed2010
Copy link
Contributor

Interesting observation. I will look into it as soon as I get a chance. Thanks for letting us know.

@lxsameer
Copy link
Contributor Author

lxsameer commented Oct 6, 2015

cool, If I find some free time I'll fix it too

@almasaeed2010
Copy link
Contributor

How can we test that these events are really firing more than once?

@lxsameer
Copy link
Contributor Author

lxsameer commented Oct 6, 2015

It's a bit complicated but I can test it for you if you want .

@lxsameer
Copy link
Contributor Author

@almasaeed2010 dist/js/app.js does not generate automatically from other js sources, right ?

@almasaeed2010
Copy link
Contributor

Right

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

Successfully merging a pull request may close this issue.

2 participants