This reverts commit 767a1978d0.
This commit is contained in:
@@ -14,10 +14,7 @@ import { isFunction } from '@polkadot/util';
|
||||
import ApiBase from '../Base';
|
||||
import Combinator, { CombinatorCallback, CombinatorFunction } from './Combinator';
|
||||
|
||||
interface RxFn {
|
||||
(...params: Array<any>): Observable<Codec | undefined | null>;
|
||||
isSubscription: boolean;
|
||||
}
|
||||
type RxFn = (...params: Array<any>) => Observable<Codec | undefined | null>;
|
||||
|
||||
/**
|
||||
* # @polkadot/api/promise
|
||||
@@ -196,8 +193,8 @@ export default class ApiPromise extends ApiBase<OnCall> implements ApiPromiseInt
|
||||
};
|
||||
}
|
||||
|
||||
protected onCall (method: RxFn, params: Array<any>, isSubscription: boolean = false): OnCall {
|
||||
if (!params || params.length === 0 || !isSubscription) {
|
||||
protected onCall (method: RxFn, params: Array<any>, isSubscription?: boolean): OnCall {
|
||||
if (!params || params.length === 0 || isSubscription === false) {
|
||||
return method(...params).pipe(first()).toPromise();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @ts-check
|
||||
|
||||
import BN from 'bn.js';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @ts-check
|
||||
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
|
||||
@@ -47,7 +46,7 @@ describe.skip('e2e transactions', () => {
|
||||
});
|
||||
|
||||
it('makes a transfer (signAndSend)', async (done) => {
|
||||
const unsubscribe = await api.tx.balances
|
||||
api.tx.balances
|
||||
.transfer('12ghjsRJpeJpUQaCQeHcBv9pRQA3tdcMxeL8cVk9JHWJGHjd', 12345)
|
||||
.signAndSend(keyring.dave, ({ events, status, type }) => {
|
||||
console.log('Transaction status:', type);
|
||||
@@ -60,8 +59,9 @@ describe.skip('e2e transactions', () => {
|
||||
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
|
||||
});
|
||||
|
||||
unsubscribe();
|
||||
done();
|
||||
if (events.length) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @ts-check
|
||||
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @ts-check
|
||||
|
||||
import { first, switchMap } from 'rxjs/operators';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { RpcInterface$Method, RpcInterface$Section } from '@polkadot/rpc-core/types';
|
||||
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
||||
import { RpcRxInterface, RpcRxInterface$Events, RpcRxInterface$Section, RpcRxObervable } from './types';
|
||||
import { RpcRxInterface, RpcRxInterface$Events, RpcRxInterface$Section } from './types';
|
||||
|
||||
import EventEmitter from 'eventemitter3';
|
||||
import { BehaviorSubject, Observable, Subscriber, from } from 'rxjs';
|
||||
@@ -100,27 +100,21 @@ export default class RpcRx implements RpcRxInterface {
|
||||
}, ({} as RpcRxInterface$Section));
|
||||
}
|
||||
|
||||
private createObservable (subName: string, name: string, section: RpcInterface$Section): RpcRxObervable {
|
||||
const isSubscription = isFunction(section[name].unsubscribe);
|
||||
const fn = isSubscription
|
||||
? this.createCachedObservable(subName, name, section)
|
||||
: (...params: Array<any>): Observable<any> =>
|
||||
from(
|
||||
section[name]
|
||||
.apply(null, params)
|
||||
.catch((error: Error) => {
|
||||
console.error(error);
|
||||
})
|
||||
);
|
||||
private createObservable (subName: string, name: string, section: RpcInterface$Section): (...params: Array<any>) => Observable<any> {
|
||||
if (isFunction(section[name].unsubscribe)) {
|
||||
return this.createCachedObservable(subName, name, section);
|
||||
}
|
||||
|
||||
const result = fn as RpcRxObervable;
|
||||
|
||||
result.isSubscription = isSubscription;
|
||||
|
||||
return result;
|
||||
return (...params: Array<any>): Observable<any> =>
|
||||
from(
|
||||
section[name]
|
||||
.apply(null, params)
|
||||
.catch((error: Error) => {
|
||||
console.error(error);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// FIXME Memoization as in derive, https://github.com/polkadot-js/api/issues/553
|
||||
private createCachedObservable (subName: string, name: string, section: RpcInterface$Section): (...params: Array<any>) => Observable<any> {
|
||||
if (!this._cacheMap[subName]) {
|
||||
this._cacheMap[subName] = {};
|
||||
|
||||
@@ -5,13 +5,10 @@
|
||||
import { ReplaySubject, Observable } from 'rxjs';
|
||||
import { ProviderInterface$Emitted } from '@polkadot/rpc-provider/types';
|
||||
|
||||
export interface RpcRxObervable {
|
||||
(...params: Array<any>): Observable<any> | ReplaySubject<any>;
|
||||
isSubscription: boolean;
|
||||
}
|
||||
export type RpcRxInterface$Method = (...params: Array<any>) => Observable<any> | ReplaySubject<any>;
|
||||
|
||||
export type RpcRxInterface$Section = {
|
||||
[index: string]: RpcRxObervable
|
||||
[index: string]: RpcRxInterface$Method
|
||||
};
|
||||
|
||||
export type RpcRxInterface$Events = ProviderInterface$Emitted;
|
||||
|
||||
Reference in New Issue
Block a user