git ssb

1+

Matt McKegg / mutant



Tree: f9d0929f645b84d8c2ec25f4189c76ba545cecb0

Files: f9d0929f645b84d8c2ec25f4189c76ba545cecb0 / concat.js

990 bytesRaw
1var resolve = require('./resolve')
2var addCollectionMethods = require('./lib/add-collection-methods')
3var computed = require('./computed')
4
5module.exports = function Concat (observables) {
6 var values = []
7 var rawValues = []
8
9 var instance = computed.extended(observables, function () {
10 var index = 0
11
12 forEach(observables, function (collection) {
13 forEach(collection, function (item) {
14 var value = resolve(item)
15 values[index] = value
16 rawValues[index] = item
17 index += 1
18 })
19 })
20
21 values.length = index
22 rawValues.length = index
23 return values
24 })
25
26 var result = function MutantConcat (listener) {
27 return instance(listener)
28 }
29
30 // getLength, get, indexOf, etc
31 addCollectionMethods(result, rawValues, instance.checkUpdated)
32
33 return result
34}
35
36function forEach (sources, fn) {
37 if (sources && !sources.forEach) {
38 sources = resolve(sources)
39 }
40
41 if (sources && sources.forEach) {
42 sources.forEach(fn)
43 }
44}
45

Built with git-ssb-web