wnr / element-resize-detector

Optimized cross-browser resize listener for elements.
MIT License
1.32k stars 118 forks source link

Work with Element instead of HTMLElement? #100

Closed jasonkuhrt closed 5 years ago

jasonkuhrt commented 6 years ago

I haven't gone digging into the codebase yet. Do you think it should be possible to support element-type things or are the techniques being used only suitable for html-element-type things? The TypeScript types are currently:

// Type definitions for element-resize-detector 1.1
// Project: https://github.com/wnr/element-resize-detector
// Definitions by: Saransh Kataria <https://github.com/saranshkataria>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

declare function elementResizeDetectorMaker(options?: elementResizeDetectorMaker.ErdmOptions): elementResizeDetectorMaker.Erd;

declare namespace elementResizeDetectorMaker {
    interface ErdmOptions {
    strategy?: 'scroll' | 'object';
    }

    interface Erd {
    listenTo(element: HTMLElement, callback: (elem: HTMLElement) => void): void;
    removeListener(element: HTMLElement, callback: (elem: HTMLElement) => void): void;
    removeAllListeners(element: HTMLElement): void;
    uninstall(element: HTMLElement): void;
    }
}
export = elementResizeDetectorMaker;
wnr commented 5 years ago

Hi, and sorry for the late response.

I'm unsure what you want changed in this project, as there is no TypeScript in this lib. Regarding the html-element vs element question, I'm honestly not sure what the difference is. It seems like html-element is correct.

jasonkuhrt commented 5 years ago

These come from definitely typed. Element type allows for things like an svg element. It’s more general.

wnr commented 5 years ago

Okay, so if I understand you correctly you are asking me if it would be a good idea to change some type definition in another repo to accepting a more general type of input. I don't have a definite answer to that, but I would guess that this library does not work with non-HTMLElements such as an svg element. One reason is due to the fact that it injects HTMLElements into the target, so I assume there are some non-HTMLElements that would not accept that.