Skip to content

Commit d332a0e

Browse files
committed
feat(zip): supports promises, iterables and lowercase-o observables
- renames spec file appropriately - removes limit functionality from zip, as it is not used by combineLatest any longer - adds support for promises, iterables, Observables and lowercase-o observables
1 parent ce76e4e commit d332a0e

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

spec/operators/zip-all-spec.js spec/operators/zipAll-spec.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
var Rx = require('../../dist/cjs/Rx');
33
var Observable = Rx.Observable;
44

5-
describe('zipAll', function () {
5+
describe('Observable.prototype.zipAll', function () {
66
it('should take all observables from the source and zip them', function (done) {
77
var expected = ['a1', 'b2', 'c3'];
88
var i = 0;
9-
Observable.fromArray([
10-
Observable.fromArray(['a', 'b', 'c']),
11-
Observable.fromArray([1, 2, 3])
12-
])
9+
Observable.of(
10+
Observable.of('a','b','c'),
11+
Observable.of(1,2,3)
12+
)
1313
.zipAll(function (a, b) {
1414
return a + b;
1515
})
@@ -21,10 +21,10 @@ describe('zipAll', function () {
2121
it('should zip until one child terminates', function (done) {
2222
var expected = ['a1', 'b2'];
2323
var i = 0;
24-
Observable.fromArray([
25-
Observable.fromArray(['a', 'b']),
26-
Observable.fromArray([1, 2, 3])
27-
])
24+
Observable.of(
25+
Observable.of('a','b','c'),
26+
Observable.of(1,2)
27+
)
2828
.zipAll(function (a, b) {
2929
return a + b;
3030
})

src/operators/zip-support.ts

+7-18
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class ZipSubscriber<T, R> extends OuterSubscriber<T, R> {
3030
active: number = 0;
3131
observables: Observable<any>[] = [];
3232
project: (...values: Array<any>) => R;
33-
limit: number = Number.POSITIVE_INFINITY;
3433
buffers: any[][] = [];
3534

3635
constructor(destination: Subscriber<R>,
@@ -61,51 +60,41 @@ export class ZipSubscriber<T, R> extends OuterSubscriber<T, R> {
6160
}
6261
}
6362

63+
6464
notifyNext(value: R, observable: T, index: number, observableIndex: number) {
6565
const buffers = this.buffers;
6666
buffers[observableIndex].push(value);
6767

6868
const len = buffers.length;
6969
for (let i = 0; i < len; i++) {
70-
let buffer = buffers[i];
71-
if(buffer.length === 0) {
70+
if(buffers[i].length === 0) {
7271
return;
7372
}
7473
}
7574

76-
const outbound = [];
75+
const args = [];
7776
const destination = this.destination;
7877
const project = this.project;
7978

8079
for(let i = 0; i < len; i++) {
81-
outbound.push(buffers[i].shift());
80+
args.push(buffers[i].shift());
8281
}
8382

8483
if(project) {
85-
let result = tryCatch(project)(outbound);
84+
let result = tryCatch(project).apply(this, args);
8685
if(result === errorObject){
8786
destination.error(errorObject.e);
8887
} else {
8988
destination.next(result);
9089
}
9190
} else {
92-
destination.next(outbound);
91+
destination.next(args);
9392
}
9493
}
9594

96-
notifyComplete(innerSubscriber) {
95+
notifyComplete() {
9796
if((this.active -= 1) === 0) {
9897
this.destination.complete();
99-
} else {
100-
this.limit = innerSubscriber.events;
10198
}
10299
}
103-
}
104-
105-
function arrayInitialize(length) {
106-
var arr = Array(length);
107-
for (let i = 0; i < length; i++) {
108-
arr[i] = null;
109-
}
110-
return arr;
111100
}

0 commit comments

Comments
 (0)