Closed hirasso closed 1 year ago
Nice! I'd just suggest extracting the check window.matchMedia('(hover: hover)').matches
into a separate method with a descriptive name like isHoverSupported
or isTouchDevice
or similar.
Of course :)
Ready to go
Description
PR #47 introduced an issue where unmounting the plugin would throw an error, since based on context (desktop/touch) there ever was only one
listener
defined (eithermouseover
ortouchstart
).At first, I solved it by making sure each listener was defined before destroying it. But then I realized that a better approach is to define both listeners initially, ignoring the context, and then return early in the handlers based on context:
This makes it possible to change the behavior at runtime (think "mobile device mode" in the dev tools, for example). I realize that checking for
hover: hover
intouchstart
is a bit weird, but you never know what crazy devices are out there :)master
branchnpm run lint
)Additional information
No breaking changes.