plugin redux
Summary: Plugins were loaded in `/plugins/index.js` which was loaded once at launch of the app. This moves the list of available plugins to redux. This way, plugins can be dynamically added. The redux store keeps to Maps of plugins (devicePlugins and clientPlugins) with their ID as key: ``` devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>, clientPlugins: Map<string, Class<FlipperPlugin<>>>, ``` On launch of the app, all plugins bundled with the app and the one found in `pluginsPath` are dynamically added. This changes now allows to add new plugins at any time. All components that need to know which plugins are available (e.g. the sidebar) are connected to the redux store. This way, they will automatically update, whenever a new plugin is added. - add `plugins` to the redux store to keep the list of available plugins - add a plugins dispatcher, responsible for loading the plugins on launch - connecting all React components that imported `plugins/index.js` before to the redux store to get the plugins from there. - moved the updating of the MenuBar to the plugins dispatcher as it needs to update whenever a new plugin is added. Reviewed By: jknoxville, passy Differential Revision: D12449236 fbshipit-source-id: 6ef3e243e2c80443614b901ccbfde485fcb4301c
This commit is contained in:
committed by
Facebook Github Bot
parent
e02420ac78
commit
7747a0714d
@@ -11,7 +11,6 @@ import type Logger from './fb-stubs/Logger.js';
|
||||
import type {Store} from './reducers/index.js';
|
||||
|
||||
import {setPluginState} from './reducers/pluginStates.js';
|
||||
import {clientPlugins} from './plugins/index.js';
|
||||
import {ReactiveSocket, PartialResponder} from 'rsocket-core';
|
||||
|
||||
const EventEmitter = (require('events'): any);
|
||||
@@ -97,14 +96,6 @@ export default class Client extends EventEmitter {
|
||||
return this.plugins.includes(Plugin.id);
|
||||
}
|
||||
|
||||
getFirstSupportedPlugin(): ?string {
|
||||
for (const Plugin of clientPlugins) {
|
||||
if (this.supportsPlugin(Plugin)) {
|
||||
return Plugin.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async init() {
|
||||
await this.getPlugins();
|
||||
}
|
||||
@@ -162,12 +153,11 @@ export default class Client extends EventEmitter {
|
||||
const params = data.params;
|
||||
invariant(params, 'expected params');
|
||||
|
||||
const persistingPlugin: ?Class<FlipperPlugin<>> = clientPlugins.find(
|
||||
(p: Class<FlipperPlugin<>>) =>
|
||||
p.id === params.api && p.persistedStateReducer,
|
||||
);
|
||||
const persistingPlugin: ?Class<
|
||||
FlipperPlugin<>,
|
||||
> = this.store.getState().plugins.clientPlugins.get(params.api);
|
||||
|
||||
if (persistingPlugin) {
|
||||
if (persistingPlugin && persistingPlugin.persistedStateReducer) {
|
||||
const pluginKey = `${this.id}#${params.api}`;
|
||||
const persistedState = {
|
||||
...persistingPlugin.defaultPersistedState,
|
||||
|
||||
Reference in New Issue
Block a user