git ssb

1+

Matt McKegg / mutant



Tree: e9d4ab45391a98cd08092fe447f7cd7c3732779b

Files: e9d4ab45391a98cd08092fe447f7cd7c3732779b / 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.delete(key)
32 }
33
34 return observable
35}
36

Built with git-ssb-web