git ssb

1+

Matt McKegg / mutant



Tree: 56963dca8e160319d630c173c0f3b003996ae919

Files: 56963dca8e160319d630c173c0f3b003996ae919 / 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