You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{DomListener}from"observer-pattern-js";classHeaderComponentextendsDomListener{constructor(){super({element: document.querySelector('h1')asHTMLElement,// You must implement methods such as onClick, onDblclick, onContextmenu in your class, // otherwise there will be an error.eventNames: ['click','dblclick','contextmenu'],});this.init();}privateinit(): void{// When this method is called, the DomListener class adds the event you specified // ({eventNames: ['click', 'dblclick', 'contextmenu']}) to the html element you // specified ({element: document.querySelector ('h1') as HTMLElement,}).this.initDomListener();}privateonClick(event: Event): void{console.log('click',event.target);}privateonDblclick(event: Event): void{console.log('dblclick',event.target);}privateonContextmenu(event: Event): void{console.log('context menu',event.target);}publicdestroy(): void{// When this method is called, the DomListener class removes the event // you specified ({eventNames: ['click', 'dblclick', 'contextmenu']}) from the specified // html element ({element: document.querySelector ('h1') as HTMLElement,}).this.removeDomListener();}}constheaderComponent=newHeaderComponent();