git ssb

1+

Matt McKegg / mutant



Tree: ef9e5ab9d31b22070e49efa9d5db1f9b8f20b572

Files: ef9e5ab9d31b22070e49efa9d5db1f9b8f20b572 / mapped-dict.js

822 bytesRaw
1var MutantLookup = require('./lookup')
2var MutantDict = require('./dict')
3var DictToCollection = require('./dict-to-collection')
4
5module.exports = MutantMappedDict
6
7function MutantMappedDict (defaultItems, lambda, opts) {
8 opts = opts || {}
9
10 var list = MutantDict(defaultItems, {
11 comparer: opts.comparer
12 })
13
14 var observable = MutantLookup(DictToCollection(list), function (item, invalidateOn) {
15 var value = lambda(item.key, item.value, invalidateOn)
16 if (value[0] === item.key && value[1] === item.value) {
17 return item // passthru
18 } else {
19 return value
20 }
21 }, opts)
22
23 observable.set = list.set
24
25 observable.put = function (key, item) {
26 list.put(key, item)
27 return observable.get(key)
28 }
29
30 observable.delete = function (key) {
31 list.remove(key)
32 }
33
34 return observable
35}
36

Built with git-ssb-web