Support receiving messages in Sandy plugins

Summary: This diffs adds the capability to listen to messages in Sandy plugins. Although API wise it looks more like the old `this.subscribe`, semantically it behaves like the `persistedStateReducer`; messages are queued if the plugin is enabled but not active.

Reviewed By: nikoant

Differential Revision: D22282711

fbshipit-source-id: 885faa702fe779ac8d593c1d224b2be13e688d47
This commit is contained in:
Michel Weststrate
2020-07-01 08:58:40 -07:00
committed by Facebook GitHub Bot
parent 6c79408b0f
commit bb0c8e0df0
8 changed files with 841 additions and 59 deletions

View File

@@ -11,6 +11,8 @@ import {
PluginDefinition,
ClientPluginDefinition,
isSandyPlugin,
FlipperPlugin,
FlipperDevicePlugin,
} from './plugin';
import BaseDevice, {OS} from './devices/BaseDevice';
import {App} from './App';
@@ -135,7 +137,10 @@ export default class Client extends EventEmitter {
messageBuffer: Record<
string /*pluginKey*/,
{
plugin: PluginDefinition;
plugin:
| typeof FlipperPlugin
| typeof FlipperDevicePlugin
| SandyPluginInstance;
messages: Params[];
}
> = {};
@@ -456,11 +461,11 @@ export default class Client extends EventEmitter {
this.store.getState().plugins.devicePlugins.get(params.api);
let handled = false; // This is just for analysis
// TODO: support Sandy plugins T68683442
if (
persistingPlugin &&
!isSandyPlugin(persistingPlugin) &&
persistingPlugin.persistedStateReducer
((persistingPlugin as any).persistedStateReducer ||
// only send messages to enabled sandy plugins
this.sandyPluginStates.has(params.api))
) {
handled = true;
const pluginKey = getPluginKey(
@@ -470,7 +475,8 @@ export default class Client extends EventEmitter {
);
if (!this.messageBuffer[pluginKey]) {
this.messageBuffer[pluginKey] = {
plugin: persistingPlugin,
plugin: (this.sandyPluginStates.get(params.api) ??
persistingPlugin) as any,
messages: [params],
};
} else {