Skip to content

Instantly share code, notes, and snippets.

@giuseppeg
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuseppeg/bf609a4bd86121e995fa to your computer and use it in GitHub Desktop.
Save giuseppeg/bf609a4bd86121e995fa to your computer and use it in GitHub Desktop.
unbind proxied event in FlightJS - patch idea
this.off = function() {
var $element, type, proxiedTo, callback;
var lastIndex = arguments.length - 1, origin = arguments[lastIndex];
if (typeof origin == 'function') {
callback = origin;
arguments[lastIndex] = undefined;
}
if (lastIndex == 1) {
type = arguments[0];
proxiedTo = registry.findInstanceInfo(this).events.some(function (event) {
// this.off('event', 'proxy')
return event.type == type;
});
// if this.off('.selector', 'event')
// we increase lastIndex so that we fall in the 1st case of the if below [1]
if (!proxiedTo) {
lastIndex += 1;
}
}
// [1]
if (lastIndex == 2) {
// this.off(selector, 'event', fn)
// this.off(selector, 'event', 'proxy')
// this.off(selector, 'event')
$element = $(arguments[0]);
type = arguments[1];
// arguments[2] is undefined if origin was a fn (callback)
// or it is our 'proxied event name' string
proxiedTo = arguments[2];
} else {
// this.off('event', fn)
// this.off('event', 'proxy')
// this.off('event')
$element = this.$node;
type = arguments[0];
// arguments[1] is undefined if origin was a fn (callback)
// or it is our 'proxied event name' string
proxiedTo = arguments[1];
}
/* ... */
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment