Skip to content

Instantly share code, notes, and snippets.

@darkcris1
Created August 20, 2021 14:20
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 darkcris1/adc08476ed5920e4070a2fe9a36d9531 to your computer and use it in GitHub Desktop.
Save darkcris1/adc08476ed5920e4070a2fe9a36d9531 to your computer and use it in GitHub Desktop.
An action for svelte to dynamically add listenera
export function getEventsAction() {
const component = get_current_component();
return node => {
const events = Object.keys(component.$$.callbacks);
const listeners = [];
events.forEach(
event => listeners.push(
listen(node, event, e => bubble(component, e))
)
);
return {
destroy: () => {
listeners.forEach(
listener => listener()
);
}
}
};
}
// Use case//
// <Component on:click={} on:mousedown={}/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment