Skip to content

Commit

Permalink
[rxjs] Establish interop of rxjs-6 and kbn-observable (elastic#21722)
Browse files Browse the repository at this point in the history
* [rxjs] Establish interop of rxjs-6 and kbn-observable
* Remove symbol-observable
  • Loading branch information
archanid authored and cjcenizal committed Aug 23, 2018
1 parent ec6e307 commit 3a677a7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,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",
Expand Down
6 changes: 3 additions & 3 deletions src/core/lib/kbn_internal_native_observable/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import symbolObservable from '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.
Expand Down Expand Up @@ -256,7 +256,7 @@ export class Observable {
return new Subscription(observer, this._subscriber);
}

[symbolObservable]() { return this }
[SymbolObservable]() { return this }

// == Derived ==

Expand All @@ -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, SymbolObservable);

if (method) {

Expand Down
37 changes: 37 additions & 0 deletions src/core/lib/kbn_observable/__tests__/observable_rxjs.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
3 changes: 2 additions & 1 deletion src/core/lib/kbn_observable/lib/is_observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* under the License.
*/

import { observable as SymbolObservable } from 'rxjs/internal/symbol/observable';
import { Observable } from '../observable';

export function isObservable<T>(x: any): x is Observable<T> {
return x !== null && typeof x === 'object' && x[Symbol.observable] !== undefined;
return x !== null && typeof x === 'object' && x[SymbolObservable] !== undefined;
}

0 comments on commit 3a677a7

Please sign in to comment.