Skip to content

Instantly share code, notes, and snippets.

@dmytro-y-dev
Last active August 23, 2017 16:24
Show Gist options
  • Save dmytro-y-dev/2dc14f13ee1ba7f77f1479fb53ebd618 to your computer and use it in GitHub Desktop.
Save dmytro-y-dev/2dc14f13ee1ba7f77f1479fb53ebd618 to your computer and use it in GitHub Desktop.
Example of how to accurately detach your event from jQuery handlers.
const table; /* DOM Element that reacts to resize event */
// Initialize table
const __sync = () { /* some happy crappy code */ };
$(window).on('resize', null, {
type: 'sticky-table-handler',
table: table
}, __sync);
__sync();
// ... User plays around with table here ...
// Bye table! Let's remove resize event that was assigned for specific table.
$.each(
$._data(window, 'events').resize,
(index, eventHandler) => {
if (eventHandler.data &&
eventHandler.data.type === 'sticky-table-handler' &&
eventHandler.data.table === table)
{
$._data(window, 'events').resize.splice(index, 1);
return false;
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment