Files: 4c817e4a9ce3c28a60cc7547029ee43eb9d9f909 / concat.js
990 bytesRaw
1 | var resolve = require('./resolve') |
2 | var addCollectionMethods = require('./lib/add-collection-methods') |
3 | var computed = require('./computed') |
4 | |
5 | module.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 | |
36 | function 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