Skip to content

Commit 6403d8a

Browse files
committed
WIP: Operate on any Subscribable
1 parent aff098b commit 6403d8a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

spec/operators/map-spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import { map, tap, mergeMap, take } from 'rxjs/operators';
33
import { TestScheduler } from 'rxjs/testing';
4-
import { of, Observable, identity } from 'rxjs';
4+
import { of, Observable, identity, Observer } from 'rxjs';
55
import { observableMatcher } from '../helpers/observableMatcher';
66

77
// function shortcuts
@@ -279,4 +279,29 @@ describe('map', () => {
279279

280280
expect(sideEffects).to.deep.equal([0, 1, 2]);
281281
});
282+
283+
describe('no lift', () => {
284+
it('can operate on any Observable-shaped object', () => {
285+
const source = {
286+
subscribe(observer: Observer<number>) {
287+
observer.next(1);
288+
observer.next(2);
289+
observer.next(3);
290+
observer.complete();
291+
return {
292+
unsubscribe() {
293+
// noop
294+
},
295+
};
296+
},
297+
};
298+
const results: any[] = [];
299+
300+
map((x: number) => x + '!!!')(source).subscribe((value: string) => {
301+
results.push(value);
302+
});
303+
304+
expect(results).to.deep.equal(['1!!!', '2!!!', '3!!!']);
305+
});
306+
});
282307
});

src/internal/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface UnaryFunction<T, R> {
2020
(source: T): R;
2121
}
2222

23-
export interface OperatorFunction<T, R> extends UnaryFunction<Observable<T>, Observable<R>> {}
23+
export interface OperatorFunction<T, R> extends UnaryFunction<Subscribable<T>, Observable<R>> {}
2424

2525
export type FactoryOrValue<T> = T | (() => T);
2626

0 commit comments

Comments
 (0)