From 4ddd66ee0843f266edf8a98b71a06e5103086625 Mon Sep 17 00:00:00 2001 From: Kostiantyn Palchyk Date: Wed, 2 Dec 2020 15:01:13 +0200 Subject: [PATCH] proxies to be instanceof Observable fix #6 --- src/core/proxy.ts | 3 +++ tests/observable.test.ts | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/proxy.ts b/src/core/proxy.ts index 50c2071..2f6391c 100644 --- a/src/core/proxy.ts +++ b/src/core/proxy.ts @@ -14,6 +14,9 @@ export function coreProxy(o: Observable, ps: Path = [], getOverride?: (ps: const proxyForPropertyCache = new Map>(); return (new Proxy(noop, { + getPrototypeOf: function () { + return Observable.prototype; + }, // call result = O.fn in Observable // and make it Observable apply(_, __, argumentsList) { diff --git a/tests/observable.test.ts b/tests/observable.test.ts index 886d434..76537f5 100644 --- a/tests/observable.test.ts +++ b/tests/observable.test.ts @@ -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'; @@ -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);