https://github.com/jabr/weak-value-map
A Javascript/ECMAScript map using weak references to values.
https://github.com/jabr/weak-value-map
Last synced: about 1 month ago
JSON representation
A Javascript/ECMAScript map using weak references to values.
- Host: GitHub
- URL: https://github.com/jabr/weak-value-map
- Owner: jabr
- License: mit
- Created: 2021-06-23T18:27:31.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-08T05:09:07.000Z (about 1 year ago)
- Last Synced: 2025-04-30T06:47:41.051Z (about 1 month ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# weak-value-map
A Javascript/ECMAScript map using weak references to values.
## Example
```js
import WeakValueMap from "../weak-value-map/index.js"
const wvm = new WeakValueMaplet obj = { a: 'x' }
wvm.set(42, obj)
wvm.get(42) // #=> { a: 'x' }obj = undefined
wvm.get(42) // #=> { a: 'x' }// GC happens...
wvm.get(42) // #=> undefined
[...wvm.keys()].includes(42) // #=> false
```## See also
* [ref-most-used](https://github.com/jabr/ref-most-used) - LRU/LFU cache of strong object references
## References
* [WeakRef](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
* [FinalizationRegistry](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry)## License
This project is licensed under the terms of the [MIT license](LICENSE.txt).