
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
add-weak-listener
Advanced tools
Add weak event listeners from your components/classes based on WeakRefs. This package handles the boilerplate for you, which isn't too much anyways but not particularly good looking.
Typescript defintions are included.
Event listeners are often a source of memory leaks. As the listener maintains a strong depedency to the callback which is in turn dependent on the object/closure, the closure/object is never Garbage collected.
See this awesome article by folks on v8 team, for a detailed explanation.
$ npm i add-weak-listener
import addWeakListener from 'add-weak-listener';
class MyComponent {
constructor() {
// This event listener will be cleaned by the garbage collector
// when the an object of MyComponent is GC'd.
addWeakListener(
window, // Event Target window / element / socket etc
'message', // Event type
this.listener, // The listener callback
{ once: true } // (optional) addEventListener options
)
}
private listener = (ev) => {
// do something here.
}
}
FAQs
Add weak event listeners based on WeakRefs
The npm package add-weak-listener receives a total of 3 weekly downloads. As such, add-weak-listener popularity was classified as not popular.
We found that add-weak-listener demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.