git ssb

1+

Matt McKegg / mutant



Tree: cbf829de3c92ce641590e320ffd3f2fb07a3cf61

Files: cbf829de3c92ce641590e320ffd3f2fb07a3cf61 / concat.js

1133 bytesRaw
1var computed = require('./computed')
2
3module.exports = function Concat (observables) {
4 var values = []
5 var rawValues = []
6
7 var result = computed(observables, function (args) {
8 var index = 0
9 for (var i = 0; i < arguments.length; i++) {
10 for (var x = 0; x < arguments[i].length; x++) {
11 var value = arguments[i][x]
12 var raw = get(observables[i], x)
13 values[index] = value
14 rawValues[index] = raw
15 index += 1
16 }
17 }
18 values.length = index
19 rawValues.length = index
20 return values
21 })
22
23 result.get = function (index) {
24 return rawValues[index]
25 }
26
27 result.getLength = function (index) {
28 return rawValues.length
29 }
30
31 result.includes = function (valueOrObs) {
32 return !!~rawValues.indexOf(valueOrObs)
33 }
34
35 result.indexOf = function (valueOrObs) {
36 return rawValues.indexOf(valueOrObs)
37 }
38
39 return result
40}
41
42function get (target, index) {
43 if (typeof target === 'function' && !target.get) {
44 target = target()
45 }
46
47 if (Array.isArray(target)) {
48 return target[index]
49 } else if (target && target.get) {
50 return target.get(index)
51 }
52}
53

Built with git-ssb-web