Revert "Bubble isSubscription from rpc-rx (#627)" (#631)

This reverts commit 767a1978d0.
This commit is contained in:
Jaco Greeff
2019-01-23 23:31:21 +01:00
committed by GitHub
parent 4ca14eb831
commit ee21272bbc
7 changed files with 22 additions and 37 deletions
+13 -19
View File
@@ -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] = {};
+2 -5
View File
@@ -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;