Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
@tobes31415/dispose
Advanced tools
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.
npm install --save @tobes31415/dispose
import { onDispose, dispose } from "@tobes31415/dispose"
onDispose(foo, () => {
//release resources
//disconnect from servers, etc
});
dispose(foo);
import { isDisposed, assertNotDisposed, createDisposeableFunctionWrapper, dispose } from "@tobes31415/dispose"
if (isDisposed(foo)) {
foo = new Foo();
}
assertNotDisposed(bar); //throws exception if bar has been disposed
const baz = createDisposeableFunctionWrapper( (a,b,c) => a * b + c );
baz(1,2,3) //outputs 5
dispose(baz);
baz(1,2,3) // throws an exception
FAQs
Dispose objects using the decorator pattern
We found that @tobes31415/dispose demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.