object-fit-polyfill icon indicating copy to clipboard operation
object-fit-polyfill copied to clipboard

Make global listeners optional

Open andrejpavlovic opened this issue 7 years ago • 3 comments

Would it be possible to make attaching global listeners optional? I think the library should not have any side-effects unless the user opts-in somehow.

https://github.com/constancecchen/object-fit-polyfill/blob/763f6cafdff704e6957ddad164c281a75068656f/src/objectFitPolyfill.basic.js#L182-L187

andrejpavlovic avatar Aug 02 '18 02:08 andrejpavlovic

Ahh man, that's a great question. I definitely see the use case especially for applications using JS frameworks like React, etc., where they're gonna have to manually call objectFitPolyfill() anyway, or more gung-ho folks who want to roll their own resize throttler/debouncer for performance.

That being said I also do know that a majority of users want it to "just work" out of the box without really having to think about it (in theory that's how polyfills vs. generic JS libs/helpers should work - silently mimicking default browser behavior w/o users having to manually do it)

I could throw in an extra objectFitPolyfill.diy.js file that just removes the lines/listeners you linked, and let folks use that. I'll keep this thread open to see what demand is like and how many other folks +1/want this - in the meanwhile, could I suggest forking? Since it's just a few lines, it should hopefully be super easy to remove the listeners for your use-case/project.

cee-chen avatar Aug 23 '18 18:08 cee-chen

Yep, fork I did. Just thought I'd make a feature request anyway. https://github.com/allboatsrise/object-fit-polyfill/commit/4f72c9d6dd31faeb831ba8b9f638d5d33af40ca4

andrejpavlovic avatar Aug 28 '18 04:08 andrejpavlovic

+1, would be great to be able to have no side effects!

fthues avatar Nov 30 '18 11:11 fthues