developit / simple-element-resize-detector

Observes element size changes using a hidden iframe
189 stars 7 forks source link

Pass element to handler #3

Closed fregante closed 7 years ago

fregante commented 7 years ago

It's useful when the handler is defined elsewhere:

function handler (element) {
    //
}

observeResize(document.querySelector('.on-the-fly'), handler);
developit commented 7 years ago

/cc @NekR who made me remove this feature :rofl:

I'm fine adding it FWIW.

fregante commented 7 years ago

I don't know, I have never seen an event handler called without any reference to the element. Even node-land EventEmitter has a reference to the emitter in this

developit commented 7 years ago

I had originally invoked the handler with this as the element, but I believe this breaks for arrow functions.

fregante commented 7 years ago

Correct. Passing it as argument is more flexible anyway

NekR commented 7 years ago

@developit okay-okay, pass it if people want it (although node.js argument doesn't really work for me :-)). LGTM 👍

developit commented 7 years ago

Released as 1.1.0