Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tobes31415/dispose

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tobes31415/dispose

Dispose objects using the decorator pattern

  • 4.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
142
decreased by-19.77%
Maintainers
1
Weekly downloads
 
Created
Source

Dispose

A tiny library to register callbacks on objects so that they get properly disposed at a later time even if you have complex trees of objects. What makes this library special enough to post is that instead of modifying the class that define the objects themselves it uses on the decorator pattern to modify objects on the fly. This means you can attach behaviour to objects coming from libraries and frameworks and even other parts of your own code. You can also directly attach behaviour to arrays and maps of objects as well.

The real advantage comes when you're dealing with large trees of objects and/or objects communicating between multiple contexts. Local user wants to disconnect? Dispose the connection to send a goodbye message and then clean up your local resources. Remote user sent a goodbye message? Dispose your connection to clean up your resources locally for no added effort. Session Timed out? network errors? Any of these you can just call dispose and trust that your objects will disconnect themselves gracefully without having to handle all the edge cases yourself. Each small piece of code handles disposing itself properly, and anyone in the code can trigger the dispose without needing knowledge of how that will work.

View API Docs

Installation

npm install --save @tobes31415/dispose

Basic Useage

import { onDispose, dispose } from "@tobes31415/dispose"

onDispose(foo, () => {
  //release resources
  //disconnect from servers, etc
});

dispose(foo);

Keywords

FAQs

Package last updated on 10 Jun 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc