v0.0.3 - bug fixes

Summary:
couple of bug fixes:
1) we don't want to init plugins on connect - let's wait for init command from flipper
2) on disonnect - "this" didn;t work well with .map() so i switched to old school loop

Reviewed By: jknoxville

Differential Revision: D23623946

fbshipit-source-id: cb3f579a8ee14fedfbe19895f31f77f9e08775d2
This commit is contained in:
Timur Valiev
2020-09-10 08:16:48 -07:00
committed by Facebook GitHub Bot
parent 0e6546b93a
commit 1d55b35dfd
2 changed files with 15 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "flipper-client-sdk",
"version": "0.0.2",
"version": "0.0.3",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"title": "Flipper SDK API",

View File

@@ -21,11 +21,11 @@ export class FlipperResponder {
}
success(response?: any) {
this.client.sendData({id: this.messageID, success: response});
this.client.sendData({ id: this.messageID, success: response });
}
error(response?: any) {
this.client.sendData({id: this.messageID, error: response});
this.client.sendData({ id: this.messageID, error: response });
}
}
@@ -63,7 +63,7 @@ export class FlipperConnection {
const receiver = this.subscriptions.get(method);
if (receiver == null) {
const errorMessage = `Receiver ${method} not found.`;
responder.error({message: errorMessage});
responder.error({ message: errorMessage });
return;
}
receiver.call(receiver, params, responder);
@@ -121,14 +121,13 @@ export abstract class FlipperClient {
return;
}
this._isConnected = true;
Array.from(this.plugins.values())
.filter((plugin) => plugin.runInBackground())
.map(this.connectPlugin, this);
}
onDisconnect() {
this._isConnected = false;
Array.from(this.plugins.values()).map(this.disconnectPlugin, this);
for (const plugin of this.plugins.values()) {
this.disconnectPlugin(plugin);
}
}
abstract start(appName: string): void;
@@ -146,11 +145,11 @@ export abstract class FlipperClient {
}) {
let responder: FlipperResponder | undefined;
try {
const {method, params, id} = message;
const { method, params, id } = message;
responder = new FlipperResponder(id, this);
if (method === 'getPlugins') {
responder.success({plugins: [...this.plugins.keys()]});
responder.success({ plugins: [...this.plugins.keys()] });
return;
}
@@ -168,7 +167,7 @@ export abstract class FlipperClient {
const plugin = this.plugins.get(identifier);
if (plugin == null) {
const errorMessage = `Plugin ${identifier} not found for method ${method}`;
responder.error({message: errorMessage, name: 'PluginNotFound'});
responder.error({ message: errorMessage, name: 'PluginNotFound' });
return;
}
@@ -181,7 +180,7 @@ export abstract class FlipperClient {
const plugin = this.plugins.get(identifier);
if (plugin == null) {
const errorMessage = `Plugin ${identifier} not found for method ${method}`;
responder.error({message: errorMessage, name: 'PluginNotFound'});
responder.error({ message: errorMessage, name: 'PluginNotFound' });
return;
}
@@ -195,7 +194,7 @@ export abstract class FlipperClient {
if (connection == null) {
const errorMessage = `Connection ${identifier} not found for plugin identifier`;
responder.error({message: errorMessage, name: 'ConnectionNotFound'});
responder.error({ message: errorMessage, name: 'ConnectionNotFound' });
return;
}
@@ -213,17 +212,17 @@ export abstract class FlipperClient {
if (connection == null) {
const errorMessage = `Connection ${identifier} not found for plugin identifier`;
responder.error({message: errorMessage, name: 'ConnectionNotFound'});
responder.error({ message: errorMessage, name: 'ConnectionNotFound' });
return;
}
const isSupported = connection.hasReceiver(
params['method'].getString(),
);
responder.success({isSupported: isSupported});
responder.success({ isSupported: isSupported });
return;
}
const response = {message: 'Received unknown method: ' + method};
const response = { message: 'Received unknown method: ' + method };
responder.error(response);
} catch (e) {
if (responder) {