Gathering detailed insights and metrics for trashable
Gathering detailed insights and metrics for trashable
Gathering detailed insights and metrics for trashable
Gathering detailed insights and metrics for trashable
trashable-react
A HOC to make React Components garbage collectable when unmounted.
mongoose-trashable
a mongoose plugin adding ablity to model instance to be trashed (soft deleted) / untrashed
@types/trashable
TypeScript definitions for trashable
react-trashable
React components for trashing promises when components unmount.
🚮 A wrapper to make promises cancellable and garbage collectable
npm install trashable
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
84 Stars
38 Commits
9 Forks
2 Watchers
3 Branches
4 Contributors
Updated on Oct 09, 2024
Latest Version
1.0.7
Package Id
trashable@1.0.7
Unpacked Size
141.29 kB
Size
38.84 kB
File Count
14
NPM Version
5.3.0
Node Version
8.1.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A wrapper to make promises cancellable and garbage collectable. See how this relates to React below and use trashable-react to make your React components garbage collectable.
1npm install --save trashable
1import makeTrashable from 'trashable'; 2 3let promise = new Promise((resolve) => { 4 setTimeout(resolve, 10000); 5}); 6 7let trashablePromise = makeTrashable(promise); 8trashablePromise.then(() => { 9 console.log('10 seconds have passed'); 10}); 11 12trashablePromise.trash();
You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.
— Joe Armstrong
The handlers you pass to promises often reference other objects. These objects can be quick large. This means if the promise is still in flight (not resolved or rejected), these large objects cannot be safely garbage collected even when the promise result has been forgotten and been ignored. That is why canceling promises so that the objects their handlers reference can be freed is so important.
In particular, this issue has reared its head in React with the use of
isMount()
method (now deprecated). This article
gives a good explanation for why using isMount()
should be avoided. Simply
put, prevents a garbage collector from getting rid of potentially large React
Elements.
It recommends to clean up any callbacks in componentWillUnmount
so that they
won't call setState()
after the element has been unmounted and thus continue
to reference the Element.
Unfortunately, this is not that easy if promises are used and the solution it provides in that article actually doesn't solve the garbage collection problem. The cancel method does nothing to dereference the handlers and the Element will not be garbage collected (see more in the PROOF).
Use trashable-react to make your React components garbage collectable.
Unlike other cancelable promise libraries, Trashable actually dereferences the promise handlers so that objects that were referenced can be garbaged collected appropriately, freeing up memory.
You need to make your promises trashable before you add your then
and
catch
handlers. Otherwise, you will not get the garbage collection benefits.
1// Do this 2const trashablePromise = makeTrashable(promise); 3trashablePromise.then(() => {}); 4 5// NOT this 6const handledPromise = promise.then(() => {}); 7makeTrashable(handledPromise);
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/25 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
66 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More