Created
August 20, 2021 14:20
-
-
Save darkcris1/adc08476ed5920e4070a2fe9a36d9531 to your computer and use it in GitHub Desktop.
An action for svelte to dynamically add listenera
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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