wv
weak-value
npm i weak-value
wv

weak-value

A Map with weakly referenced values, instead of keys

by Andrea Giammarchi

1.0.2 (see all)License:ISCTypeScript:Not Found
npm i weak-value
Readme

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.

Downloads/wk

183

GitHub Stars

21

LAST COMMIT

1yr ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
1.0.2
latest
11d ago
No alternatives found
No tutorials found
Add a tutorial

Rate & Review

100
No reviews found
Be the first to rate