Skip to content

[FEATURE] Add removeExisting Option for Listener Management #3

@AndrewBarber

Description

@AndrewBarber

Is your feature request related to a problem? Please describe.
Currently, there's no way to control whether existing listeners should be preserved or removed when using mutationReady on an element multiple times. This can lead to duplicate callbacks.

Describe the solution you'd like
Add an options parameter with removeExisting flag:

mutationReady('.my-element', callback, { removeExisting: true });

This would:

  • Remove existing listeners when removeExisting is true
  • Keep current behaviour (multiple listeners) when false or undefined

Example Usage

// Clear existing and add new
mutationReady('.element', callback, { removeExisting: true });

// Current behaviour
mutationReady('.element', callback);

Additional context
Useful for SPAs where components might be mounted multiple times.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions