Skip to content

WebReflection/weak-value

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WeakValue

📣 Check out not-so-weak module for better and faster WValue alternative


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.

About

A Map with weakly referenced values, instead of keys

Resources

License

Stars

Watchers

Forks

Packages

No packages published