-
Notifications
You must be signed in to change notification settings - Fork 18
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 issues when no el is set #23
Comments
jQuery is known for being newbie-friendly and failing gracefully, but I'm not sure that's the tack we should take. It often leads to silently swallowed errors and overly permissive code. $('foo')
> []
$('foo').on('bar', () => { throw new Error })
> []
$('foo').trigger('bar')
> [] Our two options as I see it are:
this.el = document.querySelector(element) || document.createElement('div'); It's a little wasteful but not especially harmful. May be unexpected though? What's your use case btw? When would you try to pass an |
The use case is me being lazy and using a specific module on every page whether the element is there or not. The way I got round it so far was to make It's been a while since I wrote JS as plain DOM. I can't remember, why is it that the event is attached to the document? Is that bubbling at work there? IMO, the code that attaches the event should check for the Having the element as |
We could do that. Wanna open a pull with some tests for missing elements? Let's make sure nothing else would break with this.
What part are you referring to? This section of |
I'm not sure if this is NativeView or Backbone itself, so apologies in advance.
When defining an element that is in page
el: '#some-element
if the element doesn't exist, it is rightly set tonull
.In the render function I can return early in this case, but any events that are defined are attached to the
document
as the element isn't there. This is causing issues and interruptions for the rest of the page.What should I be doing in this case? I've tried using
undelegateEvents
to no effect, as they haven't been correctly delegated, and the code looks forthis.el
.The text was updated successfully, but these errors were encountered: