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:
committed by
Facebook GitHub Bot
parent
0e6546b93a
commit
1d55b35dfd
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flipper-client-sdk",
|
"name": "flipper-client-sdk",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"title": "Flipper SDK API",
|
"title": "Flipper SDK API",
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ export class FlipperResponder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
success(response?: any) {
|
success(response?: any) {
|
||||||
this.client.sendData({id: this.messageID, success: response});
|
this.client.sendData({ id: this.messageID, success: response });
|
||||||
}
|
}
|
||||||
|
|
||||||
error(response?: any) {
|
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);
|
const receiver = this.subscriptions.get(method);
|
||||||
if (receiver == null) {
|
if (receiver == null) {
|
||||||
const errorMessage = `Receiver ${method} not found.`;
|
const errorMessage = `Receiver ${method} not found.`;
|
||||||
responder.error({message: errorMessage});
|
responder.error({ message: errorMessage });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
receiver.call(receiver, params, responder);
|
receiver.call(receiver, params, responder);
|
||||||
@@ -121,14 +121,13 @@ export abstract class FlipperClient {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._isConnected = true;
|
this._isConnected = true;
|
||||||
Array.from(this.plugins.values())
|
|
||||||
.filter((plugin) => plugin.runInBackground())
|
|
||||||
.map(this.connectPlugin, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onDisconnect() {
|
onDisconnect() {
|
||||||
this._isConnected = false;
|
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;
|
abstract start(appName: string): void;
|
||||||
@@ -146,11 +145,11 @@ export abstract class FlipperClient {
|
|||||||
}) {
|
}) {
|
||||||
let responder: FlipperResponder | undefined;
|
let responder: FlipperResponder | undefined;
|
||||||
try {
|
try {
|
||||||
const {method, params, id} = message;
|
const { method, params, id } = message;
|
||||||
responder = new FlipperResponder(id, this);
|
responder = new FlipperResponder(id, this);
|
||||||
|
|
||||||
if (method === 'getPlugins') {
|
if (method === 'getPlugins') {
|
||||||
responder.success({plugins: [...this.plugins.keys()]});
|
responder.success({ plugins: [...this.plugins.keys()] });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +167,7 @@ export abstract class FlipperClient {
|
|||||||
const plugin = this.plugins.get(identifier);
|
const plugin = this.plugins.get(identifier);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
const errorMessage = `Plugin ${identifier} not found for method ${method}`;
|
const errorMessage = `Plugin ${identifier} not found for method ${method}`;
|
||||||
responder.error({message: errorMessage, name: 'PluginNotFound'});
|
responder.error({ message: errorMessage, name: 'PluginNotFound' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +180,7 @@ export abstract class FlipperClient {
|
|||||||
const plugin = this.plugins.get(identifier);
|
const plugin = this.plugins.get(identifier);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
const errorMessage = `Plugin ${identifier} not found for method ${method}`;
|
const errorMessage = `Plugin ${identifier} not found for method ${method}`;
|
||||||
responder.error({message: errorMessage, name: 'PluginNotFound'});
|
responder.error({ message: errorMessage, name: 'PluginNotFound' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +194,7 @@ export abstract class FlipperClient {
|
|||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
const errorMessage = `Connection ${identifier} not found for plugin identifier`;
|
const errorMessage = `Connection ${identifier} not found for plugin identifier`;
|
||||||
|
|
||||||
responder.error({message: errorMessage, name: 'ConnectionNotFound'});
|
responder.error({ message: errorMessage, name: 'ConnectionNotFound' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,17 +212,17 @@ export abstract class FlipperClient {
|
|||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
const errorMessage = `Connection ${identifier} not found for plugin identifier`;
|
const errorMessage = `Connection ${identifier} not found for plugin identifier`;
|
||||||
|
|
||||||
responder.error({message: errorMessage, name: 'ConnectionNotFound'});
|
responder.error({ message: errorMessage, name: 'ConnectionNotFound' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const isSupported = connection.hasReceiver(
|
const isSupported = connection.hasReceiver(
|
||||||
params['method'].getString(),
|
params['method'].getString(),
|
||||||
);
|
);
|
||||||
responder.success({isSupported: isSupported});
|
responder.success({ isSupported: isSupported });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = {message: 'Received unknown method: ' + method};
|
const response = { message: 'Received unknown method: ' + method };
|
||||||
responder.error(response);
|
responder.error(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (responder) {
|
if (responder) {
|
||||||
|
|||||||
Reference in New Issue
Block a user