An open API service indexing awesome lists of open source software.

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.

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 WeakValueMap

let 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).