Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rxjs] Establish interop of rxjs-6 and kbn-observable #21722

Merged
merged 3 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can symbol-observable be removed from the dependencies, then?

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;
}