fix(core): fix rxjs 6 build errors

#2439
This commit is contained in:
Daniel
2018-04-05 21:34:04 +02:00
parent 97a73ca369
commit 48b0f16ed9
5 changed files with 86 additions and 58 deletions
@@ -1,5 +1,5 @@
import { callCordovaPlugin, wrapInstance, wrapPromise } from './common';
import 'rxjs/add/observable/of';
import { of } from 'rxjs';
declare const window: any;
@@ -33,14 +33,16 @@ class MockCordovaPlugin {
static ping = jest.fn((arg: string) => 'pong');
ping = jest.fn((arg: string) => 'pong');
static pingAsync = jest.fn((arg: string, success: Function, error: Function) => success('pong'));
pingAsync = jest.fn((arg: string, success: Function, error: Function) => success('pong'));
static pingAsync = jest.fn(
(arg: string, success: Function, error: Function) => success('pong')
);
pingAsync = jest.fn((arg: string, success: Function, error: Function) =>
success('pong')
);
}
describe('Common decorator functions', () => {
let plugin: MockPlugin,
instancePluginObject: MockInstancePluginObject;
let plugin: MockPlugin, instancePluginObject: MockInstancePluginObject;
beforeAll(() => {
window.mockPlugin = MockCordovaPlugin;
@@ -73,15 +75,17 @@ describe('Common decorator functions', () => {
test('original method should have received args', () => {
expect(MockCordovaPlugin.pingAsync.mock.calls[0][0]).toBe('pingpong');
expect(typeof MockCordovaPlugin.pingAsync.mock.calls[0][1]).toBe('function');
expect(typeof MockCordovaPlugin.pingAsync.mock.calls[0][2]).toBe('function');
expect(typeof MockCordovaPlugin.pingAsync.mock.calls[0][1]).toBe(
'function'
);
expect(typeof MockCordovaPlugin.pingAsync.mock.calls[0][2]).toBe(
'function'
);
});
});
describe('wrapObservable', () => {
test('should return an observable that emits a value', async () => {
});
test('should return an observable that emits a value', async () => {});
test('original method should have been called', () => {});
@@ -93,8 +97,7 @@ describe('Common decorator functions', () => {
});
describe('callInstance', () => {
test('should call an instance method', async () => {
});
test('should call an instance method', async () => {});
test('original method should have been called', () => {
// expect(instancePluginObject._pluginInstance.ping.mock.calls.length).toBe(1);
@@ -104,5 +107,4 @@ describe('Common decorator functions', () => {
// expect(instancePluginObject._pluginInstance.ping.mock.calls[0][0]).toBe('pingpong');
});
});
});
+3 -5
View File
@@ -1,7 +1,5 @@
import 'rxjs/add/observable/fromEvent';
import * as _ from 'lodash';
import { Observable } from 'rxjs/Observable';
import { Observable, fromEvent } from 'rxjs';
import { CordovaOptions } from './interfaces';
@@ -175,7 +173,7 @@ function wrapEventObservable(event: string, element: any): Observable<any> {
} else {
element = window;
}
return Observable.fromEvent(element, event);
return fromEvent(element, event);
}
/**
@@ -288,7 +286,7 @@ export function setIndex(
};
const setErrorIndex = () => {
// We don't want that the reject cb gets spliced into the position of an optional argument that has not been defined and thus causing non expected behaviour.
// We don't want that the reject cb gets spliced into the position of an optional argument that has not been defined and thus causing non expected behavior.
if (opts.errorIndex > args.length) {
args[opts.errorIndex] = reject; // insert the reject fn at the correct specific index
} else {
@@ -1,23 +1,25 @@
import { checkAvailability, getPlugin } from './common';
import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs';
function overrideFunction(pluginObj: any, methodName: string): Observable<any> {
return new Observable(observer => {
const availabilityCheck = checkAvailability(pluginObj, methodName);
if (availabilityCheck === true) {
const pluginInstance = getPlugin(pluginObj.constructor.getPluginRef());
pluginInstance[methodName] = observer.next.bind(observer);
return () => pluginInstance[methodName] = () => { };
return () => (pluginInstance[methodName] = () => {});
} else {
observer.error(availabilityCheck);
observer.complete();
}
});
}
export function cordovaFunctionOverride(pluginObj: any, methodName: string, args: IArguments | Array<any> = []) {
export function cordovaFunctionOverride(
pluginObj: any,
methodName: string,
args: IArguments | Array<any> = []
) {
return overrideFunction(pluginObj, methodName);
}