git ssb

1+

Matt McKegg / mutant



Tree: a86cbf4be984227b8ca313252ed4b61f4e66eb04

Files: a86cbf4be984227b8ca313252ed4b61f4e66eb04 / merge.js

1048 bytesRaw
1var computed = require('./computed')
2var resolve = require('./resolve')
3var forEach = require('./for-each')
4var forEachPair = require('./for-each-pair')
5var addLookupMethods = require('./lib/add-lookup-methods')
6
7module.exports = Merge
8
9function Merge (sources) {
10 var raw = {}
11 var value = {}
12 var keys = new Set()
13
14 var instance = computed.extended(sources, function update () {
15 var currentKeys = []
16
17 forEach(sources, function (source) {
18 forEachPair(source, function (key, rawValue) {
19 currentKeys.push(key)
20 keys.add(key)
21 raw[key] = rawValue
22 value[key] = resolve(rawValue)
23 })
24 })
25
26 // remove deleted keys
27 Array.from(keys.values()).filter(function (k) {
28 return !currentKeys.includes(k)
29 }).forEach(function (key) {
30 keys.delete(key)
31 delete raw[key]
32 delete value[key]
33 })
34
35 return value
36 })
37
38 var result = function MutantMerge (listener) {
39 return instance(listener)
40 }
41
42 addLookupMethods(result, raw, instance.checkUpdated)
43
44 return result
45}
46

Built with git-ssb-web