weak-value

1.0.2 • Public • Published

WeakValue

Build Status Coverage Status

A Map with weakly referenced values, instead of keys, with an optional onValueCollected callback to pass aslong.

In Node.js, it requires V8 release v8.4 or greater.

import WeakValue from 'weak-value';
// const WeakValue = require('weak-value');

const wv = new WeakValue;

(() => {
  const value = {};
  wv.set('any-key', value, /* optional */ (key, map) => {
    // will log "any-key value collected" once GC kicks in
    console.log(key, 'value collected');
    console.log(map === wv);  // true
  });
})();

Please note that explicit wv.delete(key) will NOT invoke onValueCollected, as deleting a key does not mean its referenced value has been collected.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    5
    • latest

Version History

Package Sidebar

Install

npm i weak-value

Weekly Downloads

166

Version

1.0.2

License

ISC

Unpacked Size

6.54 kB

Total Files

6

Last publish

Collaborators

  • webreflection