Allow plugins to send messages

Summary: Sandy plugins can now send messages to plugins. The methods and params are strongly typed in implementation and unit tests, based on the <Methods> generic of FlipperClient.

Reviewed By: nikoant

Differential Revision: D22256972

fbshipit-source-id: 549523a402949b3eb6bb4b4ca160dedb5c5e722d
This commit is contained in:
Michel Weststrate
2020-07-01 08:58:40 -07:00
committed by Facebook GitHub Bot
parent 8b2d8498e6
commit ec85dd5b01
9 changed files with 161 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ type Events = {
};
type Methods = {
currentState(): Promise<number>;
currentState(params: {since: number}): Promise<number>;
};
export function plugin(client: FlipperClient<Events, Methods>) {
@@ -32,10 +32,22 @@ export function plugin(client: FlipperClient<Events, Methods>) {
client.onDisconnect(disconnectStub);
client.onDestroy(destroyStub);
function _unused_JustTypeChecks() {
// @ts-expect-error Argument of type '"bla"' is not assignable
client.send('bla', {});
// @ts-expect-error Argument of type '{ stuff: string; }' is not assignable to parameter of type
client.send('currentState', {stuff: 'nope'});
}
async function getCurrentState() {
return client.send('currentState', {since: 0});
}
return {
connectStub,
destroyStub,
disconnectStub,
getCurrentState,
};
}