Update with flow lint (#46)

* Flow lint warning fixes

* Flow updates fro new flow-bin
This commit is contained in:
Jaco Greeff
2017-12-30 21:54:22 +01:00
committed by GitHub
parent 800f869c9f
commit 4053064288
17 changed files with 504 additions and 374 deletions
+1 -1
View File
@@ -34,7 +34,7 @@
"nock": "^9.1.0"
},
"dependencies": {
"@polkadot/util": "^0.10.1",
"@polkadot/util": "^0.11.1",
"babel-runtime": "^6.26.0",
"isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.25"
+2 -1
View File
@@ -19,11 +19,12 @@ module.exports = class HttpProvider extends JsonRpcCoder implements ProviderInte
this._endpoint = endpoint;
}
// flowlint-next-line unsafe-getters-setters:off
get isConnected (): boolean {
return true;
}
async send (method: string, params: Array<any>): Promise<any> {
async send (method: string, params: Array<mixed>): Promise<mixed> {
const body = this.encodeJson(method, params);
const response = await fetch(this._endpoint, {
body,
+4 -3
View File
@@ -10,7 +10,7 @@ const isUndefined = require('@polkadot/util/is/undefined');
module.exports = class JsonRpcCoder {
_id: number = 0;
decodeResponse (response: JsonRpcResponse): any {
decodeResponse (response: JsonRpcResponse): mixed {
assert(response, 'Empty response object received');
assert(response.jsonrpc === '2.0', 'Invalid jsonrpc field in decoded object');
@@ -27,7 +27,7 @@ module.exports = class JsonRpcCoder {
return response.result;
}
encodeObject (method: string, params: Array<any>): JsonRpcRequest {
encodeObject (method: string, params: Array<mixed>): JsonRpcRequest {
return {
id: ++this._id,
jsonrpc: '2.0',
@@ -36,12 +36,13 @@ module.exports = class JsonRpcCoder {
};
}
encodeJson (method: string, params: Array<any>): string {
encodeJson (method: string, params: Array<mixed>): string {
return JSON.stringify(
this.encodeObject(method, params)
);
}
// flowlint-next-line unsafe-getters-setters:off
get id (): number {
return this._id;
}
+3 -3
View File
@@ -8,7 +8,7 @@ export type JsonRpcObject = {
export type JsonRpcRequest = JsonRpcObject & {
method: string;
params: Array<any>;
params: Array<mixed>;
};
export type JsonRpcResponseBase = {
@@ -16,12 +16,12 @@ export type JsonRpcResponseBase = {
code: number,
message: string
};
result?: any;
result?: mixed;
}
export type JsonRpcResponse = JsonRpcObject & JsonRpcResponseBase;
export interface ProviderInterface {
+isConnected: boolean;
send (method: string, params: Array<any>): Promise<any>;
send (method: string, params: Array<mixed>): Promise<mixed>;
}
+12 -11
View File
@@ -4,11 +4,7 @@
import type { JsonRpcResponse, ProviderInterface } from '../types';
type AwaitingType = {
callback: (error: ?Error, result: any) => void
};
type WsMessageType = {
data: any
callback: (error: ?Error, result: mixed) => void
};
require('./polyfill');
@@ -37,6 +33,7 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
}
}
// flowlint-next-line unsafe-getters-setters:off
get isConnected (): boolean {
return this._isConnected;
}
@@ -67,11 +64,14 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
// console.log('connected to', this._endpoint);
this._isConnected = true;
Object.keys(this._queued).forEach((id: string) => {
Object.keys(this._queued).forEach((id) => {
try {
this._websocket.send(
// flowlint-next-line unclear-type:off
this._queued[((id: any): number)]
);
// flowlint-next-line unclear-type:off
delete this._queued[((id: any): number)];
} catch (error) {
console.error(error);
@@ -79,8 +79,9 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
});
}
_onMessage = (message: WsMessageType) => {
const response: JsonRpcResponse = JSON.parse(message.data);
_onMessage = (message: MessageEvent): void => {
// flowlint-next-line unclear-type:off
const response: JsonRpcResponse = JSON.parse(((message.data: any): string));
const handler = this._handlers[response.id];
if (!handler) {
@@ -99,13 +100,13 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
delete this._handlers[response.id];
}
send (method: string, params: Array<any>): Promise<any> {
return new Promise((resolve, reject) => {
send (method: string, params: Array<mixed>): Promise<mixed> {
return new Promise((resolve, reject): void => {
try {
const json = this.encodeJson(method, params);
this._handlers[this.id] = {
callback: (error: ?Error, result: any) => {
callback: (error: ?Error, result: mixed) => {
if (error) {
reject(error);
} else {