splide icon indicating copy to clipboard operation
splide copied to clipboard

Splide is creating a large sum of event listeners

Open felixranesberger opened this issue 2 years ago • 2 comments

Checks

  • [X] Not a duplicate.
  • [X] Not a question, feature request, or anything other than a bug report directly related to Splide. Use Discussions for these topics: https://github.com/Splidejs/splide/discussions

Version

4.1.4

Description

If multiple Splide instances are created on a page, Splide creates multiple events for every instance. Can all instance events be grouped to a single event type?

Screenshot 2023-04-18 at 11 19 38

Example code that could fix the issue

type ResizeEventCallback = () => void

const onResizeEvents: ResizeEventCallback[] = [];

window.addEventListener('resize', () => {
    onResizeEvents.forEach(callback => callback());
})

const useScreen = () => ({
    onResize(callback: ResizeEventCallback) {
        onResizeEvents.push(callback);
    }
});

const { onResize } = useScreen();
onResize(() => {
    // do some stuf
});

Reproduction Link

No response

Steps to Reproduce

Create mutliple Splide sliders

Expected Behaviour

Splide creates a single event listener for all Splide instances of that event type.

felixranesberger avatar Apr 18 '23 09:04 felixranesberger

I think this might be an issue with how you're creating your keydown event listener and not with Splide.

Webberjo avatar May 19 '23 20:05 Webberjo

I think this might be an issue with how you're creating your keydown event listener and not with Splide.

Can you elaborate a bit further? Because I'm not creating any keydown event-listeners in my code. When I check the event origin, the keydown events are created by the splide esm bundle.

felixranesberger avatar Sep 18 '23 06:09 felixranesberger