flightjs / flight

A component-based, event-driven JavaScript framework from Twitter
http://flightjs.github.io/
MIT License
6.53k stars 547 forks source link

Add functionality to unbind events of specific child elements #317

Open gabrielhpugliese opened 10 years ago

gabrielhpugliese commented 10 years ago

As mentioned here, it would be nice to unbind events of specific child elements inside components, like:

this.on('click', { 
  buttonSelector: this.calculateShippingPrice,
  inputSelector: this.calculateShippingPrice 
});

this.off('buttonSelector', 'click'); // <--- this
tgvashworth commented 10 years ago

To differentiate between delegated and directly bound events, we'll probably need a syntax like this:

this.off('click', { 
  buttonSelector: this.calculateShippingPrice
});
gabrielhpugliese commented 10 years ago

What if I don't want to call this.calculateShippingPrice. How would the syntax be?

giuseppeg commented 10 years ago

This may be not that straightforward, because all we have is a function (the rules live in its closure). https://github.com/flightjs/flight/blob/master/lib/utils.js#L235

tgvashworth commented 10 years ago

Yeah, this'll definitely require some redoing of the delegation stuff.