Support exporting public API from a plugin
Reviewed By: passy Differential Revision: D36098167 fbshipit-source-id: 90182248d0541a1d8eff92a391a56422537c0595
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3dd7583fdc
commit
2854e75e9c
@@ -110,6 +110,7 @@ test('Correct top level API exposed', () => {
|
||||
"FileDescriptor",
|
||||
"FileEncoding",
|
||||
"FlipperLib",
|
||||
"FlipperPluginInstance",
|
||||
"FlipperServerForServerAddOn",
|
||||
"HighlightManager",
|
||||
"Idler",
|
||||
|
||||
@@ -25,7 +25,10 @@ export {
|
||||
CrashLogListener,
|
||||
SandyDevicePluginInstance as _SandyDevicePluginInstance,
|
||||
} from './plugin/DevicePlugin';
|
||||
export {SandyPluginDefinition as _SandyPluginDefinition} from './plugin/SandyPluginDefinition';
|
||||
export {
|
||||
SandyPluginDefinition as _SandyPluginDefinition,
|
||||
FlipperPluginInstance,
|
||||
} from './plugin/SandyPluginDefinition';
|
||||
export {SandyPluginRenderer as _SandyPluginRenderer} from './plugin/PluginRenderer';
|
||||
export {
|
||||
SandyPluginContext as _SandyPluginContext,
|
||||
|
||||
@@ -223,6 +223,8 @@ export abstract class BasePluginInstance {
|
||||
definition: SandyPluginDefinition;
|
||||
/** the plugin instance api as used inside components and such */
|
||||
instanceApi: any;
|
||||
/** the plugin public api exposed over the wire via flipper-server-companion */
|
||||
companionApi?: any;
|
||||
/** the device owning this plugin */
|
||||
readonly device: Device;
|
||||
|
||||
@@ -276,6 +278,11 @@ export abstract class BasePluginInstance {
|
||||
setCurrentPluginInstance(this);
|
||||
try {
|
||||
this.instanceApi = batched(factory)();
|
||||
|
||||
const apiFactory = this.definition.module.API;
|
||||
if (apiFactory) {
|
||||
this.companionApi = apiFactory(this.instanceApi);
|
||||
}
|
||||
} finally {
|
||||
// check if we have both an import handler and rootStates; probably dev error
|
||||
if (this.importHandler && Object.keys(this.rootStates).length > 0) {
|
||||
|
||||
@@ -11,12 +11,21 @@ import {ActivatablePluginDetails} from 'flipper-common';
|
||||
import {PluginFactory, FlipperPluginComponent} from './Plugin';
|
||||
import {DevicePluginPredicate, DevicePluginFactory} from './DevicePlugin';
|
||||
|
||||
export type FlipperPluginAPI<T extends (...args: any[]) => object> = (
|
||||
pluginInstance: ReturnType<T>,
|
||||
) => object;
|
||||
|
||||
export type FlipperPluginInstance<T extends (...args: any[]) => object> =
|
||||
Parameters<FlipperPluginAPI<T>>[0];
|
||||
|
||||
/**
|
||||
* FlipperPluginModule describe the exports that are provided by a typical Flipper Desktop plugin
|
||||
*/
|
||||
export type FlipperDevicePluginModule = {
|
||||
/** predicate that determines if this plugin applies to the currently selcted device */
|
||||
supportsDevice?: DevicePluginPredicate; // TODO T84453692: remove this function after some transition period in favor of BaseDevice.supportsPlugin.
|
||||
/** the factory function that exposes plugin API over the wire */
|
||||
API?: FlipperPluginAPI<DevicePluginFactory>;
|
||||
/** the factory function that initializes a plugin instance */
|
||||
devicePlugin: DevicePluginFactory;
|
||||
/** the component type that can render this plugin */
|
||||
@@ -29,6 +38,8 @@ export type FlipperDevicePluginModule = {
|
||||
export type FlipperPluginModule<
|
||||
Factory extends PluginFactory<any, any, any, any>,
|
||||
> = {
|
||||
/** the factory function that exposes plugin API over the wire */
|
||||
API?: FlipperPluginAPI<Factory>;
|
||||
/** the factory function that initializes a plugin instance */
|
||||
plugin: Factory;
|
||||
/** the component type that can render this plugin */
|
||||
|
||||
Reference in New Issue
Block a user