Skip to content

Commit

Permalink
Use callback as event part listener (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroliu authored and justinfagnani committed Oct 23, 2018
1 parent 2f538ed commit 6d83453
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,13 @@ export class EventPart implements Part {
value: any = undefined;
_options?: {capture?: boolean, passive?: boolean, once?: boolean};
_pendingValue: any = undefined;
_boundHandleEvent: (event: Event) => void;

constructor(element: Element, eventName: string, eventContext?: EventTarget) {
this.element = element;
this.eventName = eventName;
this.eventContext = eventContext;
this._boundHandleEvent = (e) => this.handleEvent(e);
}

setValue(value: any): void {
Expand Down Expand Up @@ -469,11 +471,13 @@ export class EventPart implements Part {
newListener != null && (oldListener == null || shouldRemoveListener);

if (shouldRemoveListener) {
this.element.removeEventListener(this.eventName, this, this._options);
this.element.removeEventListener(
this.eventName, this._boundHandleEvent, this._options);
}
this._options = getOptions(newListener);
if (shouldAddListener) {
this.element.addEventListener(this.eventName, this, this._options);
this.element.addEventListener(
this.eventName, this._boundHandleEvent, this._options);
}
this.value = newListener;
this._pendingValue = noChange;
Expand Down

0 comments on commit 6d83453

Please sign in to comment.