1.0.0 • Published 7 years ago
weaktuplemap v1.0.0
WeakTupleMap
A WeakMap which accepts multiple objects as a key. This lib is one of the several possible cache for memoize-immutable, but it can suit other use-cases as it implements a usual Map API.
Install
npm install --save WeakTupleMap
This lib has no dependency, but requires a native implementation of WeakMap.
Usage
Restrictions. A WeakTupleMap can only be used when:
- The key is only made of parts that have a non-primitive type
(
object
,array
, orfunction
). - The key always has the same number of parts.
var WeakTupleMap = require('WeakTupleMap');
var cache = new WeakTupleMap();
var keyPart1 = {};
var keyPart2 = function() { return 'yolo'; };
var keyPart3 = [];
var value = {any: 'thing'};
// Note that following keyPart tuples are wrapped in new arrays that are !==
// (otherwise a WeakMap would have been enough).
cache.set([keyPart1, keyPart2, keyPart3], value);
cache.has([keyPart1, keyPart2, keyPart3]) === true;
cache.get([keyPart1, keyPart2, keyPart3]) === value;
Author
License
MPL-2.0
1.0.0
7 years ago