weakmap-shim
A minimal weakmap shim
Last updated 8 years ago by raynos .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install weakmap-shim 
SYNC missed versions from official npm registry.

weakmap-shim

A minimal weakmap shim

Example

var weakMap = require("weakmap-shim")

var map = weakMap()
var key = {}

map.set(key, 'some value')
var v = map.get(key) // 'some value'

create-store Example

var createStore = require('weakmap-shim/create-store')

var store = createStore()
var key = {}

var value = store(key)

// `value` is weakly bound to `key`. `value` is a plain object
value.foo = 'bar'

var value2 = store(key)

var v = value2.foo; // 'bar'
var bool = value === value2; // true

Motivation

Benvie has an excellent weakmap module that's far more robust. However it contains quite a bit of loc.

  • weakmap : 7451 bytes
  • weakmap-shim : 2106 bytes
  • weakmap-shim/create-store : 1311 bytes

This module is only worthwhile if you want to add a weakmap to a small module (10 - 30 loc) and dont want to bloat it with a heavier weakmap

Installation

npm install weakmap-shim

Contributors

  • Raynos

MIT Licenced

Current Tags

  • 1.1.1                                ...           latest (8 years ago)

3 Versions

  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 3
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE