alvaromartmart / types-openseadragon

Types declaration file for OpenSeadragon library (moved to DefinitelyTyped)
https://www.npmjs.com/package/@types/openseadragon
GNU General Public License v3.0
6 stars 9 forks source link

Event types #14

Open stephenwf opened 4 years ago

stephenwf commented 4 years ago

I know this is now published to DT, but thought this would be the best place to discuss and get in touch. I've independently also created types for OpenSeadragon, they're unsurprisingly similar! One thing I did spend more time focussing on was the event system. It's not fully tested yet (why it's still just local to that repository for now) but thought it might be of interest to you.

Types can be found here: https://github.com/stephenwf/use-open-seadragon/tree/master/src/types Utility for event handling: https://github.com/stephenwf/use-open-seadragon/blob/master/src/types/util.ts#L51-L58 Example event list for a class: https://github.com/stephenwf/use-open-seadragon/blob/master/src/types/viewer.ts Event source base class: https://github.com/stephenwf/use-open-seadragon/blob/master/src/types/event-source.ts

The base class lets you get the types on these types of handler functions, but only the ones supported by the class:

viewer.addHandler('zoom', e => {
  console.log(e) // { zoom: number; refPoint: Point;  immediately: boolean; }
})

and:

viewer.addHandler('press', e =>  ... ); // would error
viewer.homeButton.addHandler('press', e =>  ... ); // would not