update js-client api (migrate to TS)
Summary: JS/TS api: - migrate to TS - some refactoring (get rid of bridge, make client abstract) Implementation isn't full yet, things to be implemented: - let plugins connect on init command from Flipper - implement Responder Further plans: - make fully compatible with react-native api without breaking changes Reviewed By: mweststrate Differential Revision: D21839377 fbshipit-source-id: 9e9fe4ad01632f958b59eb255c703c6cbc5fafe2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f88d707dbb
commit
896a90aa26
50
flipper-js-client-sdk/src/example.ts
Normal file
50
flipper-js-client-sdk/src/example.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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, AbstractFlipperPlugin} from './api';
|
||||
import {newWebviewClient} from './webviewImpl';
|
||||
|
||||
class SeaMammalPlugin extends AbstractFlipperPlugin {
|
||||
getId(): string {
|
||||
return 'sea-mammals';
|
||||
}
|
||||
|
||||
runInBackground(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
newRow(row: {id: string, url: string, title: string}) {
|
||||
this.connection?.send("newRow", row)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FlipperManager {
|
||||
flipperClient: FlipperClient;
|
||||
seaMammalPlugin: SeaMammalPlugin;
|
||||
|
||||
constructor() {
|
||||
this.flipperClient = newWebviewClient();
|
||||
this.seaMammalPlugin = new SeaMammalPlugin();
|
||||
this.flipperClient.addPlugin(this.seaMammalPlugin);
|
||||
this.flipperClient.start('Example JS App');
|
||||
}
|
||||
}
|
||||
|
||||
let flipperManager: FlipperManager | undefined;
|
||||
|
||||
export function init() {
|
||||
if (!flipperManager) {
|
||||
flipperManager = new FlipperManager();
|
||||
}
|
||||
}
|
||||
|
||||
export function flipper(): FlipperManager | undefined {
|
||||
return flipperManager;
|
||||
}
|
||||
Reference in New Issue
Block a user