Skip to content

Instantly share code, notes, and snippets.

@AlbertoDePena
Created April 11, 2018 14:24
Show Gist options
  • Save AlbertoDePena/b7844499bd36ee436d1b7e8943bdff61 to your computer and use it in GitHub Desktop.
Save AlbertoDePena/b7844499bd36ee436d1b7e8943bdff61 to your computer and use it in GitHub Desktop.
export class EventDispatcher {
public static dispatch(element: Element, eventName: string, args?: any): boolean {
let customEvent: CustomEvent;
if ((window as any).CustomEvent) {
customEvent = new CustomEvent(eventName, {
detail: { args: args },
bubbles: true
});
} else {
customEvent = document.createEvent('CustomEvent');
customEvent.initCustomEvent(eventName, true, true, {
detail: { args: args }
});
}
element.dispatchEvent(customEvent);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment