Summary: This gets us on the latest Prettier 2.x: https://prettier.io/blog/2020/03/21/2.0.0.html Notably, this adds support for TypeScript 3.8, which introduces new syntax, such as `import type`. Reviewed By: zertosh Differential Revision: D20636268 fbshipit-source-id: fca5833d003804333a05ba16325bbbe0e06d6c8a
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import {FlipperClient, FlipperBridge} from './api';
|
|
|
|
import type {FlipperPluginID, FlipperMethodID} from './api';
|
|
|
|
class FlipperWebviewBridgeImpl extends FlipperBridge {
|
|
_subscriptions: Map<string, (any) => void> = new Map();
|
|
|
|
registerPlugins = (plugins: Array<FlipperPluginID>) => {
|
|
window.FlipperWebviewBridge &&
|
|
window.FlipperWebviewBridge.registerPlugins(plugins);
|
|
};
|
|
|
|
start = (appName: string) => {
|
|
window.FlipperWebviewBridge && window.FlipperWebviewBridge.start(appName);
|
|
};
|
|
|
|
stop = () => {
|
|
window.FlipperWebviewBridge && window.FlipperWebviewBridge.stop();
|
|
};
|
|
|
|
sendData = (plugin: FlipperPluginID, method: FlipperMethodID, data: any) => {
|
|
window.FlipperWebviewBridge &&
|
|
window.FlipperWebviewBridge.sendFlipperObject(
|
|
plugin,
|
|
method,
|
|
JSON.stringify(data),
|
|
);
|
|
};
|
|
|
|
subscribe = (
|
|
plugin: FlipperPluginID,
|
|
method: FlipperMethodID,
|
|
handler: any => void,
|
|
) => {
|
|
this._subscriptions.set(plugin + method, handler);
|
|
};
|
|
|
|
isAvailable = () => {
|
|
return window.FlipperWebviewBridge != null;
|
|
};
|
|
|
|
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.flipper = {
|
|
FlipperWebviewMessageReceiver: bridge,
|
|
};
|
|
return new FlipperClient(bridge);
|
|
}
|