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

Unbind events/delegations #156

Closed
dzek69 opened this issue Jan 10, 2016 · 8 comments
Closed

Unbind events/delegations #156

dzek69 opened this issue Jan 10, 2016 · 8 comments
Assignees

Comments

@dzek69
Copy link

dzek69 commented Jan 10, 2016

Documentation doesn't say a word about that. Ability to handle events as easy as in jQuery would be nice.

@LeaVerou
Copy link
Owner

Bliss does store listeners, so that would be pretty easy to implement.
Could you provide any examples of the API you would find convenient? Trying to see what exactly you're missing.
If you just want to unbind a specific event, you can always use removeEventListener so I assume it's mass unbinding that you're missing, right?

@dzek69
Copy link
Author

dzek69 commented Jan 13, 2016

Unbinding events requires to pass handler function, so it's not very convinient to bind with anonymous function as I cannot unbind such events without getting inside Bliss listeners storage.

I haven't thought about any specific API call example - I just need a way to do that.

A jQuery-like mechanism with ability to "name" or "group" events by "class name" and unbind events with that class name would be nice.

jQuery example:

$('a').click(function() { /* ... */ });
$('a').bind('click.someName change.someName', function() { /* ... */ });
$('a').bind('click.someOtherName', handlerFunction);

$('a').unbind('.someName');
// two event handlers still attached, one click and one change event removed
$('a').unbind('click');
// no event handlers left

So maybe this should be equivalent:

$('a')._.events({
  'click': function() {},
  'click.someName change.someName':  function() {},
  'click.someOtherName': handlerFunction
});

$('a')._.removeEvents('.someName');
// same effect as above
$('a')._.removeEvents('click');
// no events left

// This should also work:
$('a')._.removeEvents(); // will remove everything
$('a')._.removeEvents('click change'); // will remove everything in this example
$('a')._.removeEvents('click.someOtherName click.someName'); // will leave change and "classless" click event

@LeaVerou
Copy link
Owner

LeaVerou commented Feb 2, 2016

This is definitely useful functionality that I'm interested in implementing.

@LeaVerou LeaVerou changed the title Unbind events/deletagions Unbind events/delegations Feb 7, 2016
@LeaVerou
Copy link
Owner

Do you think this should only apply to events attached via $.events or also events attached via addEventListener? Since we wrap addEventListener in Bliss Full, the latter is also possible, but I’m a bit worried it might be too intrusive. Do people use periods in their event names for other reasons?

@dzek69
Copy link
Author

dzek69 commented Feb 13, 2016

PERSONALLY I would like it to work with addEventListener too. I don't know about the others. I never heard about naming events with periods. A notice in the docs would be enough for me.

@LeaVerou
Copy link
Owner

It’s actually much easier to implement that way, so that’s what I’m doing.

@dzek69
Copy link
Author

dzek69 commented Feb 13, 2016

Awesome, thanks.

@LeaVerou LeaVerou self-assigned this Feb 13, 2016
@LeaVerou
Copy link
Owner

@dzek69 I pushed and added some docs :) It still needs tests though.

LeaVerou added a commit that referenced this issue Feb 17, 2016
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

2 participants