10BC0 GitHub - memoize-immutable/WeakTupleMap: A WeakMap which accepts multiple objects as a key.
[go: up one dir, main page]

Skip to content

memoize-immutable/WeakTupleMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WeakTupleMap npm version Build Status Dependency Status Coverage Status

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, or function).
  • 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

@louis_remi

License

MPL-2.0

About

A WeakMap which accepts multiple objects as a key.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0