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

Use jQuery namespaces for all binded events #294

Closed
mitar opened this issue Dec 9, 2013 · 18 comments
Closed

Use jQuery namespaces for all binded events #294

mitar opened this issue Dec 9, 2013 · 18 comments
Assignees
Milestone

Comments

@mitar
Copy link

mitar commented Dec 9, 2013

Annotator should really use jQuery namespaces for all binded events, so that it is easy to possible to unbind events as well without interfering with other things.

@tilgovi
Copy link
Member

tilgovi commented Jan 14, 2014

+1

@mitar
Copy link
Author

mitar commented Jan 14, 2014

The rationale in our case is that we have a single-page application, so we never reload the page. So we have to be able to clean everything between moving through different documents.

@tilgovi
Copy link
Member

tilgovi commented Jan 14, 2014

This would be an easy update to the Delegator (class.coffee). Changes to addEvents (or maybe _addEvents) and the corresponding remove.

@mitar
Copy link
Author

mitar commented Jan 14, 2014

So there should be a way to unload annotator completely.

@tilgovi
Copy link
Member

tilgovi commented Jan 14, 2014

Agreed. There is, in recent tree. The destroy() method should propagate event unbinding to all the plugins. It's not guaranteed to work, but it's an attempt. The Delegator class is tracking the closures itself right now, but a namespace might be better if jQuery has an easy way to unbind all events from a given namespace.

@mitar
Copy link
Author

mitar commented Jan 14, 2014

but a namespace might be better if jQuery has an easy way to unbind all events from a given namespace.

Exactly this was motivation for this ticket. :-) .off('.annotator') unbinds all on the element. Hm, probably then $('*').off('.annotator') unbinds everything?

@mitar
Copy link
Author

mitar commented Jan 24, 2014

Is there any cleanup code already in place? Or should I improvise for now?

@tilgovi
Copy link
Member

tilgovi commented Jan 25, 2014

Yes, there is. See my previous comments. I mentioned the important points.

You might also want to audit some plugins for events set on document or window.

@tilgovi
Copy link
Member

tilgovi commented Jan 28, 2014

@mitar was that clear?

@mitar
Copy link
Author

mitar commented Jan 28, 2014

I definitely see bindings with jQuery oustide events of Delegator. I had in mind those. For example, see _setupDocumentEvents.

The issue is also that there is no consistency in how code binds events. So we have Delegator's events. Then I saw addEventListener and jQuery bind.

Why not just use jQuery on everywhere, with namespaces, and for custom events use jQuery as well.

@tilgovi
Copy link
Member

tilgovi commented Jan 28, 2014

_setupDocumentEvents is the exception, not the rule. Lots of things in Annotator use the Delegator events feature.

To answer question, I've already voiced support for doing exactly what you suggest. I'm asking if my answer was clear enough such that you feel you can now begin to implement that, and if you have interest in doing so.

@mitar
Copy link
Author

mitar commented Jan 28, 2014

So exceptions should stay exceptions? Anyway, in our extended Annotator class we are already doing this.

@tilgovi
Copy link
Member

tilgovi commented Jan 29, 2014

I made no claim about whether they should stay the way they are. I suspect not. I said already I like the namespace idea. Would you like to work on this?

@mitar
Copy link
Author

mitar commented Jan 29, 2014

I think I already did it. :-) So I think it would be enough just to define a destroy method on Annotator which makes sure everything is cleared up? I would leave events in Delegator as they are, but add a destroy there as well. And I would unify to use .on everywhere. And namespaces.

Where should this code be? Which branch? Against hypothesis/annotator?

@csillag
Copy link
Contributor

csillag commented Jan 29, 2014

Where should this code be? Which branch? Against |hypothesis/annotator|?

We are working on several different branches in hypothesis/annotator.
Hopefully, we will consolidate all work on a single branch soon, and
then start merging it into okfn/annotator.

I wouldn't recommend adding any further divergent branches, at this point.

(That being said, I fully support the idea of consolidating the mixed
browser event / jquery event / Delegator binding usage.)

@tilgovi
Copy link
Member

tilgovi commented Jan 29, 2014

Definitely on okfn/master!

@tilgovi
Copy link
Member

tilgovi commented Jan 29, 2014

I mean okfn/annotator@master

@tilgovi
Copy link
Member

tilgovi commented May 9, 2014

At this point, I believe master accomplishes this.

@tilgovi tilgovi closed this as completed May 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants