Wraps a plugin with automatic listener-reference tracking.
When a middleware plugin intercepts addListener and wraps the listener
function, the adapter stores the wrapped reference. If the caller later
invokes removeListener with the original listener, the adapter cannot
find it — the reference has changed.
withListenerTracking solves this by wrapping the original listener with a
tracking wrapper in addListener and storing the original → wrapper
mapping. On removeListener, it resolves the original listener back to the
tracking wrapper before forwarding the call to the chain.
Wraps a plugin with automatic listener-reference tracking.
When a middleware plugin intercepts
addListenerand wraps the listener function, the adapter stores the wrapped reference. If the caller later invokesremoveListenerwith the original listener, the adapter cannot find it — the reference has changed.withListenerTrackingsolves this by wrapping the original listener with a tracking wrapper inaddListenerand storing theoriginal → wrappermapping. OnremoveListener, it resolves the original listener back to the tracking wrapper before forwarding the call to the chain.