Last active
April 24, 2016 16:01
-
-
Save TheLarkInn/d3b0ee4d3647331b70d07b5519a12f09 to your computer and use it in GitHub Desktop.
A more successful way to implement the addEventListener function for Multiple events bindings.
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
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function { | |
var zone = this.manager.getZone(); | |
var eventsArray = this.getMultiEventArray(eventName); | |
// Entering back into angular to trigger changeDetection | |
var outsideHandler = (event) => { | |
zone.run(() => handler(event)) | |
}; | |
// Executed outside of angular so that change detection is not constantly triggered. | |
var addAndRemoveHostListenersForOutsideEvents = () => { | |
eventsArray.forEach((singleEventName: string) => { | |
// Sending the events back up to this.manager allows the events to be handled by the appropriate plugin | |
this.manager.addEventListener(element, singleEventName, outsideHandler); | |
}); | |
} | |
return this.manager.getZone().runOutsideAngular(addAndRemoveHostListenersForOutsideEvents); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment