refactoring and fixes
Summary: Slightly refactored JS api to make it work with new js app launcher Reviewed By: jknoxville Differential Revision: D18761757 fbshipit-source-id: edb8e5907765a9354e4c636be97d3cf6df63ee98
This commit is contained in:
committed by
Facebook Github Bot
parent
beff2c4cac
commit
fe4af064cf
@@ -14,7 +14,7 @@ export type FlipperMethodID = string;
|
||||
export class FlipperBridge {
|
||||
registerPlugins: (plugins: Array<FlipperPluginID>) => void;
|
||||
|
||||
start: () => void;
|
||||
start: (appName: string) => void;
|
||||
|
||||
stop: () => void;
|
||||
|
||||
@@ -104,9 +104,9 @@ export class FlipperClient {
|
||||
return this.plugins.get(id);
|
||||
}
|
||||
|
||||
start() {
|
||||
start(appName: string) {
|
||||
this._bridge.registerPlugins([...this.plugins.keys()]);
|
||||
this._bridge.start();
|
||||
this._bridge.start(appName);
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
||||
@@ -23,7 +23,7 @@ class FlipperManager {
|
||||
this.furyPlugin = new FuryPlugin();
|
||||
this.flipperClient.addPlugin(this.analyticsPlugin);
|
||||
this.flipperClient.addPlugin(this.furyPlugin);
|
||||
this.flipperClient.start();
|
||||
this.flipperClient.start('Example JS App');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ class FlipperWebviewBridgeImpl extends FlipperBridge {
|
||||
window.FlipperWebviewBridge.registerPlugins(plugins);
|
||||
};
|
||||
|
||||
start = () => {
|
||||
window.FlipperWebviewBridge && window.FlipperWebviewBridge.start();
|
||||
start = (appName: string) => {
|
||||
window.FlipperWebviewBridge && window.FlipperWebviewBridge.start(appName);
|
||||
};
|
||||
|
||||
stop = () => {
|
||||
@@ -42,22 +42,22 @@ class FlipperWebviewBridgeImpl extends FlipperBridge {
|
||||
handler: any => void,
|
||||
) => {
|
||||
this._subscriptions.set(plugin + method, handler);
|
||||
window.FlipperWebviewBridge &&
|
||||
window.FlipperWebviewBridge.subscribe(plugin, method);
|
||||
};
|
||||
|
||||
isAvailable = () => {
|
||||
return window.FlipperWebviewBridge != null;
|
||||
};
|
||||
|
||||
handleMessage(plugin: FlipperPluginID, method: FlipperMethodID, data: any) {
|
||||
const handler: ?(any) => void = this._subscriptions.get(plugin + method);
|
||||
handler && handler(data);
|
||||
receive(plugin: FlipperPluginID, method: FlipperMethodID, data: string) {
|
||||
const handler = this._subscriptions.get(plugin + method);
|
||||
handler && handler(JSON.parse(data));
|
||||
}
|
||||
}
|
||||
|
||||
export function newWebviewClient(): FlipperClient {
|
||||
const bridge = new FlipperWebviewBridgeImpl();
|
||||
window.FlipperBridgeClientSide = bridge;
|
||||
window.flipper = {
|
||||
FlipperWebviewMessageReceiver: bridge,
|
||||
};
|
||||
return new FlipperClient(bridge);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user