feat(turbo): add on
method to stimulus application controller
This commit is contained in:
parent
2eaf486372
commit
cfb83bbdda
1 changed files with 15 additions and 0 deletions
|
@ -22,4 +22,19 @@ export class ApplicationController extends Controller {
|
|||
target: document.documentElement
|
||||
});
|
||||
}
|
||||
|
||||
protected on<HandlerEvent extends Event = Event>(
|
||||
eventName: string,
|
||||
handler: (event: HandlerEvent) => void
|
||||
): void {
|
||||
const disconnect = this.disconnect;
|
||||
const callback = (event: Event): void => {
|
||||
handler(event as HandlerEvent);
|
||||
};
|
||||
this.element.addEventListener(eventName, callback);
|
||||
this.disconnect = () => {
|
||||
this.element.removeEventListener(eventName, callback);
|
||||
disconnect.call(this);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue