Add weak event listeners from your components/classes based on WeakRefs

Overview

Add weak Listener

npm version

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.

Why ?

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.

Usage

$ 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.
  }
}
You might also like...

Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Jan 1, 2023

An RSS reader running entirely from your GitHub repo.

An RSS reader running entirely from your GitHub repo.

Turn GitHub into an RSS reader

Dec 31, 2022

Web app for adding EU Digital COVID Certificates to your wallet apps

Web app for adding EU Digital COVID Certificates to your wallet apps

Web app for adding EU Digital COVID Certificates to your wallet apps

Dec 31, 2022

BetterDiscord plugin to see what your friends are playing across platforms, all on Discord

BetterDiscord plugin to see what your friends are playing across platforms, all on Discord

CrossPlatformPlaying A plugin that brings Rich Presence to games that don't support it, and lets you see what your friends are playing even if they tu

Dec 12, 2022

A Sequelize web builder interface. To make your own sequelize schema

A Sequelize web builder interface. To make your own sequelize schema

Mar 9, 2022

A personal home page for quick access to all your personal apps/sites

A personal home page for quick access to all your personal apps/sites

Fenrus Fenrus personal home page/dasbhoard. It allows you to have a custom home page/new tab page with quick access to your personal apps. For support

Dec 31, 2022

A cool Discord bot to manage tickets on your server 🎫

A cool Discord bot to manage tickets on your server 🎫

Discord Tickets Bot A cool Discord bot to manage tickets on your server 🎫 Project under construction... follow the progress on the Discord server. If

Oct 10, 2022

A ~2kb hotkeys library for solid that adds only 2 event listeners.

A ~2kb hotkeys library for solid that adds only 2 event listeners.

Solid Hotkeys - Cmd+S+H Solid Hotkeys is the easiest way to add hotkeys to your application. Built for and with Solid. Motivation You gotta have hotke

Aug 1, 2022

To keep online organized data and be able to add listeners in certain paths by socket.io and http clients

To keep online organized data and be able to add listeners in certain paths by socket.io and http clients

The purpose of this project is to create a state machine server to keep organized data and be able to add listeners with socket.io in specific paths and in addition to providing a possible form of messages between socket.io clients.

Mar 19, 2022

πŸ€– Tailwind CSS assistant helps you to edit classes (includes JIT & ignores purge), toggle breakpoint classes on an element and view current breakpoint

πŸ€– Tailwind CSS assistant helps you to edit classes (includes JIT & ignores purge), toggle breakpoint classes on an element and view current breakpoint

Tailwind CSS Assistant See it in action on this example website πŸŽ‰ βœ… Small JavaScript package that helps you work with Tailwind CSS by... Showing you

Dec 28, 2022

io-ts Typed Event Bus for the runtime of your Node.js application. A core for any event-driven architecture based app.

Typed Event Bus Based on io-ts types, this bus provides a handy interface to publish and consume events in the current runtime of the Node.js process.

May 23, 2022

'event-driven' library aims to simplify building backends in an event driven style

'event-driven' library aims to simplify building backends in an event driven style

'event-driven' library aims to simplify building backends in an event driven style(event driven architecture). For message broker, light weight Redis Stream is used and for event store, the well known NoSQL database, MongoDB, is used.

Jan 4, 2023

This plugin add a new utilities classes so you can use from 0% to 100%!

This plugin add new utilities classes so you can use from 0% to 100%!

Apr 3, 2022

A package of small but beautiful React components from the planet, Pluto. πŸ”΅ Get minimal components for your React based applications 😍

A package of small but beautiful React components from the planet, Pluto. πŸ”΅ Get minimal components for your React based applications 😍

React Pluto Component Design System + UI Kit A package of small but beautiful React components from the planet Pluto. To install the latest version, r

Aug 8, 2022

we are make our components in story book. So if we add some components you can find document and example of useage in storybook.

we are make our components in story book. So if we add some components you can find document and example of useage in storybook.

we are make our components in story book. So if we add some components you can find document and example of useage in storybook.

Aug 12, 2022

Hi there! This is a react native starter which used to build a awesome Event Booking App based on the Figma design. You can download or clone it to speed up your projects.

Hi there! This is a react native starter which used to build a awesome Event Booking App based on the Figma design. You can download or clone it to speed up your projects.

mcrn-event-booking-app-starter Hi there! This is a react native starter which used to build a awesome Event Booking App based on the Figma design. You

Dec 19, 2022

The invoker based on event model provides an elegant way to call your methods in another container via promisify functions

The invoker based on event model provides an elegant way to call your methods in another container via promisify functions. (like child-processes, iframe, web worker etc).

Dec 29, 2022
Releases(1.0.10)
Owner
Ashish Shubham
No business like the show business!
Ashish Shubham
A-Frame components implementing multiple cameras

aframe-multi-camera multi-camera.mp4 Overview This repository contains components that can be used to create multi-camera scenes in A-Frame. Cameras c

Diarmid Mackenzie 14 Oct 10, 2022
Estrela - a JavaScript library for building reactive web components inspired by lit

Estrela ⭐ Full Reactive Web Components Estrela is a JavaScript library for building reactive web components inspired by lit. Just like Lit, Estrela is

null 50 Oct 31, 2022
Custom HTML elements for generic components (dropdown, modal...) without style.

Headless elements The goal of this project is to create a library of Custom Elements to stop reinventing the wheel (starting by reinventing the wheel

Jonathan 21 Sep 17, 2022
A simple implementation of a task list application that can be used to add, remove, edit and check users tasks

"To-do list" is a tool that helps to organize daily activites. It simply lists the things which are needed to be done and allows user to mark them as complete. In this step of project, the CRUD (create, update, delete) methods are implemented. This simple web page is built using webpack and served by a webpack dev server.

Zahra Arshia 5 Mar 28, 2022
Add WebAssembly ESM integration to Vite and support wasm-pack generated modules

Add WebAssembly ESM integration (aka. Webpack's asyncWebAssembly) to Vite and support wasm-pack generated modules

Menci ❀️ 78 Dec 26, 2022
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API

Huge thanks to for sponsoring me! Ky is a tiny and elegant HTTP client based on the browser Fetch API Ky targets modern browsers and Deno. For older b

Sindre Sorhus 8.5k Jan 2, 2023
A prebuilt Express JS Authentication & Authorization Project based on a REST API interface.

A prebuilt Express JS Authentication & Authorization Project based on a REST API interface. It has the basic authentication and Authorization routes with the latest security measures implemented so that your application is much more secure from day 1. You are welcome to build upon and extend this project as and when required.

Soumalya Bhattacharya 2 Oct 7, 2022
Folder structure-based PHP wiki documentation engine

Mad simple PHP wiki engine for auto-generating documentation webpage with it's own language

Vortex 5 Sep 5, 2022
Max is a Typescript-based Discord bot with many functionalities

Max is a Typescript-based Discord bot with many functionalities. He is both my learning curve for understanding Discord's API as well as my current passion project.

Jack Levreau 4 May 24, 2022
SPOILER ALERT! A happy little bit of javascript to hide spoilers on your site.

SPOILER ALERT! Don't spoil it! Hide copy and images with a bit of SVG blur. Taste on mouseover. Eat on click. Do you publish spoilers? Do you wish you

Joshua Hull 473 Sep 27, 2022