@thundercraft5/weak-utils
v1.0.1
Published
A zero-dependency lightweight library for iterable weak collections and proxies.
Downloads
3
Maintainers
Readme
⇢ weak-utils
weak-utils
is a zero-dependency lightweight library written in TypeScript that provides weak reference utilities.
What does this do?
weak-utils
has 3 components:
IterableWeakMap<object, any>
- An iterable weak mapIterableWeakSet<object>
- An iterable weak setWeakProxy<object>
- A constructor that creates weak proxies over a target object which is weakly referenced and has support for a the standard proxy handlers and in addition to a finalizer method.
Usage
IterableWeakMap<object, any>
Use as you would a regular Map
or WeakMap
. Has all methods of Map
.
IterableWeakSet<object>
Use as you would a regular Set
or WeakSet
. Has all methods of Set
.
WeakProxy<object>
Use as you would a regular a regular proxy, supports revocable proxies as well.
This object works by registering a finalizer for the target value via FinalizationRegistry()
, then, when the target value is collected, the proxy is revoked.
The use cases for weak proxies are currently unknown in JS, I added this feature as the result of an experiment.
To register a finalizer method, pass a finalize()
method in the handler object.