]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/grim/node_modules/emissary/lib/helpers.js
89df58c34a0ee5f40695951bdcfea1f214e11ce1
2 var Behavior
, combineArray
, combineWithFunction
,
5 Behavior
= require('./behavior');
7 exports
.combine = function() {
9 args
= 1 <= arguments
.length
? __slice
.call(arguments
, 0) : [];
10 if (args
.length
=== 1 && Array
.isArray(args
[0])) {
11 return combineArray(args
[0]);
12 } else if (typeof args
[args
.length
- 1] === 'function') {
13 return combineWithFunction(args
);
15 throw new Error("Invalid object type");
19 combineArray = function(array
) {
21 return behavior
= new Behavior(function() {
22 var element
, i
, outputArray
, ready
, _i
, _len
,
24 outputArray
= array
.slice();
26 for (i
= _i
= 0, _len
= array
.length
; _i
< _len
; i
= ++_i
) {
28 if (element
.constructor.name
=== 'Behavior') {
29 (function(element
, i
) {
30 return _this
.subscribe(element
.onValue(function(value
, metadata
) {
32 outputArray
= outputArray
.slice();
34 outputArray
[i
] = value
;
36 return _this
.emitValue(outputArray
, metadata
);
43 return this.emitValue(outputArray
);
47 combineWithFunction = function(args
) {
50 return combineArray(args
).map(function(argsArray
) {
51 return fn
.apply(null, argsArray
);