Skip to content

mafintosh/thunky-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thunky-map

A map version of thunky

npm install thunky-map

Usage

const ThunkyMap = require('thunky-map')

const m = new ThunkyMap(function (key, cb) {
  // load the resource async
  // only ran once per key
  setTimeout(function () {
    cb(null, key)
  }, 1000)
})

// triggers the load function above
m.get('hi', function (err, val) {
  // ...
})

// does not as it's already running
m.get('hi', function (err, val) {
  // ...
})

API

m = new ThunkyMap(load)

Make a new ThunkyMap instance. load should be a function taking a key and callback argument and should return a value.

m.get(key, cb)

Get a key. Triggers the load if the key hasn't been loaded before.

m.delete(key)

Delete a value

m.has(key)

Check if the map has a value

License

MIT

About

A map version of thunky

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published