From 3e89e7cdbcbeab8a35908b7ad22f2e43d8ee5cbe Mon Sep 17 00:00:00 2001 From: archanid Date: Tue, 7 Aug 2018 07:52:19 -0500 Subject: [PATCH 1/2] [rxjs] Establish interop of rxjs-6 and kbn-observable --- .../kbn_internal_native_observable/index.js | 6 +-- .../__tests__/observable_rxjs.test.ts | 37 +++++++++++++++++++ .../lib/kbn_observable/lib/is_observable.ts | 3 +- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/core/lib/kbn_observable/__tests__/observable_rxjs.test.ts diff --git a/src/core/lib/kbn_internal_native_observable/index.js b/src/core/lib/kbn_internal_native_observable/index.js index 4b6a56c9062f0..cc5f72c13ea47 100644 --- a/src/core/lib/kbn_internal_native_observable/index.js +++ b/src/core/lib/kbn_internal_native_observable/index.js @@ -1,4 +1,4 @@ -import symbolObservable from 'symbol-observable'; +import { observable as Symbol_observable } from 'rxjs/internal/symbol/observable'; // This is a fork of the example implementation of the TC39 Observable spec, // see https://github.com/tc39/proposal-observable. @@ -256,7 +256,7 @@ export class Observable { return new Subscription(observer, this._subscriber); } - [symbolObservable]() { return this } + [Symbol_observable]() { return this } // == Derived == @@ -267,7 +267,7 @@ export class Observable { if (x == null) throw new TypeError(x + " is not an object"); - let method = getMethod(x, symbolObservable); + let method = getMethod(x, Symbol_observable); if (method) { diff --git a/src/core/lib/kbn_observable/__tests__/observable_rxjs.test.ts b/src/core/lib/kbn_observable/__tests__/observable_rxjs.test.ts new file mode 100644 index 0000000000000..1d17b0b28e3e6 --- /dev/null +++ b/src/core/lib/kbn_observable/__tests__/observable_rxjs.test.ts @@ -0,0 +1,37 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { from, of } from 'rxjs'; +import { isObservable } from '../lib/is_observable'; +import { Observable } from '../observable'; + +// Test that rxjs observable and kbn-observable are interoperable. +describe('interoperability', () => { + it('understood by rxjs of kbn-observables', () => { + const obs = Observable.of([1, 2, 3]); + expect(() => { + from(obs); + }).not.toThrowError(TypeError); + }); + + it('understood by kbn-observable of rxjs observables', () => { + const rxobs = of([1, 2, 3]); + expect(isObservable(rxobs)).toBeTruthy(); + }); +}); diff --git a/src/core/lib/kbn_observable/lib/is_observable.ts b/src/core/lib/kbn_observable/lib/is_observable.ts index ef1999e840534..6d3fade29de90 100644 --- a/src/core/lib/kbn_observable/lib/is_observable.ts +++ b/src/core/lib/kbn_observable/lib/is_observable.ts @@ -17,8 +17,9 @@ * under the License. */ +import { observable as Symbol_observable } from 'rxjs/internal/symbol/observable'; import { Observable } from '../observable'; export function isObservable(x: any): x is Observable { - return x !== null && typeof x === 'object' && x[Symbol.observable] !== undefined; + return x !== null && typeof x === 'object' && x[Symbol_observable] !== undefined; } From 3a10bd799fe6b062f22d31a112e4337cb1970fce Mon Sep 17 00:00:00 2001 From: archanid Date: Fri, 10 Aug 2018 09:11:38 -0500 Subject: [PATCH 2/2] Remove symbol-observable --- package.json | 1 - src/core/lib/kbn_internal_native_observable/index.js | 6 +++--- src/core/lib/kbn_observable/lib/is_observable.ts | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ab046a29f32a1..a0bbe09a37739 100644 --- a/package.json +++ b/package.json @@ -197,7 +197,6 @@ "script-loader": "0.7.2", "semver": "^5.5.0", "style-loader": "0.19.0", - "symbol-observable": "^1.2.0", "tar": "2.2.0", "tinygradient": "0.3.0", "tinymath": "0.2.1", diff --git a/src/core/lib/kbn_internal_native_observable/index.js b/src/core/lib/kbn_internal_native_observable/index.js index cc5f72c13ea47..504ddc1e34297 100644 --- a/src/core/lib/kbn_internal_native_observable/index.js +++ b/src/core/lib/kbn_internal_native_observable/index.js @@ -1,4 +1,4 @@ -import { observable as Symbol_observable } from 'rxjs/internal/symbol/observable'; +import { observable as SymbolObservable } from 'rxjs/internal/symbol/observable'; // This is a fork of the example implementation of the TC39 Observable spec, // see https://github.com/tc39/proposal-observable. @@ -256,7 +256,7 @@ export class Observable { return new Subscription(observer, this._subscriber); } - [Symbol_observable]() { return this } + [SymbolObservable]() { return this } // == Derived == @@ -267,7 +267,7 @@ export class Observable { if (x == null) throw new TypeError(x + " is not an object"); - let method = getMethod(x, Symbol_observable); + let method = getMethod(x, SymbolObservable); if (method) { diff --git a/src/core/lib/kbn_observable/lib/is_observable.ts b/src/core/lib/kbn_observable/lib/is_observable.ts index 6d3fade29de90..23c7d80d49d5a 100644 --- a/src/core/lib/kbn_observable/lib/is_observable.ts +++ b/src/core/lib/kbn_observable/lib/is_observable.ts @@ -17,9 +17,9 @@ * under the License. */ -import { observable as Symbol_observable } from 'rxjs/internal/symbol/observable'; +import { observable as SymbolObservable } from 'rxjs/internal/symbol/observable'; import { Observable } from '../observable'; export function isObservable(x: any): x is Observable { - return x !== null && typeof x === 'object' && x[Symbol_observable] !== undefined; + return x !== null && typeof x === 'object' && x[SymbolObservable] !== undefined; }