refactor: Fixes #239. Rename from RxRpc to RpcRx in rpc-rx types (#240)

This commit is contained in:
Luke Schoen
2018-10-11 07:37:30 +02:00
committed by Jaco Greeff
parent 9e2962f0c5
commit 3c8c4b0baf
4 changed files with 25 additions and 25 deletions
+5 -5
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { RxRpcInterface, RxRpcInterface$Method, RxRpcInterface$Section } from '@polkadot/rpc-rx/types';
import { RpcRxInterface, RpcRxInterface$Method, RpcRxInterface$Section } from '@polkadot/rpc-rx/types';
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { EMPTY, Observable, combineLatest, from } from 'rxjs';
@@ -25,13 +25,13 @@ const defaultMapFn = (result: any): any =>
// Raw base implementation for the observable API. It simply provides access to raw calls, allowing
// decendants to make direct queries to either API methods or actual storage
export default class ApiBase {
protected _api: RxRpcInterface;
protected _api: RpcRxInterface;
protected _genesisHash: Hash;
// Observable that returns the first time we are connected and loaded
whenReady: Observable<boolean>;
constructor (api: RxRpcInterface) {
constructor (api: RpcRxInterface) {
this._api = api;
this._genesisHash = new Hash();
this.whenReady = from(this.init());
@@ -91,11 +91,11 @@ export default class ApiBase {
}
rawCall = <T> ({ method, section }: RpcMethod, ...params: Array<any>): Observable<T> => {
const apiSection = this._api[section as keyof RxRpcInterface] as RxRpcInterface$Section;
const apiSection = this._api[section as keyof RpcRxInterface] as RpcRxInterface$Section;
assert(apiSection, `Unable to find 'api.${section}'`);
const fn: RxRpcInterface$Method = apiSection[method];
const fn: RpcRxInterface$Method = apiSection[method];
assert(fn, `Unable to find 'api.${section}.${method}'`);
+2 -2
View File
@@ -5,7 +5,7 @@
import { Observable } from 'rxjs';
import { ExtrinsicFunction } from '@polkadot/extrinsics/types';
import RpcRx from '@polkadot/rpc-rx/index';
import { RxRpcInterface$Events } from '@polkadot/rpc-rx/types';
import { RpcRxInterface$Events } from '@polkadot/rpc-rx/types';
import { Base } from '@polkadot/types/codec';
import { Hash, RuntimeVersion } from '@polkadot/types/index';
import RuntimeMetadata, { FunctionMetadata } from '@polkadot/types/Metadata';
@@ -37,7 +37,7 @@ export interface SubmittableExtrinsics {
[index: string]: SubmittableModuleExtrinsics;
}
export type RxApiInterface$Events = RxRpcInterface$Events | 'ready';
export type RxApiInterface$Events = RpcRxInterface$Events | 'ready';
export interface RxApiInterface {
readonly genesisHash: Hash;
+8 -8
View File
@@ -4,7 +4,7 @@
import { RpcInterface, RpcInterface$Section } from '@polkadot/rpc-core/types';
import { ProviderInterface } from '@polkadot/rpc-provider/types';
import { RxRpcInterface, RxRpcInterface$Section } from './types';
import { RpcRxInterface, RpcRxInterface$Section } from './types';
import E3 from 'eventemitter3';
import { BehaviorSubject, ReplaySubject, Observable, Subscriber, from } from 'rxjs';
@@ -37,14 +37,14 @@ type CachedMap = {
* const api = new RpcRx(provider);
* ```
*/
export default class RpcRx extends E3.EventEmitter implements RxRpcInterface {
export default class RpcRx extends E3.EventEmitter implements RpcRxInterface {
private _api: RpcInterface;
private _cacheMap: CachedMap;
private _isConnected: BehaviorSubject<boolean>;
readonly author: RxRpcInterface$Section;
readonly chain: RxRpcInterface$Section;
readonly state: RxRpcInterface$Section;
readonly system: RxRpcInterface$Section;
readonly author: RpcRxInterface$Section;
readonly chain: RpcRxInterface$Section;
readonly state: RpcRxInterface$Section;
readonly system: RpcRxInterface$Section;
/**
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
@@ -82,7 +82,7 @@ export default class RpcRx extends E3.EventEmitter implements RxRpcInterface {
});
}
private createInterface (sectionName: string, section: RpcInterface$Section): RxRpcInterface$Section {
private createInterface (sectionName: string, section: RpcInterface$Section): RpcRxInterface$Section {
return Object
.keys(section)
.filter((name) => !['subscribe', 'unsubscribe'].includes(name))
@@ -90,7 +90,7 @@ export default class RpcRx extends E3.EventEmitter implements RxRpcInterface {
observables[name] = this.createObservable(`${sectionName}_${name}`, name, section);
return observables;
}, ({} as RxRpcInterface$Section));
}, ({} as RpcRxInterface$Section));
}
private createObservable (subName: string, name: string, section: RpcInterface$Section): (...params: Array<any>) => Observable<any> | ReplaySubject<any> {
+10 -10
View File
@@ -5,20 +5,20 @@
import { ReplaySubject, Observable } from 'rxjs';
import interfaces from '@polkadot/jsonrpc/types';
export type RxRpcInterface$Method = (...params: Array<any>) => Observable<any> | ReplaySubject<any>;
export type RpcRxInterface$Method = (...params: Array<any>) => Observable<any> | ReplaySubject<any>;
export type RxRpcInterface$Section = {
[index: string]: RxRpcInterface$Method
export type RpcRxInterface$Section = {
[index: string]: RpcRxInterface$Method
};
export type RxRpcInterface$Events = 'connected' | 'disconnected';
export type RpcRxInterface$Events = 'connected' | 'disconnected';
export type RxRpcInterface = {
readonly author: RxRpcInterface$Section;
readonly chain: RxRpcInterface$Section;
readonly state: RxRpcInterface$Section;
readonly system: RxRpcInterface$Section;
export type RpcRxInterface = {
readonly author: RpcRxInterface$Section;
readonly chain: RpcRxInterface$Section;
readonly state: RpcRxInterface$Section;
readonly system: RpcRxInterface$Section;
isConnected: () => Observable<boolean>
on: (type: RxRpcInterface$Events, handler: (...args: Array<any>) => any) => void;
on: (type: RpcRxInterface$Events, handler: (...args: Array<any>) => any) => void;
}