Refactor plugin lists computations
Summary: This is purely refactoring change. Before that we computed plugin lists in-place in PluginList component. Now we will be re-computing them as side effect and will keep computed lists in redux. This makes it easier to re-use plugin lists in other places outside of PluginList component, e.g. in the upcoming Marketplace UI. Reviewed By: mweststrate Differential Revision: D29161719 fbshipit-source-id: 5cb06d4d8a553aa856101c78b2311fbc078c6bd7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0d6262aa5e
commit
ac9ef7620a
@@ -23,6 +23,7 @@ import reactNative from './reactNative';
|
||||
import pluginMarketplace from './fb-stubs/pluginMarketplace';
|
||||
import pluginDownloads from './pluginDownloads';
|
||||
import info from '../utils/info';
|
||||
import pluginLists from './pluginLists';
|
||||
|
||||
import {Logger} from '../fb-interfaces/Logger';
|
||||
import {Store} from '../reducers/index';
|
||||
@@ -51,6 +52,7 @@ export default function (store: Store, logger: Logger): () => Promise<void> {
|
||||
pluginMarketplace,
|
||||
pluginDownloads,
|
||||
info,
|
||||
pluginLists,
|
||||
].filter(notNull);
|
||||
const globalCleanup = dispatchers
|
||||
.map((dispatcher) => dispatcher(store, logger))
|
||||
|
||||
120
desktop/app/src/dispatcher/pluginLists.tsx
Normal file
120
desktop/app/src/dispatcher/pluginLists.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* 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 Client from '../Client';
|
||||
import {Logger} from '../fb-interfaces/Logger';
|
||||
import {Store} from '../reducers';
|
||||
import {pluginListsChanged} from '../reducers/pluginLists';
|
||||
import {computePluginLists} from '../utils/pluginUtils';
|
||||
import {sideEffect} from '../utils/sideEffect';
|
||||
|
||||
export default (store: Store, _logger: Logger) => {
|
||||
const recomputePluginList = () => {
|
||||
store.dispatch(
|
||||
pluginListsChanged(
|
||||
computePluginLists(
|
||||
store.getState().connections,
|
||||
store.getState().plugins,
|
||||
),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
let prevClient: null | Client = null;
|
||||
|
||||
sideEffect(
|
||||
store,
|
||||
{name: 'computePluginLists', throttleMs: 100, fireImmediately: true},
|
||||
(state) => {
|
||||
const {
|
||||
activeClient,
|
||||
activeDevice,
|
||||
metroDevice,
|
||||
enabledDevicePlugins,
|
||||
enabledPlugins,
|
||||
} = state.connections;
|
||||
const {
|
||||
bundledPlugins,
|
||||
marketplacePlugins,
|
||||
loadedPlugins,
|
||||
devicePlugins,
|
||||
disabledPlugins,
|
||||
gatekeepedPlugins,
|
||||
failedPlugins,
|
||||
clientPlugins,
|
||||
} = state.plugins;
|
||||
return {
|
||||
activeClient,
|
||||
activeDevice,
|
||||
metroDevice,
|
||||
enabledDevicePlugins,
|
||||
enabledPlugins,
|
||||
bundledPlugins,
|
||||
marketplacePlugins,
|
||||
loadedPlugins,
|
||||
devicePlugins,
|
||||
disabledPlugins,
|
||||
gatekeepedPlugins,
|
||||
failedPlugins,
|
||||
clientPlugins,
|
||||
};
|
||||
},
|
||||
(
|
||||
{
|
||||
activeClient,
|
||||
activeDevice,
|
||||
metroDevice,
|
||||
enabledDevicePlugins,
|
||||
enabledPlugins,
|
||||
bundledPlugins,
|
||||
marketplacePlugins,
|
||||
loadedPlugins,
|
||||
devicePlugins,
|
||||
disabledPlugins,
|
||||
gatekeepedPlugins,
|
||||
failedPlugins,
|
||||
clientPlugins,
|
||||
},
|
||||
store,
|
||||
) => {
|
||||
store.dispatch(
|
||||
pluginListsChanged(
|
||||
computePluginLists(
|
||||
{
|
||||
activeClient,
|
||||
activeDevice,
|
||||
metroDevice,
|
||||
enabledDevicePlugins,
|
||||
enabledPlugins,
|
||||
},
|
||||
{
|
||||
bundledPlugins,
|
||||
marketplacePlugins,
|
||||
loadedPlugins,
|
||||
devicePlugins,
|
||||
disabledPlugins,
|
||||
gatekeepedPlugins,
|
||||
failedPlugins,
|
||||
clientPlugins,
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
if (activeClient !== prevClient) {
|
||||
if (prevClient) {
|
||||
prevClient.off('plugins-change', recomputePluginList);
|
||||
}
|
||||
prevClient = activeClient;
|
||||
if (prevClient) {
|
||||
prevClient.on('plugins-change', recomputePluginList);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user