Skip to content

Commit

Permalink
proxies to be instanceof Observable
Browse files Browse the repository at this point in the history
fix #6
  • Loading branch information
kosich committed Dec 2, 2020
1 parent ae0c2f6 commit 4ddd66e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/core/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export function coreProxy<O>(o: Observable<O>, ps: Path = [], getOverride?: (ps:
const proxyForPropertyCache = new Map<keyof O, ObservableProxy<O[keyof O]>>();

return (new Proxy(noop, {
getPrototypeOf: function () {
return Observable.prototype;
},
// call result = O.fn in Observable<O>
// and make it Observable<result>
apply(_, __, argumentsList) {
Expand Down
23 changes: 22 additions & 1 deletion tests/observable.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObservable, of, Subscription } from 'rxjs';
import { combineLatest, from, isObservable, Observable, of, Subscription } from 'rxjs';
import { filter, map, scan } from 'rxjs/operators';
import { proxify } from '../src';
import { createTestObserver, TestObserver } from './helpers';
Expand All @@ -24,6 +24,27 @@ describe('Proxify', () => {
expect(isObservable(p)).toBe(true);
});

test('should be instance of Observable', () => {
const o = of(1);
const p = proxify(o);
expect(p instanceof Observable).toBe(true);
});

test('should still behave as an Observable even after applying from', () => {
const o = of(1);
const p = proxify(o);
const o2 = from(p);
sub = o2.subscribe(observer);
expect(observer.next.mock.calls).toEqual([[1]]);
});

test('should be combinable with other Observables', () => {
const a = proxify(of('a'));
const b = of('b');
sub = combineLatest([a, b]).subscribe(observer);
expect(observer.next.mock.calls).toEqual([[['a', 'b']]]);
});

test('directly applying operator', () => {
const o = of(1, 2, 3);
const p = proxify(o);
Expand Down

0 comments on commit 4ddd66e

Please sign in to comment.